Repository navigation
fix: mark component roots and check menu fills the way the browser reads them - #510
Merged
Merged
Conversation
JuroOravec
force-pushed
the
fix/html-structure-like-browser
branch
from
October 28, 2026 18:37
24c7f3d to
ad2d61c
Compare
JuroOravec
force-pushed
the
fix/html-structure-like-browser
branch
from
October 28, 2026 18:55
ad2d61c to
8603462
Compare
…ads them `mark_html` adds a component's `data-cid-*` attribute, which its scoped CSS and root lookups depend on, to the root-level tags of its HTML. It counted nesting with a few shortcuts the browser does not take, so later root tags lost the marker or nested tags got it: - it knew only four elements whose content the browser reads as text; - it treated any `/>` as closing the element, while the browser keeps a non-void HTML element written with `/>`, such as `<div/>`, open; - every end tag lowered the count, whatever element it named. The scanner now keeps the open elements and follows the browser's rules: - the content of `<xmp>`, `<iframe>`, `<noembed>`, `<noframes>` and `<plaintext>` is text; - a block end tag closes its element when it is in scope, a table end tag first closes an open cell or caption, and any other end tag closes the element it names unless a special element comes first; - a new `<li>`, `<dt>`, `<dd>`, `<option>`, `<button>`, cell, row, table section or heading ends an open one where the browser does, and a block start ends an open `<p>`; - in SVG and MathML `/>` closes the element. Each tag name is classified once, and the stack counts the open elements a rule can close, so a release build scans as fast as before. The `<template c-render-id>` placeholder Citry leaves for a child component is still split out inside text content and `<noscript>`, so the child's HTML is kept, and serialize now joins a literal placeholder's text back into a leaf instead of dropping it. A new test parses the marked HTML of 104 inputs with html5ever and checks the markers sit exactly on the top-level elements. The Python walk that places row markers at compile time follows the same rules and declines where it does not mirror one. Citry UI's check of a menu's or accordion's direct content fed a self-closed template element such as `<span/>` to its parser with the `/`, followed by the end tag the compiler always emits, so the parser saw an extra end tag and rejected valid content. It now feeds the element the way the page writes it, and Citry writes a self-closed `<head>` element such as `<title/>` the same way. Co-Authored-By: Claude Opus 5.5 <[email protected]>
JuroOravec
force-pushed
the
fix/html-structure-like-browser
branch
from
October 28, 2026 18:59
8603462 to
fb17316
Compare
This was referenced Oct 28, 2026
JuroOravec
added a commit
that referenced
this pull request
Oct 28, 2026
#510 marks the elements the browser places at a component's top level, including a `<div>` that closes an open `<p>`. So in `<p>text<div><a ...></a></div></p>` a finding on the link inside the `<div>` names the component. The test still expected the older result, where only the `<p>` was marked. A second test keeps the case that test was written for: a child component's `<div>` closes the parent's `<p>`, so the browser moves the parent's link out of every root, and the report must not name a component. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Fixes cases 1 and 2 of #302, the two the 0.7.0 triage kept. The other cases stay open in #302 for v1.1.
Case 1: the attribute that scopes a component's CSS lands on the wrong tags
mark_html(crates/citry_html_transform/src/marker.rs) adds a component'sdata-cid-*attribute to the root-level tags of its HTML. Scoped CSS and root lookups depend on it. It counted nesting with shortcuts the browser does not take, so later root tags lost the marker or nested tags got it:script,style,textareaandtitleas elements whose content is text./>as closing the element, while the browser keeps a non-void HTML element written with/>, such as<div/>or<textarea/>, open.The scanner now keeps the names and namespaces of the open elements and follows the browser's rules:
<script>,<style>,<textarea>,<title>,<xmp>,<iframe>,<noembed>,<noframes>and<plaintext>is text.<plaintext>runs to the end of the input.<noscript>stays markup: with scripting off the browser reads it as markup, and Citry's template grammar places child components there.</div>closes its element and everything inside it when the element is in scope. A table end tag (</table>,</tbody>,</tr>and the like) first closes an open cell or caption, so omitted</td>tags work. Any other end tag closes the innermost element with its name, unless an element the browser calls special comes first. An end tag the browser ignores closes nothing.<li>,<dt>or<dd>,<option>,<button>, cell, row, table section or heading ends an open one where the browser does, and a block start ends an open<p>./>closes the element, and<style>,<script>and<title>hold markup. The children of<foreignObject>,<desc>,<title>,<mi>,<mo>,<mn>,<ms>and<mtext>are HTML;<mglyph>and<malignmark>stay MathML.basefont,bgsound,frame,imageandkeygen.<template c-render-id>placeholder Citry leaves for a child component is still split out inside text content and inside<noscript>, so the child's HTML is kept. A child rendered inside a<textarea>now writes its HTML there (as text in the page), where the page used to get the placeholder.serialize.pynow joins a literal placeholder's text back into a leaf at the two places that dropped it, so the per-row path keeps a placeholder written inside a<textarea>like the other paths.classify), and the open-element stack counts the elements each rule can close, so a rule skips its search when nothing it closes is open. A release-build micro-benchmark gives the same times as main: 3.3 µs for a 1.4 KB frame, and about 0.9 ms for 350 KB flat or inside 20 nested<div>s.New test:
tests/marker_browser.rsmarks 104 inputs, parses the result with html5ever as the content of a<div>, and checks that every top-level element carries the marker and no nested element or text does. The inputs cover:<div><i class="icon"/></div>), stray and misnested end tags;<p>,<button>and headings;</td>and</tr>,<object>, SVG and MathML self-closing, integration points and<mglyph>;All 104 agree with html5ever.
Not modelled:
</p>makes the browser create an empty<p>that has no tag in the source, so no marker can go on it. The test leaves this shape out and says why.<p>,<div>,<img>and others), and the scanner keeps those inside.<annotation-xml encoding="text/html">is read as MathML, because the scanner does not read attributes.<plaintext>does not affect the parent's later tags.<a>1<a>2,<b>a<p>b</b>,<nobr>) and some HTML tags inside SVG, which the scanner does not repeat. With<noscript>read as markup, unbalanced content inside it, such as<noscript><p>x</noscript>, is also not modelled. Nor is content the browser moves out in front of a table (<table><p>x</p></table>), or a<td>outside any table, which the browser drops.The Python walk for row markers:
packages/py/citry/citry/_vue/leaf_program.pyplaces row markers at compile time and must agree with the native scan. It now keeps a stack of open element names. It mirrors the text-element and void lists. It declines whenever one of the rules it does not copy could apply: an end tag that is not the innermost element's, an implied end, SVG, MathML,<plaintext>, or a non-void/>.Case 2: Citry UI rejects valid fills that contain
<span/>feed_typed_direct_output(packages/py/citry_ui/citry_ui/components/_direct_output.py) fed a self-closed template element to its HTML parser as<span/>, followed by the</span>the compiler always emits. The page writes<span></span>, so the parser saw an extra end tag. ACMenuItemlabel or aCAccordionItemtitle holding<span/>then failed with "may contain only valid direct ... declarations". The feeder now writes/only for a void element, as the page does.Sweep:
_vue/document.py's head writer had the same pattern. It wrote<title/></title>, which the browser reads the same as<title></title>but which breaks the rule that non-void elements expand. It now matches the other writers.is_self_closingwriters inpackages/pyalready checkis_void.leaf_program.py:3206writes a Vue template, where<x/>is valid syntax._vue/direct_capture.py,parser.rs(#c-ignoreplacement), the grammar's text containers and the formatter's verbatim tags are the same class of bug. Decide HTML structure the way the browser does #302 lists them as unverified and the triage left them for v1.1, so this PR does not change them.Tests
tests/marker_browser.rs(above).tests/marker.rs: each text element;<div/>,<textarea/>and<TEXTAREA/>; SVG and MathML self-closing;<textarea>in<foreignObject>; placeholders inside<xmp>and<noscript>;<i/>inside a parent; a stray end tag;<li/><li/>.citry_core:mark_htmlthrough the Python binding.citry:<p>keeps its marker afterMarkup("<xmp></div></xmp>")and after<div>{{ icon }}</div>withMarkup('<i class="icon"/>'), and gets none afterMarkup("<textarea/>");<noscript>is written, and one inside<textarea>writes its HTML there;<xmp>,<plaintext>, list items and a placeholder inside<textarea>, where the row writer, the per-row scan and the ordinary path must give the same bytes.CMenuItemlabel and aCAccordionItemtitle holding<span/>render like<span></span>. Both tests fail without the fix.<title/>is written as<title></title>, and<meta/>keeps its slash. This test fails without the fix.Run locally:
cargo test -p citry_html_transform, plus clippy and fmt.citry_core, and thecitryserialize, marker, component, Vue, render, deps, static, opaque, raw, markup, simple, leaf and native test files.--platform linux) onleaf_program.py.Not caused by this PR:
test_python_binding_consumes_the_shared_structural_corpusfails on main too. #511 fixes it.Changelog
packages/py/citry_core/CHANGELOG.md: later root tags keep the scoping attribute and nested tags do not get it; a child rendered inside a<textarea>writes its HTML there.packages/py/citry_ui/CHANGELOG.md:CMenuandCAccordionaccept<span/>.🤖 Generated with Claude Code