# Code Highlighting with Escaped Quotes

**URL:** https://meta.discourse.org/t/code-highlighting-with-escaped-quotes/235999
**Category:** Support
**Created:** [August 12, 2022, 3:42pm UTC](https://meta.discourse.org/t/code-highlighting-with-escaped-quotes/235999 "2022-08-12T15:42:15Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![MaxZ](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@MaxZ](https://meta.discourse.org/u/MaxZ)
#### Post date: [August 12, 2022, 3:42pm UTC](https://meta.discourse.org/t/code-highlighting-with-escaped-quotes/235999/1 "2022-08-12T15:42:15Z")

</div>

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.

 ![image](https://global.discourse-cdn.com/meta/original/4X/c/6/a/c6a23fcfdeff1c6bb6488f01a513e2f86257a2a1.png)  
Link to my screenshotted forum post: [https://unofficialnextion.com/t/set-vale-on-page2/1679/3](https://unofficialnextion.com/t/set-vale-on-page2/1679/3)

Further details:

- 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](https://meta.discourse.org/t/53504?silent=true)
- 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).

Kind regards,  
Max

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [August 12, 2022, 3:47pm UTC](https://meta.discourse.org/t/code-highlighting-with-escaped-quotes/235999/2 "2022-08-12T15:47:33Z")

</div>

That’s the [highlightjs library](https://github.com/highlightjs/highlight.js) so any bug would be upstream.

Also looks like this works in `cpp` mode?

```cpp
const char* NXT_CMD_END = "\xff\xff\xff";
Serial.print("page2.t0.txt=\"Any text\"");
Serial.print(NXT_CMD_END);

```

You can set a explicit language using the “info string” feature in a code block:

````plaintext
```cpp
your code here   
```

````

will create a cpp flavored code block.

---

<div class="post-metadata">

### Author: ![MaxZ](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@MaxZ](https://meta.discourse.org/u/MaxZ)
#### Post date: [August 12, 2022, 4:02pm UTC](https://meta.discourse.org/t/code-highlighting-with-escaped-quotes/235999/3 "2022-08-12T16:02:07Z")

</div>

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?

Kind regards,  
Max

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [August 12, 2022, 4:07pm UTC](https://meta.discourse.org/t/code-highlighting-with-escaped-quotes/235999/4 "2022-08-12T16:07:06Z")

</div>

Have you rebaked the post containing the code block after changing the settings?

---

<div class="post-metadata">

### Author: ![MaxZ](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@MaxZ](https://meta.discourse.org/u/MaxZ)
#### Post date: [August 12, 2022, 4:12pm UTC](https://meta.discourse.org/t/code-highlighting-with-escaped-quotes/235999/5 "2022-08-12T16:12:32Z")

</div>

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.

So, with `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.

Kind regards,  
Max

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [August 12, 2022, 4:15pm UTC](https://meta.discourse.org/t/code-highlighting-with-escaped-quotes/235999/6 "2022-08-12T16:15:41Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![MaxZ](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@MaxZ](https://meta.discourse.org/u/MaxZ)
#### Post date: [August 12, 2022, 4:21pm UTC](https://meta.discourse.org/t/code-highlighting-with-escaped-quotes/235999/7 "2022-08-12T16:21:34Z")

</div>

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?

Kind regards,  
Max
