Skip to content

id(web/markdown): strip_leading_blank_quote_lines deletes a literal blank line at the start of a top-level fenced code block on save (residual of #1002 / PR #4816) #8665

Closed

Description

@dezren39

Bug

strip_leading_blank_quote_lines (pkgs/id/src/web/markdown/markdown_serialization.rs, the #1002 save-path stripper) has no fenced-code-block state. On save, it deletes a literal blank line from the start of a top-level fenced code block whose first content lines look like quote lines.

Verified end-to-end on origin/main f44b820 (laptop probe binary calling markdown_to_prosemirror → prosemirror_to_markdown):

  • IN: "```\n> \n> text\n```\n" → OUT: "```\n> text\n```\n" — the code block's first line (> ) is gone.
  • IN: "```rust\n> \n> text\n```\n" → OUT: "```rust\n> text\n```\n" — same loss.
  • Controls round-trip fine: quoted fence "> ```rust\n> code\n> ```\n", "> paragraph\n".

Mechanism: the fence opener line is neither a blank quote line nor quote content, so the scan sets at_quote_start = true; the next line (> , blank quote) is then treated as the start of a quote run, and the lookahead sees > text (quote content) and strips the blank — even though both lines are literal code content inside the fence.

Origin

This is the unresolved CodeRabbit Major finding on PR #4816 (discussion r4452869637, #4816 (comment)), which merged for #1002 without the finding being dispositioned. It was flagged again by task 6565's park reason; this filing is that investigation's result (task 6565, lane code-a, 2026-11-11). The neighbouring restore_github_alert_markers in the same file already tracks fences (FenceTracker in markdown_scan.rs) for exactly this reason.

Fix shape

Track fenced-block state in strip_leading_blank_quote_lines (reuse FenceTracker + split_quote_prefix, as restore_github_alert_markers does): never strip lines inside a fence, at any quote depth. Add round-trip regression tests: top-level backtick/tilde fences whose first content lines are > + > text, plus the existing #1002 controls (fence/table/rule-first quotes still strip their leading blanks).

Acceptance: the probe cases above round-trip byte-identically; the existing web::markdown tests (incl. test_blockquote_leading_block_round_trips_without_extra_blank_lines) pass.

🤖 Filed by repo-queue worker lane code-a (task 6565) — agent-note:v1 state=filed at=2026-11-11T12:37:00Z

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/idPackage/app: id (pkgs/ or apps/ in this repo)kind/bugSomething isn't working (prefixed form of the classic bug label)status:done

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions