Code highlighting seems to ignore escaped quotes (both single and double). Meaning, if a string within a code section contains escaped quotes, parts of the string are highlighted like normal code. In this forum code highlighting seems to be disabled, hence I include the link to the specific forum post where I’ve noticed it for the first time.
Link to my screenshotted forum post: Set vale on page2 - #3 by Max - Nextion Editor - Unofficial Nextion/TJC User Forum
- Said forum runs Discourse v2.9.0.beta9
- Code highlighting is enabled for bash, cs, cpp, xml, ini, json, makefile, markdown, python, c, c-like. Default is set to cpp. Resetting these language highlighting settings to default doesn’t solve the issue.
- Issue is also present in safe mode
- Issue is also present when escaping single-quotes in a single-quoted string (escaping single-quote in a double-quoted string and vice-versa works properly).
That’s the highlightjs library so any bug would be upstream.
Also looks like this works in
const char* NXT_CMD_END = "\xff\xff\xff";
You can set a explicit language using the “info string” feature in a code block:
your code here
will create a cpp flavored code block.
Thanks for the quick reply and info!
Indeed, cpp highlighting works if set explicitly. However, while looking into this a bit further I found another… unexpected behavior.
I removed all languages from the highlighted languages list except for
cpp and reverted the default language back to
auto. The result was still a wrong highlighting. Opening the Inspector in Firefox revealed that the code is apparently recognized as
vbnet - a language that was never in the list of highlighted languages (neither the default one nor any custom ones I tried for this issue)? Is this supposed to happen?
Have you rebaked the post containing the code block after changing the settings?
I reloaded the page. While the forum post itself never changed - even when restarting firefox or reloading the page with
CTRL+F5 - I noticed that the preview for editing the post does use the modified settings when reloading the page.
cpp as only language in the list (to keep things simple), if I set the default language to
cpp, code highlighting in the post edit preview is correct. If I set the default language to
auto and again reload the page, it’s not correct anymore as described in the previous post.
Restarting the browser won’t do it. In Discourse posts are baked (converted from markdown to HTML) in the server just once, and the resulting HTML is cached in the database. In order to updated said cooked post, you need to “rebake” it. This can be done by a staff user using the wrench menu on a post or by the post author by editing said post contents.
Thx. Rebaking results in the same behavior as with the edit preview though.
auto selects a language (
vbnet) that’s not in the list of languages to highlight. Setting the default lang explicitly to
cpp (either in the forum settings or as you showed here) does work as reported earlier.
So the question remains: is
auto supposed to use other languages than those in the list?