Repository navigation
Markdown: bound container nesting to Chromium's 512-element parser limit - #1122
Conversation
Track open container elements across lists, list items and block quotes up to 510 elements (255 nested lists or 510 nested block quotes, matching Chromium's 512-element HTML parser cap after `<html>` and `<body>` in `DOMParser`), flattening deeper list items as siblings at the final list level and deeper block quotes into the final quote. Widen `Flow::cols` from `u8` to `usize` so copy indentation no longer wraps past 127 levels, and split `collapsed` top and bottom edge scans so single-child nested containers walk linearly instead of branching `2^D` times.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
|
Windows whole suite ( |
…ratively, and cap flattened streaming tails
…uments fit V8's call stack
…ent targets, and key quote plain cache by block
…ist markers, and keep marker unselectable
In Blink's HTML parser (
HTMLConstructionSite::AttachLater,kMaximumHTMLParserDOMTreeDepth=512including<html>and<body>), elements nest up to 511 open elements under<body>(255nested bullet or ordered list levels,1quote +255nested list levels,10quotes +250list levels, or510non-empty<blockquote>s; text nodes still attach to the current element). Past that bound, deeper list items flatten as sibling items in the innermost list (or open a single 1-level list when a list starts inside a deep quote so bullets and task checkboxes stay intact), and deeper block quotes merge their inner blocks into the last quote (510on Windows, macOS, and Linux;385on web and other unguarded targets — so386..510quotes draw differently on the web than natively). Neither flattening bound displays a visual marker; only when a single container accumulates more than64flattened items or blocks past the bound are the remaining lines grouped into one selectable, searchable plain block preceded by an unselectable"N more nested lines"(rune::Label::MoreNestedLines) marker.flowchart LR P["pulldown-cmark events"] --> B{"MAX_ELEMENT_DEPTH = 511<br/>(+ 770-flex-container bound outside Win/macOS/Linux)"} B -->|"Fits (or first list in Quote)"| N["Push Container::List + Item / Quote"] B -->|"Past bound (items 1..=64)"| F["Flatten as siblings in last List / merge into last Quote<br/>(no marker at bound)"] B -->|"Past bound (item 65+)"| T["Keep all remaining lines in 1 UTF-8-chunked plain block<br/>+ unselectable 'N more nested lines' a11y marker"] N & F & T --> R["Iterative Dirs + Renderer + plain_iter<br/>(O(1) call stack in rune-kit)"]crates/rune-kit/src/markdown/parser.rs,markdown.rs):Builder::depth() + 2 <= MAX_ELEMENT_DEPTH(511) matches Blink on odd quote counts (1quote +255lists nests all255levels) and preserves a single list container when a list opens inside a 509/510-deep quote so bullets and- [ ]/- [x]task checkboxes (with exact source byte offsets andBuilder::pushtasksalignment) render intact. Outside#1120'scfg(any(windows, target_os = "macos", target_os = "linux"))segment gate (wasm32,ios,android, etc.),MAX_UNGUARDED_LAYOUT_DEPTH = 770preserves all255list levels (765),1quote +255lists (767), and10quotes +250lists (770) while capping pure<blockquote>nesting at385(770flex containers) so V8's ~984 KiB WebAssembly call stack and 1–2 MiB mobile main threads do not overflow.crates/rune/src/labels.rs,crates/rune-kit/src/markdown/{parser,cache,find,stream,plain,render}.rs):Builder's real past-bound container state (QuoteSlot::Merged/ListSlot::SiblingItems— never inside a code block and never on< 255nested ordered lists, unwinding any open inner list cleanly so list items never double their marker), items past the 64th flattened item in a container are kept in one plain block (BlockMap::DeepTail), split into32 KiBchunks on newline bytes or valid UTF-8 character boundaries (is_char_boundary), and preceded by an unselectableRole::Noteheader carryingrune::Label::MoreNestedLines(n)("N more nested lines") as its accessibility label only (so neither selection copy norQuoteFramecopies the marker line as content).>, so a line made only of those characters disappears while list markers and[ ]remain as text; every kept byte maps 1-to-1 viaSpanMapback tosrc, soMarkdown::find, highlights, and source copy remain exact — identically while streaming (extended incache.rswith uncapped2 * src.len()budget accounting) and once settled.O(1)-stack rendering, linearbidi, collision-freeQuotePlainCache, and existingrune-kitchecks (crates/rune-kit/src/markdown/{render,bidi,plain}.rs):Renderer::blocks_in_with_dirs,bidi::Dirs::new,plain_iter, andcollapsed_top/collapsed_bottomrun iteratively on heap stacks in linear time,Flow::cols/Lead::widthwiden fromu8tousizefor copying past 128 levels, andQuotePlainCacheskips empty quotes while keying by(quote_block_ptr, first_task, cols, lists) -> (task_delta, breaks, text)so emptyVec<Block>slices never collide or rewindtask.rune-kittest program (50targets withmarkdown+mermaid):439passed,0failed (3ignored), matchingdev23096262(439passed,0failed).Side-by-side captures at 1× raster scale (
1280×800, light)16px/level acrossx = 324..628)16px/level tox = 1268at column edge)255nested levels tox = 4388)255..260flatten as siblings atx = 4388)28px/nested level acrossx = 324..856)255..260flatten as siblings atx = 7436, numbered1..6)510merge into quote510)Stack peaks across native (
8 MiB) & WebAssembly (2 MiB-zstack-size=2097152)8,388,608B reserve, without#1120)2,097,152B shadow stack — Chromium 159 / Firefox 159 / WebKit 27.2)list-255(255nested lists)2,060,288B (1.96 MiB)1,022,360B (0.97 MiB, all 3 engines open)mixed-1q-255ul(1quote +255lists)2,064,384B (1.97 MiB)1,024,760B (0.98 MiB, all 3 engines open)mixed-10q-250ul(10quotes +250lists)2,068,480B (1.97 MiB)1,028,360B (0.98 MiB, all 3 engines open)quote-510/quote-511(510/511quotes)2,711,552B (2.59 MiB)1,028,360B in Chromium (385quotes =770flex containers;1,328,360B at510quotes in Firefox & WebKit)