Sublime Forum

Nested html`` in javascript breaks syntax highlighting

#1

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

(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.

0 Likes

#2

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

A possible fix was probosed via PR4318 but abandoned as it significantly increases overall complexity of involved syntax definitions.

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

0 Likes

#3

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.

0 Likes

#4

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

0 Likes