Skip to content

fix(parse): keep non-numeric fence braces out of highlights - #643

Merged
farnabaz merged 1 commit into
mainfrom
fix/codeblock-highlight-non-numeric-braces
Nov 30, 2026
Merged

farnabaz merged 1 commit into
mainfrom
fix/codeblock-highlight-non-numeric-braces

Conversation

@farnabaz

@farnabaz farnabaz commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Restrict the brace group in a fence info string to numeric highlight syntax (0-9, ,, -, whitespace) inside parseCodeblockInfo.
  • Add SPEC fixtures for ```{1,3-4} (highlights without a language) and ```{x} (non-numeric braces).

Behavior

Fence pre attributes
```{1,3-4} { highlights: [1, 3, 4] }
```{x} { meta: "{x}" }

Previously {x} matched the highlight pattern, produced no numeric ranges, and the group was consumed and dropped. With the numeric-only pattern it falls through to meta, so the information survives parsing and rendering.

Tests

  • cd packages/comark && pnpm vitest run (2656 passed, 4 skipped)
  • New fixtures: packages/comark/SPEC/COMARK/codeblock-highlight-no-language.md, packages/comark/SPEC/COMARK/codeblock-highlight-invalid.md

Credits

Co-authored-by: @EnesKartal, based on #640.


Read this PR faster

Summary by CodeRabbit

  • Bug Fixes
    • Fenced code blocks now recognize highlight annotations containing line numbers and ranges, while other brace-delimited content is treated as metadata.
  • Documentation
    • Added examples showing how highlight ranges and invalid code-block opener metadata appear in parsed output, rendered HTML, and serialized Markdown.

A fence info string such as ```{x} matched the highlight pattern, consumed the brace group, and dropped it because no numeric range was found. Restrict the highlight pattern to digits, commas, dashes, and whitespace so non-numeric braces fall through to `meta` and stay visible in the output.

Add SPEC fixtures for `{1,3-4}` (highlights without a language) and `{x}` (non-numeric braces).

Co-authored-by: Enes Kartal <[email protected]>
@vercel

vercel Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
comark Ready Ready Preview Nov 30, 2026 12:37am UTC
comark-binding Ready Ready Preview Nov 30, 2026 12:37am UTC
comark-json-render Ready Ready Preview Nov 30, 2026 12:37am UTC
comark-nextjs Ready Ready Preview Nov 30, 2026 12:37am UTC
comark-nuxt Ready Ready Preview Nov 30, 2026 12:37am UTC
comark-svelte Ready Ready Preview Nov 30, 2026 12:37am UTC
comark-sveltekit Ready Ready Preview Nov 30, 2026 12:37am UTC
comark-twoslash Ready Ready Preview Nov 30, 2026 12:37am UTC
comark-vue Ready Ready Preview Nov 30, 2026 12:37am UTC

Request Review

@coldtea-pr-lens

coldtea-pr-lens Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Architecture

Walkthrough of Strict line number parsing for codeblock highlights, in two steps

Read this PR faster


Data flow

No data-flow sequence changed in this PR.


Review

✨ Nothing flagged · reviewed aea7d1e


Tip

Set github.draw: on-demand in .github/pr-lens.yml and PR Lens stops drawing pull requests on its own. Comment @pr-lens draw on a pull request when you want that one drawn

🪧 More tips
  • Run npx skills add coldteadotai/pr-lens, then tell your coding agent: "Diagram the change you just made with PR Lens and attach it to the pull request."
  • Run npx @coldtea/pr-lens-cli analyze --base origin/main on a branch, then npx @coldtea/pr-lens-cli render .pr-lens/graph.json. Same lenses, your own model key, before the pull request exists
  • Click the link under each diagram to open it on a canvas you can zoom, pan and step through
  • The diagrams are links. Click one to open it on the canvas, then press W or click play to walk through the change
  • Open a diagram on the canvas, then press W or click play to walk through the change one step at a time
  • The CLI's render reads .github/pr-lens.yml and applies your renames, exclusions and lane pins at draw time
  • Set github.comment.collapsed: true in .github/pr-lens.yml to fold the comment behind one View architecture… row. Drawing still runs as before
  • Add .github/workflows/pr-lens.yml with coldteadotai/pr-lens/packages/action@v0 and your model provider's key as its api-key to run PR Lens from your own CI. Any /chat/completions endpoint works
  • After a push, tick Redraw to draw the latest commit
  • Switch GitHub to dark mode and the diagrams follow. The moving dots are this pull request's data in motion
  • Set github.description: false in .github/pr-lens.yml to stop PR Lens adding buttons to your PR descriptions

Thanks for using PR Lens! It's free for OSS. If it helped, a star helps other teams find it.  Star PR Lens on GitHub

@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The highlight parser now accepts only digits, commas, hyphens, and whitespace inside highlight annotations. Two specifications document highlight ranges and brace-group metadata in parsed, rendered, and serialized code blocks.

Changes: Code fence info parsing

Layer / File(s) Summary
Restrict highlight parsing and document fence examples
packages/comark/src/internal/parse/tree-utils.ts, packages/comark/SPEC/COMARK/codeblock-highlight-no-language.md, packages/comark/SPEC/COMARK/codeblock-highlight-invalid.md
The highlight pattern now accepts only digits, commas, hyphens, and whitespace. The examples show highlight ranges in AST and HTML output, and show {x} retained as metadata and serialized with a preceding space.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Possibly related issues

  • comarkdown/comark#525: The issue includes code-fence brace-group behavior. This change documents and preserves {x} as metadata during parsing, but does not cover the issue’s broader save and round-trip scope.

Suggested reviewers: atinux, onmax

Merge Risk: Minimal · up to aea7d

Code fences with non-numeric brace groups such as {x} now keep that text as metadata instead of having it dropped as highlights. Numeric highlight syntax is unchanged. The change is small, covered by new fixtures, and ready to merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix(parse): keep non-numeric fence braces out of highlights" matches the main change. The PR restricts the brace group parsed by parseCodeblockInfo to numeric highlight syntax (digits, comm…
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(parse): keep non-numeric fence braces out of highlights" matches the main change. The PR restricts the brace group parsed by parseCodeblockInfo to numeric highlight syntax (digits, commas, hyphens, whitespace), so non-numeric groups such as {x} are no longer consumed as highlights. The title names the parser area, the fix type, and the specific behavior. It is concise and free of file lists or vague terms.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • 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

Recent review info

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: 6ad77ad8-19f1-49c0-9651-39da7a316ff3
Commits

Reviewing files that changed from the base of the PR and between 27586c6 and aea7d1e.

Files selected for processing: 3

  • packages/comark/SPEC/COMARK/codeblock-highlight-invalid.md
  • packages/comark/SPEC/COMARK/codeblock-highlight-no-language.md
  • packages/comark/src/internal/parse/tree-utils.ts

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

@pkg-pr-new

pkg-pr-new Bot commented Nov 30, 2026

Copy link
Copy Markdown

Open in StackBlitz

comark

npm i https://pkg.pr.new/comark@643

@comark/angular

npm i https://pkg.pr.new/@comark/angular@643

@comark/ansi

npm i https://pkg.pr.new/@comark/ansi@643

@comark/html

npm i https://pkg.pr.new/@comark/html@643

@comark/nuxt

npm i https://pkg.pr.new/@comark/nuxt@643

@comark/react

npm i https://pkg.pr.new/@comark/react@643

@comark/svelte

npm i https://pkg.pr.new/@comark/svelte@643

@comark/vue

npm i https://pkg.pr.new/@comark/vue@643

commit: aea7d1e

@codspeed

codspeed Bot commented Nov 30, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 2 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 48 untouched benchmarks


Comparing fix/codeblock-highlight-non-numeric-braces (aea7d1e) with main (27586c6)

Open in CodSpeed

@farnabaz
farnabaz merged commit f1ae10b into main Nov 30, 2026
17 checks passed
@farnabaz
farnabaz deleted the fix/codeblock-highlight-non-numeric-braces branch November 30, 2026 00:39
@github-actions github-actions Bot mentioned this pull request Nov 30, 2026

This branch was successfully deployed

8 active deployments
Preview – comark-nuxt — aea7d1ee Deployed Nov 30, 2026 by vercel[bot]
Preview – comark-sveltekit — aea7d1ee Deployed Nov 30, 2026 by vercel[bot]
Preview – comark-twoslash — aea7d1ee Deployed Nov 30, 2026 by vercel[bot]
Preview – comark-json-render — aea7d1ee Deployed Nov 30, 2026 by vercel[bot]
Preview – comark-nextjs — aea7d1ee Deployed Nov 30, 2026 by vercel[bot]
Preview – comark-vue — aea7d1ee Deployed Nov 30, 2026 by vercel[bot]
Preview – comark-svelte — aea7d1ee Deployed Nov 30, 2026 by vercel[bot]
Preview – comark-binding — aea7d1ee Deployed Nov 30, 2026 by vercel[bot]
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