# Nested html\`\` in javascript breaks syntax highlighting

**URL:** <https://forum.sublimetext.com/t/nested-html-in-javascript-breaks-syntax-highlighting/78081>\
**Category:** Technical Support\
**Created:** [February 19, 2026, 1:57am UTC](https://forum.sublimetext.com/t/nested-html-in-javascript-breaks-syntax-highlighting/78081 "2026-02-19T01:57:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ejs](https://forum.sublimetext.com/user_avatar/forum.sublimetext.com/ejs/32/80436_2.png) [@ejs](https://forum.sublimetext.com/u/ejs)\
**Post date:** [February 19, 2026, 1:57am UTC](https://forum.sublimetext.com/t/nested-html-in-javascript-breaks-syntax-highlighting/78081/1 "2026-02-19T01:57:49Z")

</div>

i’m on build 4200. in javascript highlighting, template literals tagged with a tag called “html” get special treatment, in that their contents get highlighted as HTML.

however, this breaks horribly when an html`` literal is nested inside another:

 ![2026-02-18-220321_555x263_scrot](https://forum.sublimetext.com/uploads/default/original/3X/9/3/93408ea1c5f3a54d256d27dfad63078ba4a13e36.png)

(the entire rest of the file is then highlighted incorrectly)

the inner template string doesn’t even need to be tagged html`` for this to happen, any template literal inside html`` will break it.

---

<div class="post-metadata">

**Author:** ![deathaxe](https://forum.sublimetext.com/user_avatar/forum.sublimetext.com/deathaxe/32/52468_2.png) [@deathaxe](https://forum.sublimetext.com/u/deathaxe)\
**Post date:** [February 19, 2026, 6:32am UTC](https://forum.sublimetext.com/t/nested-html-in-javascript-breaks-syntax-highlighting/78081/2 "2026-02-19T06:32:02Z")

</div>

This is a limitation per design, to avoid infinite recursive import loops with nested syntaxes.

A possible fix was probosed via [PR4318](https://github.com/sublimehq/Packages/pull/4318) but abandoned as it significantly increases overall complexity of involved syntax definitions.

I’d say: Just don’t do that.

> <https://github.com/sublimehq/Packages/issues/4220>

---

<div class="post-metadata">

**Author:** ![ejs](https://forum.sublimetext.com/user_avatar/forum.sublimetext.com/ejs/32/80436_2.png) [@ejs](https://forum.sublimetext.com/u/ejs)\
**Post date:** [February 19, 2026, 3:17pm UTC](https://forum.sublimetext.com/t/nested-html-in-javascript-breaks-syntax-highlighting/78081/3 "2026-02-19T15:17:51Z")

</div>

I appreciate that getting arbitrarily-nesting syntax highlighting working here is complex, but is there any chance we can at least avoid completely breaking highlighting for the rest of the file? whether automatically by detecting when this happens or at least by providing some mechanism to opt out of this special behavior for html``.

I don’t always have complete control over the coding conventions used in the files I open, so “just don’t do that” is not exactly actionable. the current behavior produces obviously broken highlighting for obviously syntactically valid javascript, which seems like an odd default.

---

<div class="post-metadata">

**Author:** ![deathaxe](https://forum.sublimetext.com/user_avatar/forum.sublimetext.com/deathaxe/32/52468_2.png) [@deathaxe](https://forum.sublimetext.com/u/deathaxe)\
**Post date:** [February 19, 2026, 5:35pm UTC](https://forum.sublimetext.com/t/nested-html-in-javascript-breaks-syntax-highlighting/78081/4 "2026-02-19T17:35:36Z")

</div>

> [@ejs](#):
>
> completely breaking highlighting for the rest of the file?

Not the way it is and needs to be implemented, and withoout completely removing syntax highlighting within tagged template strings again.

---

<div class="post-metadata">

**Author:** ![yurivish](https://forum.sublimetext.com/user_avatar/forum.sublimetext.com/yurivish/32/62756_2.png) [@yurivish](https://forum.sublimetext.com/u/yurivish)\
**Post date:** [August 28, 2026, 2:43am UTC](https://forum.sublimetext.com/t/nested-html-in-javascript-breaks-syntax-highlighting/78081/5 "2026-08-28T02:43:12Z")

</div>

I just ran into this too, nesting mixed `html` and `svg` tags, and sometimes encountering issues with un-nested syntax highlighting too, on build 4200:

 ![41%402x](https://forum.sublimetext.com/uploads/default/original/3X/9/5/95774c913f785303136d727f6f24e105230f1133.png)

I’d also love if there was support for the same HTML highlighting for `svg`. An `svg` literal creates elements in the SVG namespace, and many libraries such as Observable’s [Hypertext Literal](https://github.com/observablehq/htl) and the popular [Lit](https://lit.dev/docs/api/templates/) web component library use it.

---

<div class="post-metadata">

**Author:** ![deathaxe](https://forum.sublimetext.com/user_avatar/forum.sublimetext.com/deathaxe/32/52468_2.png) [@deathaxe](https://forum.sublimetext.com/u/deathaxe)\
**Post date:** [August 28, 2026, 3:26pm UTC](https://forum.sublimetext.com/t/nested-html-in-javascript-breaks-syntax-highlighting/78081/6 "2026-08-28T15:26:17Z")

</div>

This issue is not directly related to nested tagged template strings, but also fixed by [https://github.com/sublimehq/Packages/pull/4566](https://github.com/sublimehq/Packages/pull/4566).

The PR was merged and should be part of one of the next dev builds.

---

<div class="post-metadata">

**Author:** ![yurivish](https://forum.sublimetext.com/user_avatar/forum.sublimetext.com/yurivish/32/62756_2.png) [@yurivish](https://forum.sublimetext.com/u/yurivish)\
**Post date:** [August 30, 2026, 3:27am UTC](https://forum.sublimetext.com/t/nested-html-in-javascript-breaks-syntax-highlighting/78081/7 "2026-08-30T03:27:24Z")

</div>

That’s fantastic, thank you. Do you think it’d be possible to make `svg```highlight the same as `html```? i think that’s all i was asking about in the second part of my question, since the only real difference between the two is what namespace the elements are created in; they both accept the exact same syntax.

---

<div class="post-metadata">

**Author:** ![deathaxe](https://forum.sublimetext.com/user_avatar/forum.sublimetext.com/deathaxe/32/52468_2.png) [@deathaxe](https://forum.sublimetext.com/u/deathaxe)\
**Post date:** [August 30, 2026, 6:27am UTC](https://forum.sublimetext.com/t/nested-html-in-javascript-breaks-syntax-highlighting/78081/8 "2026-08-30T06:27:09Z")

</div>

> <https://github.com/sublimehq/Packages/pull/4606>

---

<div class="post-metadata">

**Author:** ![yurivish](https://forum.sublimetext.com/user_avatar/forum.sublimetext.com/yurivish/32/62756_2.png) [@yurivish](https://forum.sublimetext.com/u/yurivish)\
**Post date:** [August 31, 2026, 3:38am UTC](https://forum.sublimetext.com/t/nested-html-in-javascript-breaks-syntax-highlighting/78081/9 "2026-08-31T03:38:14Z")

</div>

🎂🎺✨🙏

Woohoo!
