Skip to content

Read HTML script and style bodies as text up to their closing tag [minor] - #741

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/738-html-script-style-raw-text
Nov 4, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/738-html-script-style-raw-text

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

The markup tokenizer started a tag at any < followed by a letter, including inside a <script> or <style> body, and an attribute value then ran to the next matching quote. An inline script needs only two things to trigger this: count<limit, then an apostrophe in a later comment. Together they coloured every following line of the HTML block as one string. The class doc and the README both said these bodies are treated as text.

Change

  • New LanguageDefinition.RawTextElements: the markup elements whose body is raw text. HTML sets it to script and style. XML leaves it empty, so <script> in XML is still markup.
  • After an opening tag for one of these elements, MarkupTokenizer emits everything up to </name as a single Plain token. The name matches in any case, and the match must not be followed by a name character, so </styles> does not close <style>. A self-closing <script/> opens no body.
  • MarkupTokenizer.Tokenize now takes the definition. Both call sites (HighlightCache, EmbeddedExpander) pass the one they already hold.
  • SyntaxHighlighting/README.md and the class doc now describe what actually happens.

I left out the issue's optional extra, which would end an unterminated attribute quote at > or at a newline. HTML allows both inside a quoted value, so that change would break valid markup.

Tests

MarkupTokenizerTests gains four tests:

  • The issue's reproduction: the script body is all Plain, and the following <p class="intro"> and <a href="/docs"> come out as tags, attribute names and values.
  • A <STYLE> body containing '</b>' and </styles> is closed only by </Style>.
  • An unclosed script body stays text.
  • XML still tokenizes <script><item/></script> as markup.

Results:

  • Without the source change, the three HTML tests fail. With it, all of SyntaxHighlighting.Tests passes (111/111).
  • The Release build of SyntaxHighlighting is clean.

Fixes #738


Generated by Claude Code

…nor]

The markup tokenizer started a tag at any `<` followed by a letter, inside
a script or style body as well, and an attribute value then ran to the
next matching quote. An ordinary inline script with `count<limit` and an
apostrophe in a later comment coloured every following line of the HTML
as one string, though the class doc and README said these bodies are text.

LanguageDefinition.RawTextElements names the elements whose body is raw
text; HTML sets it to script and style. After such an opening tag the
tokenizer emits everything up to `</name` (any case, not followed by a
name character) as Plain. XML is unchanged.

Fixes #738

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW1ukQkdr8Cyf3p9j6Z
@sonarqubecloud

sonarqubecloud Bot commented Nov 3, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants