Repository navigation
fix(citry-ui): read SVG/MathML <style> content and void end tags in checked fills as browsers do - #778
Merged
Conversation
…lls as browsers do The components that check their rendered slot fills (CImage, CCommandPalette, CListbox, CTree, CDisclosure, CAccordion and the Menu collections) now share one parser, MarkupTreeParser, that tracks which elements a browser keeps open. It reads the content of <style> and the other raw-text elements inside SVG and MathML as elements, reads <![CDATA[ as browsers do, ignores end tags that close nothing (such as </link>), removes only the form on </form>, and closes the elements a start tag closes (an open <p> before <div>, a <button> before another). The region checks also refuse <noscript>, whose content is text when scripting is on. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KUhrHXH1mNfRCnPcsQt7ED
…arser # Conflicts: # docs/design/trust_boundaries.md # packages/py/citry_ui/CHANGELOG.md
Browsers ignore end tags other than those of the select and its options while a <select> is open, so the checks of rendered fills now do the same. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KUhrHXH1mNfRCnPcsQt7ED
This was referenced Nov 18, 2026
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.
What changed
Several citry-ui components check the HTML they rendered, for example that a
CImageplaceholder fill holds nothing focusable, or that aCAccordionholds one root element per item. These checks now read SVG and MathML<style>content and end tags on void elements (and similar cases) the way browsers do.MarkupTreeParser(packages/py/citry_ui/citry_ui/components/_markup_tree.py). It tracks which elements a browser keeps open, with their namespace, and tells each check when an element opens and closes. All eight checks use it:CImage,CCommandPalette,CListbox,CTree,CDisclosuretitle and content,CAccordion, and the Menu collections. They no longer keep their own depth counters.<style>and the other elements Python'sHTMLParserreads as raw text now hold elements, as in a browser. The HTML integration points (foreignObject,desc, SVGtitle,annotation-xmlwith an HTML encoding, the MathML text elements) keep the HTML rules.</link>, end tags hidden by a table cell or other scope limit, and end tags inside an open<select>.</br>and an unmatched</p>create elements.</form>removes only the form.<p>before<div>or a<button>before another<button>.<![CDATA[is a comment in HTML and a CDATA section in SVG and MathML, and<image>is read as<img>.CImage,CCommandPaletteandCListboxregion checks refuse<noscript>, whose content the browser reads as text when scripting is on.docs/design/trust_boundaries.mdsection 13.Known limits, stated in the class docstring: the parser does not model the elements a browser moves (a block element moved out of a misnested
<b>or a second<a>, content placed before a<table>), or an<option>closing an<option>.Browser comparison
A throwaway Playwright harness (not committed) compared the element tree with Chromium, Firefox and WebKit, using
DOMParseron 64 documents. 60 match all three browsers exactly, and the three browsers agree with each other on all 64. The 4 differences are the known limits above (an implied<tbody>twice, the formatting-element reopen, the adoption-agency move); none of them moves an element into or out of a checked region. At check level, 12 representative fills gave the same verdict as the browsers for bothCImageandCCommandPalette. A reviewer also ran 9,000 random tag sequences against Chromium for the open and close bookkeeping.Checks
ruff check,ruff format --check,mypy, andmypy --platform linuxon the 10 touched Python files: clean.packages/py/citry_ui, without e2e andtest_citry_ui_type_check.py, which needs citry-lsp): 4558 passed, 109 skipped.test_markup_tree.pyandtest_output_parsers.py: 114 passed on Python 3.14.9; an earlier revision also passed on 3.11.15.citry-core==2.1.1wheel; no Rust build.Versioning
citry-ui is 0.x, so the 1.x promise does not cover it; this is a patch-level fix. A fill that the browser renders with a focusable element in a checked region, or with an extra root, now raises
ValueErrorwhere it rendered before. Nocitrycode, contract version or stored format changes.Review
An independent reviewer did a technical review, a security pass (Text and markup; Parser rules browsers differ on) and a prose pass. Folded in:
</form>closing too much,<noscript>in regions, start tags that close elements, end tags inside<select>, end-tag cost growing with nesting depth, older Python releases reading<textarea>and<![differently, and wording fixes.🤖 Generated with Claude Code
https://claude.ai/code/session_01KUhrHXH1mNfRCnPcsQt7ED