Repository navigation
Conversation
In HTML, <plaintext> outside SVG/MathML turns the rest of the document into text. posthtml-parser 0.13 (htmlparser2 12) follows this and returns everything after it as the element's content, so the source has no end tags after it. The renderer appended </plaintext> and the ancestors' end tags, which browsers would show as text. Track foreign content like htmlparser2 and stop emitting end tags once such an element is opened. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
voischev
requested review from
Scrum,
michael-ciniawsky and
mrmlnc
as code owners
November 30, 2026 15:56
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In HTML, a
<plaintext>start tag outside SVG/MathML switches the tokenizer to plain text until the end of the document. posthtml-parser 0.13 (htmlparser2 12) follows the spec and returns everything after it as the element's text content:The appended
</plaintext></div>never existed in the source and browsers render it as text.Fix.
render()tracks foreign content like htmlparser2 (exactsvg/mathstart it;foreignObject,desc,title,mi,mo,mn,ms,mtext,annotation-xmlreturn to HTML). Once aplaintextelement (any case) is opened outside foreign content, no further end tags are emitted: not for it, its ancestors, or later nodes. Inside SVG/MathMLplaintextis a regular element. The state is perrender()call.Foreign detection is intentionally case-sensitive to mirror htmlparser2 with
lowerCaseTags: false(posthtml-parser's default): it does not treat<SVG>as foreign, and the renderer must agree to reproduce the parsed source.Tests: end tags omitted for the element, ancestors and later nodes; case-insensitive
PLAINTEXT; regular element inside SVG and MathML; text mode again insideforeignObject; case-sensitiveSVG; no state leak between calls. Five of them fail without the fix.npm run checkpasses.Round trip with posthtml-parser
master(incl. posthtml/posthtml-parser#113): 10 of 11 plaintext/SVG/HTML samples render back identical; the remaining one differs only by the pre-existing explicit</li>for an implied end tag.Downstream: htmlnano
masterwith posthtmlmaster+ posthtml/posthtml#421, posthtml-parsermasterand this renderer: 1866/1867 tests pass, types pass. The remaining test uses uppercase<SVG>, which htmlnano treats as foreign per spec while htmlparser2 does not (case-sensitive foreign detection); the renderer reproduces the parsed source there.🤖 Generated with Claude Code