Skip to content

id(web): #1543's newline-destination protection rewrites literal code text (code spans, indented blocks, long fences) and joins destinations across whitespace blank lines #1707

Closed

Description

@dezren39

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 by idweb-newline-0-token. Comrak parses span content literally, so the converted PM text node contains the token string; restore_attr_newlines never 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

Acceptance criteria

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/triageQueue packet kind: verify, reproduce, and route this item
    priority/normalOrdinary priority (the default)
    app/idPackage/app: id (pkgs/ or apps/ in this repo)
    effort/sSmall: expected under 2 hours of work
    on Oct 28, 2026
  2. developing-today commented on Oct 28, 2026

    @developing-today
    Contributor
  3. dezren39 commented on Oct 28, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

  4. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Nov 1, 2026
  5. 18 remaining items

  6. added and removed
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    on Nov 1, 2026
  7. dezren39 commented on Nov 1, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

  8. added
    user/escalatedRequires a Drew decision or access
    queue/blockedQueue or user escalation state
    status/blockedQueue or user escalation state
    and removed
    queue/claimedQueue worker lifecycle state
    on Nov 1, 2026
  9. dezren39 commented on Nov 1, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · escalated to Drew

  10. added a commit that references this issue on Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

app/idPackage/app: id (pkgs/ or apps/ in this repo)effort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/pr-diff-reviewFiled by the pr-diff-review jobstatus:in-reviewtask/triageQueue packet kind: verify, reproduce, and route this itemuser/escalatedRequires a Drew decision or access

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions