Skip to content

Possible to have code block with gray background, no syntax highlighting, and not run with rustc? #179

Closed
@carols10cents

Description

@carols10cents

What I'm trying to do is get a code block that has the gray background that comes with:

.hljs {
   background: #f1f1f1;
}

(and the rest of the .hljs css too, probably) but not have any syntax highlighting applied, and also not have mdbook try and run the code block with rustdoc --test.

My use case is code blocks like this that are showing command line output:

$ cargo run
   Compiling panic v0.1.0 (file:///projects/panic)
    Finished debug [unoptimized + debuginfo] target(s) in 0.27 secs
     Running `target/debug/panic`
thread 'main' panicked at 'index out of bounds: the len is 3 but the index is
100', ../src/libcollections/vec.rs:1265
note: Run with `RUST_BACKTRACE=1` for a backtrace.
error: Process didn't exit successfully: `target/debug/panic` (exit code: 101)

I've tried:

  • Setting the language as bash, which uses the gray background, but since it's meant for bash scripts not bash command line interactions, it confusingly will highlight arbitrary words like "in".
  • Setting the language as text, which turns off highlighting, but that also means that block doesn't get the hljs class since it technically didn't go through highlight.js.
  • Setting the language as something nonexistent like blah, which has the same effect as text.
  • Not setting a language at all, which does get me the grey background and lack of syntax highlighting, but mdbook test tries to run the contents as rust :(
  • Setting the language to just ignore, which makes mdbook test ignore it as desired but has the same display without the grey background as text, blah, etc

Do you know of any other workarounds that would result in the behavior I'm looking for?

Alternatively, would you accept a PR that adds this (or similar) to highlight.css, that matches the words in highlight.js's regex to not do syntax highlighting?

.language-no-highlight, .language-nohighlight, .language-plain, .language-text {
  display: block;
  overflow-x: auto;
  background: #f1f1f1;
  color: #6e6b5e;
  padding: 0.5em;
-webkit-text-size-adjust: none;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions