Repository navigation
Description
Finding
PR #1543 added protect_newline_destinations (pkgs/id/src/web/markdown.rs:138, current main 211aa58f) to the parse side of the id markdown codec: before comrak parsing, it replaces each newline inside an angle-form link/image destination (](<...>), ]: <...>) with a collision-safe token, and restore_attr_newlines (markdown.rs:217) restores the token to a newline afterwards — but only in link href / image src attrs.
The destination/context classification is incomplete in two directions, both verified on current main (function unchanged since #1543 merged):
1. Literal code contexts other than plain fenced blocks are not skipped — the token leaks into text
The doc comment skips fenced code blocks because "a destination-shaped string inside a fence is literal text, not a link". The same applies to contexts the scanner does not track:
- Inline code spans:
`[x](<a\nb>)`— the newline inside the span is replaced byidweb-newline-0-token. Comrak parses span content literally, so the converted PM text node contains the token string;restore_attr_newlinesnever rewrites text nodes, so the document now literally reads`[x](<aidweb-newline-0-tokenb>)`and a save writes the token into the file. The newline is destroyed. - Indented code blocks (4-space indent): same corruption — fence tracking only recognises lines whose first non-space characters (up to 3 spaces) are a fence, and the
](<scan itself is not line-anchored. - Longer fences: fence state toggles on any line starting with
```regardless of the opening fence's length, so inside a````block a```line flips the state early and protection fires inside the still-open literal block.
Probe (faithful port of the function's detection/substitution logic, run this review): all three inputs above come out protected=True with the token substituted into the literal text; the control fenced block and a genuine link behave as intended.
2. The blank-line guard misses whitespace-only blank lines — a non-destination becomes a link
The closing-> scan only breaks on a blank line spelled exactly \n\n (markdown.rs, b'\n' if bytes[k+1] == b'\n'). A blank line containing spaces/tabs (\n \n) does not break the scan, so [x](<a\n \nb>) — which is not a link in CommonMark, the paragraph break ends any destination — is protected across the break and comrak then parses it as a real link whose restored href contains "\n \n". Literal text silently becomes a link node.
Why it matters
markdown_to_prosemirror is the reopen path for every id document; the codec's core contract (the whole #1019/#1423 line of work) is a save/reopen fixpoint that never rewrites content the author didn't touch. Documents that quote markdown link syntax inside code — documentation about linking/markdown is the obvious case — are silently corrupted on open + save, and a paragraph-broken destination can invent a link. Both failure modes are silent: no error, the file on disk changes.
Evidence
- PR: fix(id): widen spaced-destination protection to tab/newline destinations (#1423) #1543 (merged; head commits
5baa46dc…c5e0491f), fixing id(web): link/image destinations containing a tab or newline are corrupted on save — tab becomes %09, newline destroys the link (the #1019 fix only handles spaces) #1423. - Current main
211aa58f97800e7eacf78dad09f8ae31c9ff22ce:pkgs/id/src/web/markdown.rs:110(markdown_to_prosemirror),:138(protect_newline_destinations),:217(restore_attr_newlines— rewrites onlyhref/srcstring attrs). - Probe script and outputs from this review are kept in the goal workspace (
hidden_files/probe-1543/probe.py): inline code span, indented block, and 4-backtick fence cases all substitute the token into literal text; the\n \ncase is protected across the paragraph break; controls (plain fence,\n\n, genuine link) behave as designed. - Dedupe: open + closed issue search for
idweb-newline, "code span destination", "newline token",protect_newline_destinations— only id(web): link/image destinations containing a tab or newline are corrupted on save — tab becomes %09, newline destroys the link (the #1019 fix only handles spaces) #1423 itself (closed, the space/tab/newline save-direction fix); nothing covers the parse-side literal-context or whitespace-blank-line gaps.
Acceptance criteria
- A destination-shaped string inside an inline code span or an indented code block is left byte-identical by
markdown_to_prosemirror(no token in any text node after conversion). - Fence tracking respects the opening fence's character and length: a shorter fence line inside a longer fence does not end the literal block.
- A whitespace-only blank line (spaces/tabs between the newlines) breaks the destination scan exactly like
\n\n. - Regression tests in
pkgs/id/src/web/markdown.rspin all of the above plus the existing id(web): link/image destinations containing a tab or newline are corrupted on save — tab becomes %09, newline destroys the link (the #1019 fix only handles spaces) #1423 behaviours (genuine inline + reference destinations with newlines still round-trip). - No converted document ever contains the protection token outside an
href/srcattr.
Activity
developing-today commentedon Oct 28, 2026
CODE-684
dezren39 commentedon Oct 28, 2026
🤖 Agent note · filed
5baa46dc…c5e0491f, for id(web): link/image destinations containing a tab or newline are corrupted on save — tab becomes %09, newline destroys the link (the #1019 fix only handles spaces) #1423) added parse-sideprotect_newline_destinationsinpkgs/id/src/web/markdown.rs(current main211aa58f, function at :138 unchanged). Its classification is incomplete both ways: (1) inline code spans, indented code blocks, and the inside of longer (````) fences are not skipped, so a destination-shaped string there gets its newline replaced by theidweb-newline-0-token, comrak keeps it as literal text, and `restore_attr_newlines` (:217) only restores `href`/`src` attrs — the token is written into the document text; (2) the blank-line scan guard only matches exactly `\n\n`, so a whitespace-only blank line (`\n \n`) lets protection join a non-destination across a paragraph break into a link comrak then parses. Verified by a faithful Python port of the verbatim detection/substitution logic (probe in the goal workspace, `hidden_files/probe-1543/probe.py`): all four gap inputs substitute/join; controls (plain fence, `\n\n`, genuine link) behave as designed. Deduped against open+closed issues (only id(web): link/image destinations containing a tab or newline are corrupted on save — tab becomes %09, newline destroys the link (the #1019 fix only handles spaces) #1423 itself).18 remaining items
dezren39 commentedon Nov 1, 2026
🤖 Agent note · picked up
b2e6c9f, authored by Drew (dezren39). The runbook prohibits modifying or merging Drew-owned PRs.dezren39 commentedon Nov 1, 2026
🤖 Agent note · escalated to Drew
escalated-to-user. PR fix(id/web): newline-destination protection skips literal code contexts (#1707) #3746 is OPEN and authored by Drew (dezren39), so this lane cannot touch it under the runbook.b2e6c9f; branch is 14 commits behind main. Current PR view shows only CodeRabbit neutral; required checks are not complete/green.Merge pull request #3746 from developing-today/queue/4788-1707-newlin…