Skip to content

Support inline code diff notation - #2

Merged
tannerlinsley merged 1 commit into
mainfrom
taren/fix-code-diff-notation
Jul 27, 2026
Merged

Support inline code diff notation#2
tannerlinsley merged 1 commit into
mainfrom
taren/fix-code-diff-notation

Conversation

@tannerlinsley

@tannerlinsley tannerlinsley commented Jul 27, 2026

Copy link
Copy Markdown
Member

What changed

  • Parse trailing [!code ++] and [!code --] directives at the Markdown adapter boundary.
  • Remove directives before tokenization and copying.
  • Emit th-line--inserted and th-line--deleted decorations.
  • Support line, block, hash, and HTML comment forms.
  • Document and test the behavior.

Why

TanStack docs already use Shiki's inline diff notation. The new Highlight renderer treated those directives as literal source, leaking them into rendered and copied code.

Validation

  • pnpm run verify
  • 46 tests passed
  • Package, docs, size, and benchmark checks passed

Summary by CodeRabbit

  • New Features
    • Added inline code-diff notation using [!code ++] and [!code --] markers.
    • Code examples now display inserted and deleted line styling while removing markers from copied and rendered code.
    • Supports JavaScript, shell/Python, and HTML comment formats.
    • Added documentation for parsing and rendering inline code differences.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Inline ++ and -- code directives are parsed into line decorations, removed before highlighting and copying, merged with existing fence annotations, and covered by parser, fence-rendering, and adapter tests.

Changes

Inline code diff notation

Layer / File(s) Summary
Notation parser and contract
src/markdown.ts, docs/reference/markdown.md, docs/guides/annotations.md, test/adapters.test.ts
Adds parseCodeDiffNotation, supports multiple comment syntaxes, strips directives, and returns inserted/deleted line decorations with unit coverage.
Code-fence decoration merging
src/markdown.ts, docs/reference/markdown.md, test/adapters.test.ts
Merges inline, metadata, and explicit decorations while rendering cleaned code and validating inserted-line markup.
Highlighter integration
src/markdown.ts, test/adapters.test.ts
Tokenizes notation-stripped code, includes inline decorations with highlighted lines, and validates deleted-line markup without raw directives.

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

Sequence Diagram(s)

sequenceDiagram
  participant MarkdownInput
  participant parseCodeDiffNotation
  participant renderCodeFence
  participant TanStackMarkdownHighlighter
  MarkdownInput->>parseCodeDiffNotation: Provide code with inline diff directives
  parseCodeDiffNotation-->>renderCodeFence: Return cleaned code and line decorations
  renderCodeFence->>TanStackMarkdownHighlighter: Pass cleaned code and merged decorations
  TanStackMarkdownHighlighter-->>MarkdownInput: Return highlighted markup without directives
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately reflects the main change: adding support for inline code diff notation.
Description check ✅ Passed The description covers the behavior, motivation, and validation, though it uses different headings than the template.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch taren/fix-code-diff-notation

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/markdown.ts`:
- Around line 149-155: Update the decoration assembly in the markdown rendering
flow around parseCodeDiffNotation and parseCodeFenceMeta to preserve mappings
for stripped directive spans and rebase caller-provided range decorations from
the original code onto the cleaned text before combining them. Keep parsed and
annotated decorations intact, and add coverage for a range on a line following a
removed directive to verify it renders at the corrected offset.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 26c77796-82ab-4ef8-ac32-972ff4f9a8c2

📥 Commits

Reviewing files that changed from the base of the PR and between 0f355b6 and 45649ac.

📒 Files selected for processing (4)
  • docs/guides/annotations.md
  • docs/reference/markdown.md
  • src/markdown.ts
  • test/adapters.test.ts

Comment thread src/markdown.ts
Comment on lines +149 to +155
const annotated = parseCodeDiffNotation(code)
const parsed = parseCodeFenceMeta(meta)
const resolvedDecorations = [...parsed.decorations, ...(decorations || [])]
const resolvedDecorations = [
...annotated.decorations,
...parsed.decorations,
...(decorations || []),
]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Rebase range decorations after stripping directives.

decorations can contain character-range offsets for the original code. Removing a directive shifts all later offsets, so caller-provided range decorations render on the wrong text. Preserve removed-span mappings and rebase range decorations before rendering; add coverage for a range on a line after a directive.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/markdown.ts` around lines 149 - 155, Update the decoration assembly in
the markdown rendering flow around parseCodeDiffNotation and parseCodeFenceMeta
to preserve mappings for stripped directive spans and rebase caller-provided
range decorations from the original code onto the cleaned text before combining
them. Keep parsed and annotated decorations intact, and add coverage for a range
on a line following a removed directive to verify it renders at the corrected
offset.

@tannerlinsley
tannerlinsley merged commit 23ceca7 into main Jul 27, 2026
4 checks passed
@tannerlinsley
tannerlinsley deleted the taren/fix-code-diff-notation branch July 27, 2026 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant