diff --git a/guide/src/format/theme/syntax-highlighting.md b/guide/src/format/theme/syntax-highlighting.md index 05cf6206ff..c8c1b325da 100644 --- a/guide/src/format/theme/syntax-highlighting.md +++ b/guide/src/format/theme/syntax-highlighting.md @@ -103,11 +103,14 @@ Will render as # } ``` -**At the moment, this only works for code examples that are annotated with -`rust`. Because it would collide with semantics of some programming languages. -In the future, we want to make this configurable through the `book.toml` so that -everyone can benefit from it.** +Hiding is only enabled by default for code examples with the language `rust`, +since it collides with ordinary use of `#` in some other programming languages. +To enable code hiding for a specific non-Rust code block, append `,hidelines` +after the language selector: +~~~markdown +```haskell,hidelines +~~~ ## Improve default theme diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 918ec29e5e..ff1d6ec374 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -848,6 +848,8 @@ fn add_playground_pre( } else { format!("{}", classes, hide_lines(code)) } + } else if classes.contains("hidelines") { + format!("{}", classes, hide_lines(code)) } else { // not language-rust, so no-op text.to_owned() diff --git a/src/theme/book.js b/src/theme/book.js index 5e386369f7..23dd3e4664 100644 --- a/src/theme/book.js +++ b/src/theme/book.js @@ -166,7 +166,7 @@ function playground_text(playground) { // even if highlighting doesn't apply code_nodes.forEach(function (block) { block.classList.add('hljs'); }); - Array.from(document.querySelectorAll("code.language-rust")).forEach(function (block) { + Array.from(document.querySelectorAll("code.language-rust, code.hidelines")).forEach(function (block) { var lines = Array.from(block.querySelectorAll('.boring')); // If no lines were hidden, return