Skip to content

fix(citry-ui): read SVG/MathML <style> content and void end tags in checked fills as browsers do - #778

Merged
JuroOravec merged 3 commits into
mainfrom
fix/citry-ui-markup-parser
Nov 18, 2026
Merged

JuroOravec merged 3 commits into
mainfrom
fix/citry-ui-markup-parser

Conversation

@JuroOravec

Copy link
Copy Markdown
Member

What changed

Several citry-ui components check the HTML they rendered, for example that a CImage placeholder fill holds nothing focusable, or that a CAccordion holds 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.

  • New shared parser 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, CDisclosure title and content, CAccordion, and the Menu collections. They no longer keep their own depth counters.
  • Inside SVG and MathML, <style> and the other elements Python's HTMLParser reads as raw text now hold elements, as in a browser. The HTML integration points (foreignObject, desc, SVG title, annotation-xml with an HTML encoding, the MathML text elements) keep the HTML rules.
  • End tags that close nothing are ignored: void end tags such as </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.
  • Start tags close what a browser closes, such as an open <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>.
  • The CImage, CCommandPalette and CListbox region checks refuse <noscript>, whose content the browser reads as text when scripting is on.
  • Lookups use per-kind position lists, so each tag costs the same however deep the nesting is.
  • Changelog entry under Unreleased. New row and an intro sentence in docs/design/trust_boundaries.md section 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 DOMParser on 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 both CImage and CCommandPalette. A reviewer also ran 9,000 random tag sequences against Chromium for the open and close bookkeeping.

Checks

  • ruff check, ruff format --check, mypy, and mypy --platform linux on the 10 touched Python files: clean.
  • citry_ui tests (packages/py/citry_ui, without e2e and test_citry_ui_type_check.py, which needs citry-lsp): 4558 passed, 109 skipped.
  • test_markup_tree.py and test_output_parsers.py: 114 passed on Python 3.14.9; an earlier revision also passed on 3.11.15.
  • Built with the published citry-core==2.1.1 wheel; 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 ValueError where it rendered before. No citry code, 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

JuroOravec and others added 3 commits November 18, 2026 13:23
…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
@JuroOravec
JuroOravec merged commit 8685814 into main Nov 18, 2026
21 of 31 checks passed
@JuroOravec
JuroOravec deleted the fix/citry-ui-markup-parser branch November 18, 2026 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant