Files
agent_coder 3042b3e326 fix(converter): T6 bridgeNestedCallouts must not drop a leading #293 directive (#359 review round 2)
Round-2 review found my T6 fix introduced a HIGH data-loss regression: bridgeNestedCallouts
returned document.body.innerHTML, but a comment that LEADS the output is parsed by HTML5 at
document level (child of #document, before <html>) — outside <body> — so body.innerHTML
dropped it. Those are the standalone #293 directives (<!-- pagebreak -->, <!-- subpages -->)
that the LATER applyCommentDirectives pass restores by walking the whole document; since
bridgeNestedCallouts runs first and only needs a `[!` substring anywhere to trigger, a page
that STARTS with a directive AND contains `[!` (a nested callout, or `[!` in text/code)
silently lost the directive.

Fix: before returning, relocate the raw leading document-level comment nodes into the start
of <body> in document order (TreeWalker over SHOW_COMMENT, keeping only nodes not already
contained by body — no double-emit; reverse-prepend preserves order), mirroring the
leading-comment relocation applyCommentDirectives already uses. This pass does NOT interpret
the directives (that stays applyCommentDirectives' job) — it only preserves the raw comments
so the next pass can recover them.

Tests: 3 directive-preservation cases (leading pagebreak + nested callout; pagebreak + `[!`
in inline code — the reviewer's minimal trigger; subpages + `[!` in text), all driven from
markdown that starts with the directive. Mutation-checked: reverting to plain
body.innerHTML reds all 3. prosemirror-markdown 690 passed (687 + 3); git-sync 272 and
datasource 36 unaffected.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-05 21:55:13 +03:00
..