Skip to content

Commit 08b5d14

Browse files
committed
Add hljs class to all code blocks, regardless of highlighting
Fixes #179. Highlight.js does not apply syntax highlighting to code blocks marked no-highlight, nohighlight, plain, or text. When it finds blocks of those languages, it does not add the `hljs` class to those code blocks either. highlight.css and tomorrow-night.css use the `hljs` class to give code blocks their backrgound color and text color, and we want that to apply even if the code doesn't get syntax highlighting markup. This is a somewhat hacky solution to get just that behavior! After this commit, code blocks with no-highlight, nohighlight, plain, or text language set on them will indeed get the hljs colors.
1 parent f0c0d71 commit 08b5d14

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/theme/book.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ $( document ).ready(function() {
2222
$('code').each(function(i, block) {
2323
hljs.highlightBlock(block);
2424
});
25+
26+
// Adding the hljs class gives code blocks the color css
27+
// even if highlighting doesn't apply
28+
$('code').addClass('hljs');
2529

2630
var KEY_CODES = {
2731
PREVIOUS_KEY: 37,

0 commit comments

Comments
 (0)