Skip to content
Closed
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
11 changes: 7 additions & 4 deletions guide/src/format/theme/syntax-highlighting.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions src/renderer/html_handlebars/hbs_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,8 @@ fn add_playground_pre(
} else {
format!("<code class=\"{}\">{}</code>", classes, hide_lines(code))
}
} else if classes.contains("hidelines") {
format!("<code class=\"{}\">{}</code>", classes, hide_lines(code))
} else {
// not language-rust, so no-op
text.to_owned()
Expand Down
2 changes: 1 addition & 1 deletion src/theme/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down