Skip to content

fix(id/web): newline-destination protection skips literal code contexts (#1707) - #3746

Merged
dezren39 merged 1 commit into
mainfrom
queue/4788-1707-newline-destinations
Nov 2, 2026
Merged

dezren39 merged 1 commit into
mainfrom
queue/4788-1707-newline-destinations

Conversation

@dezren39

@dezren39 dezren39 commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Fixes #1707 (queue task 4788).

protect_newline_destinations (pkgs/id/src/web/markdown.rs) now treats all literal contexts as literal, not just plain fenced blocks:

  • Inline code spans: backtick-run tracking — a destination-shaped string inside a span is left byte-identical, so the protection token can no longer leak into a text node and be saved into the file.
  • Indented code blocks: a 4+ space indented line that starts a block (after a blank line / at start / continuing an indented block) is skipped; an indented lazy continuation inside a paragraph is still scanned.
  • Fences: tracking now records the opening fence's character and run length; only a same-character fence at least as long closes the block, so a ``` line inside a ```` block no longer ends it early.
  • Whitespace-only blank lines: the closing-> scan now breaks on \n[ \t\r]*\n, exactly like \n\n, so a paragraph-broken destination is no longer protected into an invented link.

Untouched per the packet scope: the token scheme and the save-side substitute_spaced_destinations.

Tests: new test_newline_destination_protection_skips_literal_contexts pins all four cases plus controls (plain fence unchanged; genuine inline destination still protected; a genuine destination after a fenced block still protected; end-to-end check that no converted doc contains the token and the paragraph-broken shape gains no link mark). Existing #1423 round-trip tests must stay green.

Verification status: targeted cargo test --lib --features web web::markdown is running on the laptop (cold target dir under heavy fleet load); CI on this PR is the deciding run — this PR is parked in the queue awaiting both.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

… inline code spans, indented code blocks, fence char/length respected, whitespace-only blank lines break the destination scan (#1707)
@dezren39
dezren39 requested a review from a team as a code owner November 1, 2026 15:10
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T15:14:24.158122Z b2e6c9f PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 1, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 42 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b629dc63-9b5a-44c3-a729-0f39f39d7bc1
Commits

Reviewing files that changed from the base of the PR and between 3cd23c7 and b2e6c9f.

Files selected for processing: 1
  • pkgs/id/src/web/markdown.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b2e6c9f277

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

};
match (fence, fence_run) {
(None, Some(open)) => fence = Some(open),
(Some((ch, n)), Some((cch, cn))) if cch == ch && cn >= n => fence = None,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep closing fence lines out of inline span tracking

After a backtick fence closes, fence becomes None before literal_line is computed, so the closing backticks reach the inline-code tracker and open a new span. For example, "```\nexample\n```\n\n[y](<c\nd>)\n" now returns no protection token, leaving the subsequent newline-containing link unparseable by comrak and losing its href on reopen. The newly added mixed control also exercises this failure. Treat the closing fence line itself as literal rather than feeding its delimiter into span tracking.

Useful? React with 👍 / 👎.

Comment on lines +266 to +268
match span {
None => span = Some(n),
Some(open) if n == open => span = None,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Only open spans for valid, unescaped backtick delimiters

When an earlier paragraph contains an unmatched or escaped backtick, this unconditional assignment treats subsequent content as code indefinitely, including across paragraph boundaries. For example, "plain unmatched\n\ny\n"` now returns no protection token, whereas the parent commit protects the link. Consequently, an ordinary literal backtick can cause later newline-containing links to lose their link marks and hrefs on reopen. Only matched, unescaped delimiters within the relevant inline block should suppress destination protection.

Useful? React with 👍 / 👎.

// after a blank line (or at the start, or continuing an
// indented block); a 4+ indented line inside a paragraph
// is a lazy continuation, not code.
in_indented = indent >= 4 && fence.is_none() && (prev_line_blank || prev_line_indented);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Account for list indentation before classifying code blocks

For a continuation paragraph inside a list item, four leading spaces do not necessarily indicate an indented code block: indentation must first be measured relative to the list container. For example, "- item\n\n [x](<a\n b>)\n" is now skipped as code even though the link belongs to a normal list-item paragraph. The parent commit protects its destination, but this version leaves it unprotected, so reopening loses the newline-containing link. Classify indentation relative to enclosing containers rather than using the absolute four-space threshold.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant