Link example documents to their elements #4
Loading…
Reference in a new issue
No description provided.
Delete branch "example-links"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Requested by Moof · project thread
Adds
--examples DIR. Every.xmlfile under the directory gets a page underexamples/with its element names linked to their declarations, and every global element page gets an Examples section listing the examples that use it, each linked to the line of its first occurrence (with an occurrence count). The index gets an "All N examples" tree, like the source-file one.How elements are matched
Each element is resolved against its parent's content model (base types, groups, compositors, substitution groups,
xsi:type), so a local element links to the row that declares it:<Name>inside a<Line>goes toline.html#d213-341, not to some otherName. When the content model doesn't explain an element (wildcards, unknown parents, invalid examples) it falls back to a global element with the same name. On the 290 NeTEx examples againstNeTEx_publication.xsd, 856,807 of 857,797 start tags get a link.Size
Example pages store the document as plain text (only
&and<escaped) plus a compact list of link targets per start tag, andsite.jshighlights it and adds the links in the browser. Line numbers use the CSS counter from #3. For NeTEx, the examples are 53 MB of XML and theexamples/output is 64 MB; rendering them server-side with a link per tag would have roughly doubled that. The largest example (5 MB, 139k lines) renders in about 7 s in headless Chromium; lines are laid out in 200-line chunks withcontent-visibility: auto, so find-in-page still works. Typical examples render in well under a second.Without
--examplesthe output is unchanged.Testing
tests/test_examples.pywith small fixture examples: context-aware resolution (global, local, unknown), first-occurrence lines and counts, CLI output, and no change without the option. Full suite: 43 passed.NeTEx_publication.xsdwithNeTEx/examplesand checked in headless Chromium: links,#L-nfirst-occurrence targets scrolling and highlighting, gutter clicks, no console errors.🤖 Generated with Claude Code
https://claude.ai/code/session_01F2T5yLBWpYT83XFbEYaKPT