Skip to content

fix(shared): Markdown footnotes find definitions inside blockquotes - #48485

Open
StiensWout wants to merge 7 commits into
pingdotgg:mainfrom
StiensWout:wf/find-f085be312d69e7c56e56287b
Open

StiensWout wants to merge 7 commits into
pingdotgg:mainfrom
StiensWout:wf/find-f085be312d69e7c56e56287b

Conversation

@StiensWout

Copy link
Copy Markdown
Contributor

In long Markdown files that are previewed in pieces, a footnote reference showed as literal [^label] text when its definition was in a blockquote or list item in a later piece (for example > [^source]: Quoted source note. under a Sources heading). The splitter now finds definitions behind quote and list markers by parsing only that container with the preview's own Markdown and math rules, and adds them to the shared footnotes section, so the reference renders as a linked footnote. Look-alike definitions in quoted code, HTML or display math stay plain text, a long block after the container no longer hides a short definition, and quotes nested too deeply for the parser still split and display without linking.

Related: #48228, #48065, #48370

Reproduction on main

Commit efbd62a7a7 (main). The opening paragraph shows [^source] as literal text. Expected: The opening paragraph shows a clickable footnote number linked to the quoted note.

  1. Start sources.md with See the source[^source].
  2. Add a blank line and a paragraph of about 4,800 characters.
  3. After a blank line, add a ## Sources heading followed by a blank line and > [^source]: Quoted source note.
  4. Open sources.md in a local project’s file preview.
  5. Switch to rendered Markdown.

The cause is at packages/shared/src/markdownChunks.ts:1062. Ran pnpm scenarios:prove scripts/scenarios/markdown-footnote-finds-quoted-definition.e2e.ts --target web with the repro scenario added: it failed in 2 of 2 runs on a clean boat.dev VM, with expect.toHaveCount failed in the output.

Evidence

Environment: The web app in Chromium on Linux x64, a fresh checkout on a boat.dev VM reset before each run.

Proven: the repro fails at the test commit c96c2cfc94 and passes on the head d87573e54b, both on main efbd62a7a7.

Before After
Commit c96c2cfc94 d87573e54b
Result ASSERTION_FAILED: expect.toHaveCount failed passed
quoted footnote definition Before: quoted footnote definition Before: quoted footnote definition (changed region)
The opening paragraph shows [^source] as literal text.
After: quoted footnote definition After: quoted footnote definition (changed region)
The opening paragraph shows a clickable footnote number linked to the quoted note.
failure Before: failure
Recording Before: recording After: recording

Tests

  • c96c2cfc94 adds the failing test, alone, before the fix.
  • pnpm exec vp run check:changed efbd62a7a700a29ad545f8334b2139407875dab3 passed on head.

Not in this change

  • A [^label] written inside indented code in a quote is still counted as a footnote reference and gets an extra backlink. This already happens with ordinary top-level definitions and needs separate handling of quoted code.
  • If the text around a quote or list is longer than the 64 KiB footnote limit, its definitions only work within their own piece, as before.
  • Mobile file previews use the same shared splitter, so they get this fix too, but no mobile-specific test was added.

Who did the work

  • Repro written by GPT 6.2 Sol, in Codex
  • Duplicate check judged by Claude Opus 5.5, in Claude Code
  • Written by Claude Opus 5.5, in Claude Code
  • Reviewed by Claude Opus 5.5, in Claude Code, and by GPT 6.2 Sol, in Codex
  • Reproduction, checks and proof run by a program on base and head, not by an agent

Made in T3 Code by Claude Opus 5.5 and GPT 6.2 Sol

StiensWout and others added 7 commits December 3, 2026 23:20
…quote

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Chunked Markdown previews collected footnote definitions only at the start of a
line, so a definition inside a blockquote in a later chunk left its reference
as literal text. Look past quote markers and end the definition where its quote
paragraph ends.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
A quote can hold fences, HTML and indented code, so a quoted line that looks like
a definition is checked against the parsed quote instead of a line pattern.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…view does

Parse the container with the preview's math syntax so quoted display math stays
math, stop at the container's end so a long following block cannot hide a short
definition, accept list markers around the quote, and keep the source chunked when
nesting is too deep for the parser.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…ep quotes

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Dec 3, 2026
if (lineIndex > containedFootnotesParsedThrough) {
// Parse this container's lines once; past the cap its definitions stay local.
let end = lineIndex + 1;
while (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟠 High src/markdownChunks.ts:1114

A blank line ends the lookahead for a list footnote, so containedFootnoteEnd excludes valid indented continuation paragraphs and the shared footnote output drops their text. Include blank lines in the parser input and let readContainedFootnotes determine where the definition ends.

🤖 Copy this AI Prompt to have your agent fix this:
In file @packages/shared/src/markdownChunks.ts around line 1114:

A blank line ends the lookahead for a list footnote, so `containedFootnoteEnd` excludes valid indented continuation paragraphs and the shared footnote output drops their text. Include blank lines in the parser input and let `readContainedFootnotes` determine where the definition ends.

@macroscopeapp

macroscopeapp Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Would Approve

Macroscope's review found this PR approvable — This extends Markdown preview footnote extraction to blockquotes and lists, with bounded parsing and fallback behavior. The reported continuation-text omission remains subject to the separate correctness blocking gate; no additional material risk was identified.

Needs human approval because:

  • 1 blocking correctness issue found at or above your repo's Minimum Blocking Severity

Adjust the Minimum Blocking Severity for this repo — including turning it Off — in Settings. You can add or adjust custom eligibility rules. Learn more.

@coderabbitai

coderabbitai Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Markdown chunker now detects footnote definitions inside blockquotes and lists, and collects their content through the parsed definition’s end. Tests cover nested definitions, excluded look-alikes, deep nesting, and a rendered quoted footnote.

Changes: Nested Footnote Collection

Layer / File(s) Summary
Detect definitions inside containers
packages/shared/src/markdownChunks.ts
The chunker parses bounded container regions to identify footnote definitions and their ending lines. If parsing throws or does not identify a definition, the existing line-start detection path remains available.
Collect definitions and verify Markdown behavior
packages/shared/src/markdownChunks.ts, packages/shared/src/markdownChunks.test.ts, scripts/scenarios/markdown-footnote-finds-quoted-definition.e2e.ts
The chunker collects contained definitions through their parsed end. Unit tests cover valid definitions, excluded look-alikes, and deep nesting. The end-to-end scenario checks a quoted definition in rendered Markdown.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: saphid, iamshadmantaqi

Merge Risk: Minimal · up to d8757

This change makes Markdown footnote definitions inside blockquotes and lists link correctly in chunked previews. No merge-blocking issue remains. A list footnote with blank-line-separated paragraphs may show only its first paragraph, which is a narrow edge case and an improvement over the previous unlinked behavior.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(shared): Markdown footnotes find definitions inside blockquotes" names the primary change. The changeset makes the markdown chunk splitter find footnote definitions inside blockquotes a…
Description check Passed The description follows the repository template closely. It has a clear Problem section with reproduction steps, a Change section that explains the parser-based container approach, a Scope section tha…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix(shared): Markdown footnotes find definitions inside blockquotes" names the primary change. The changeset makes the markdown chunk splitter find footnote definitions inside blockquotes and list items, and the raw summary and objectives match this. It uses a conventional commit prefix and a specific description. It does not mention list items, which the change also covers, but it is not overly broad or misleading.

Full details: Description check

Explanation

The description follows the repository template closely. It has a clear Problem section with reproduction steps, a Change section that explains the parser-based container approach, a Scope section that links related issues (#48228, #48065, #48370) but does not link the issue that shows the bug, and a Verification section with a failing-then-passing test proof and a check run. It also states the model and harness used. The Scope section gap is minor: it does not state a linked bug issue or explain why no issue is needed. The template's required structure is otherwise present, so the check passes.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between efbd62a and d87573e.

Files selected for processing: 3

  • packages/shared/src/markdownChunks.test.ts
  • packages/shared/src/markdownChunks.ts
  • scripts/scenarios/markdown-footnote-finds-quoted-definition.e2e.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

This branch has not been deployed

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

Labels

size:L 100-499 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant