Skip to content

Canonical form owes the author fidelity: strip only editor-injected state - #29

Open
namedgraph wants to merge 1 commit into
masterfrom
canonical-fidelity
Open

Canonical form owes the author fidelity: strip only editor-injected state#29
namedgraph wants to merge 1 commit into
masterfrom
canonical-fidelity

Conversation

@namedgraph

Copy link
Copy Markdown
Member

Problem

Canonicalization conflated two jobs: removing the editor's own ephemera (its duty) and enforcing a class-free storage doctrine on authored content (a host policy, inherited from a since-retired draft of the LDH v6 document format). The second half fails the basic contract an editor owes its data — load, touch nothing, blur, and the document should come back identical. Instead, C2 stripped every authored class/id/style/aria-*/data-*, upon which the attributeless-wrapper rules (C6/C7) dissolved the newly bare wrappers, and S1 dropped button elements outright. In LinkedDataHub this destroyed a styled documentation page through nothing but a click-in/click-out: all 23 classes, 11 ids (anchor targets), every aria-*/hidden, 3 buttons and 7 spans gone, 15 of 16 divs digested into paragraphs.

Change

  • C2 strips only what the editor itself injects — contenteditable, draggable, tabindex="-1" — plus @style, which no editing gesture can author (browsers mint styled spans during editing and paste, so inline style stays in the browser-mess family with font/u).
  • C2b subtracts the editor's own class tokens (rdfa-editor-*, dragging, drop-*, rdfa-invalid) instead of deleting the attribute; authored tokens survive, an emptied attribute drops.
  • cm:authored-attributes() backs the meaninglessness tests: C6 (span unwrap) and C7a/C7b (div→p / div unwrap) now treat any surviving authored attribute as meaning, mirroring how unknown elements are already preserved-and-linted rather than deleted. C8 keeps empty a[@id] — an anchor target, not junk.
  • S1 exempts button: inert markup once S2 strips its on* handlers, and legitimately stored by content components (e.g. ARIA tab strips). form/input/select/textarea/script/iframe/… stay banned.
  • A host with a stricter storage policy layers its own stripping by overriding these templates at higher import precedence — the same mechanism ldh-editor.xsl already uses.

Tests

Canonical fixtures updated to the fidelity contract (region-root host attributes and authored attributes now survive; 07-attr-strip exercises the new split directly). Fixture 05 gains empty-anchor coverage, 11 gains standalone-button coverage. All extractor, lint and canonical suites pass; both SEF flavors compile.

A useful property this buys downstream: an unedited region canonicalizes to exactly what was loaded, so hosts can implement a save dirty-check as a string comparison (LinkedDataHub now does).

🤖 Generated with Claude Code

https://claude.ai/code/session_01S1UnYpbW5aYLj7LbwtyUo1

…ributes round-trip

Canonicalization conflated two jobs: removing the editor's own ephemera
(its duty) and enforcing a class-free storage doctrine on authored content
(a host policy, inherited from a retired draft). The second half made every
save destructive for content the doctrine didn't cover: one click-in/
click-out stripped all class/id/aria-*/hidden attributes, upon which the
attributeless-wrapper rules dissolved the remains into bare paragraphs.

C2 now strips only the editor's injections (contenteditable, draggable,
tabindex="-1") plus @Style, which no editing gesture can author; C2b
subtracts the editor's own class tokens instead of deleting the attribute.
cm:authored-attributes() backs the C6/C7 meaninglessness tests, so an
element keeping any authored attribute is never unwrapped as browser junk,
and C8 keeps empty a[@id] anchors. S1 exempts button - inert markup once
S2 strips its handlers, legitimately stored by content components. A host
with a stricter storage policy overrides these templates at higher import
precedence.

Canonical fixtures updated to the fidelity contract; 05 and 11 gain
coverage for anchor preservation and button survival.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S1UnYpbW5aYLj7LbwtyUo1
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