Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't highlight code spans in headers. #1162

Merged
merged 1 commit into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/theme/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ function playpen_text(playpen) {
languages: [], // Languages used for auto-detection
});

let code_nodes = Array
.from(document.querySelectorAll('code'))
// Don't highlight `inline code` blocks in headers.
.filter(function (node) {return !node.parentElement.classList.contains("header"); });

if (window.ace) {
// language-rust class needs to be removed for editable
// blocks or highlightjs will capture events
Expand All @@ -154,16 +159,12 @@ function playpen_text(playpen) {
.from(document.querySelectorAll('code:not(.editable)'))
.forEach(function (block) { hljs.highlightBlock(block); });
} else {
Array
.from(document.querySelectorAll('code'))
.forEach(function (block) { hljs.highlightBlock(block); });
code_nodes.forEach(function (block) { hljs.highlightBlock(block); });
}

// Adding the hljs class gives code blocks the color css
// even if highlighting doesn't apply
Array
.from(document.querySelectorAll('code'))
.forEach(function (block) { block.classList.add('hljs'); });
code_nodes.forEach(function (block) { block.classList.add('hljs'); });

Array.from(document.querySelectorAll("code.language-rust")).forEach(function (block) {

Expand Down
5 changes: 5 additions & 0 deletions src/theme/css/general.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ code {
font-size: 0.875em; /* please adjust the ace font size accordingly in editor.js */
}

/* Don't change font size in headers. */
h1 code, h2 code, h3 code, h4 code, h5 code, h6 code {
font-size: unset;
}

.left { float: left; }
.right { float: right; }
.boring { opacity: 0.6; }
Expand Down