Open camelid opened 4 years ago
Technically those examples are not marked to be syntax-highlighted as rust. The first one, ignore doesn't specify, the next ones specify "markdown". Inconsistent, but it smells like incorrect intent, and not a mdbook bug to me.
I know, but mdBook has support for Markdown syntax highlighting, yet the code marked with markdown
is not being highlighted as Markdown.
Ah, that wasn't clear, sorry.
Cc @ehuss – I'm thinking this might be an mdBook issue
I don't understand exactly what you are expecting.
The first example has no language. You can change it to rust,ignore
, but I don't really know if that is an improvement, since it is all comments, it will change it to a harder-to-read color.
The second and third examples are correctly highlighted as markdown, but it is a code block, so it only has one color.
Well, I deleted my previous comment since that was wrong, but there is a longer code block that has plain text and inner code blocks, and it is rendered using a single color. Starts with
``````markdown
First, we set `x` to five:
I can see in the HTML that it's picked up as expected as language-markdown
, but it seems interesting that it's rendered the same as the no-language ones.
Since it is inside a code block, "plain text" in markdown will be rendered the same as code blocks (with triple backticks) since they are all a "code" style. Other markdown constructs (like headers, lists, links, etc.) will have different colors.
It might be feasible to style hljs-code
differently, but that seems like it will take a fair bit of work to make sure it doesn't have negative consequences. I'm also unsure how to style it differently, since it is already in a <code>
block.
Personally this doesn't seem like a giant loss to me; the point of these examples is the markdown syntax, not the Rust code itself. I wouldn't mind having the rust highlighted, but if it's hard to do like ehuss mentioned, I'm not sure it's worth it.
I don't necessarily agree with you here. In the context of markdown, plaintext is not code, so I think it should be styled somewhat differently. And most of the highlighters do, I think.
Let's see what GitHub does here.
random code
I'm not arguing for the inner code to be rust-highlighted, but the markdown be markdown-highlighted :)
Well, in any case, this isn't a rustdoc issue, it's a mdbook issue. Can someone move it there?
Transferred.
I didn't say it should or should not be styled the same, I just said why it is the same. It would probably be reasonable to add a different color to hljs-code
, but I don't know what a good color choice would be. One would need to pick colors for all five color themes, make sure they don't regress on any language (and there are many). That would be a fair bit of work I think.
From this page:
Yet some code samples are syntax-highlighted:
I checked the source for this page, and it looks fine:
I'm wondering if this might be a bug in mdbook, but I figured I would post here first since this is the only place I've seen it.