Serialize the Source view as Exclusive XML Canonicalization#20
Merged
Conversation
serialize(indent:true()) was no canonical form at all: SaxonJS indents between the element children of mixed content (injecting whitespace that renders, e.g. around a figcaption's <br/>s), empty elements stayed self-closed and attribute order was arbitrary. Port LinkedDataHub's ldh:canonicalize-xml instead: vendor its xml-c14n-sync.js bundle (W3C xml-exc-c14n#WithComments, the rdf:XMLLiteral value space) and run the canonical tree through it — serialize() → parse-xml() bridges the XDM temporary tree to the browser DOM the lib walks. Host pages now include the lib alongside SaxonJS3.js. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Problem
The Source view serialized the canonical tree with
serialize(…, indent: true()), which is not a canonical form at all:<br/>s:<br/>), attribute order was arbitrary, namespace declarations unsorted — none of the c14n rules applied.Fix
Port LinkedDataHub's
ldh:canonicalize-xmlpattern:xml-c14n-sync.jsbundle (W3C Exclusive XML Canonicalization,xml-exc-c14n#WithComments— therdf:XMLLiteralvalue space, i.e. the form this content is headed for in the LDH v6 format) intolib/, loaded alongsideSaxonJS3.jsbyindex.htmland the test fixtures.local:canonicalize-xmlinedit.xsl:serialize()→parse-xml()bridges the XDM temporary tree to the browser DOM the lib walks, thencanonicaliseSyncproduces the canonical string. The view-source handler now emits that instead of the indented serialization.Output is now e.g.
…its three<br></br><br></br> parts.— start/end tag pairs for empty elements, sorted attributes (<img alt="…" src="…">), sorted namespace declarations, no serializer-injected whitespace; only the document's own whitespace survives.Note: exclusive c14n (not c14n 1.1) is deliberate — it's what
rdf:XMLLiteralspecifies and what LDH uses for XMLLiteral persistence; for standalone fragments with no inherited namespace context the two coincide.Embedding contract
Host pages now include
lib/xml-c14n-sync.jsnext toSaxonJS3.js(README + CLAUDE.md updated).Testing
🤖 Generated with Claude Code