Repository navigation
Commit bbfef6b
fix(md): preserve fence line-highlight ranges from markdown-it-attrs (#228)
## Problem
Code-fence **line highlighting** via the Shiki `{1,3-5}` meta syntax
silently does nothing in `@void/md`:
````md
```ts {2}
const a = 1
const b = 2
```
````
No line gets the `highlighted` class.
## Root cause
`createCompiler` registers `transformerMetaHighlight()` and passes
`meta: { __raw: token.info }` to Shiki — correct. But
`markdown.use(attrs)` (`markdown-it-attrs`) treats the `{…}` after the
fence language as an attribute block and **strips it from `token.info`
at parse time**. By render time `token.info` is just `"ts"`, so
`transformerMetaHighlight` finds no range and no-ops.
```
MarkdownExit → token.info = "ts {2}"
markdown-it-attrs → token.info = "ts" ← {2} eaten here
codeToHtml(meta:{__raw:"ts"}) → no .highlighted
```
## Fix
Snapshot the original fence info onto `token.meta.rawInfo` with a core
rule anchored `after('block')` (fence tokens exist) and before
`curly_attributes` (which runs after `inline`), then feed `rawInfo` to
Shiki via `meta.__raw`. `markdown-it-attrs` still applies to non-fence
content unchanged.
## Tests
Added `compile.test.ts` cases:
- single `{N}`, range `{N-M}`, combined `{a,c-d}`
- a comment-less language (`text {1}`) — works, unlike comment-notation
highlighting
- no curly meta → stays unhighlighted
- `{.class}` on prose → markdown-it-attrs still applies
> Note: verified locally by running `compile()` directly against the
source (all cases pass). I could not run `vp test`/`vp fmt`/`tsgo` in my
checkout because `vite-plus`/`tsgo` weren't installed there — CI should
exercise the full harness.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Low Risk**
> Targeted markdown pipeline fix with unit tests; no auth, data, or API
surface changes.
>
> **Overview**
> Restores **Shiki fence line highlighting** (`{2}`, `{2-3}`, `{1,3-4}`,
etc.) in `@void/md` by keeping the full fence info string before
`markdown-it-attrs` strips the `{…}` portion from `token.info`.
>
> A new core rule **`stash_fence_info`** runs after `block` and copies
each fence’s original `token.info` to **`token.meta.rawInfo`**. The
custom fence renderer passes that value to Shiki as **`meta.__raw`**
instead of the stripped `token.info`, so **`transformerMetaHighlight`**
receives the line ranges again.
>
> **Tests** in `compile.test.ts` assert highlighted line indices for
single lines, ranges, combined specs, and `text` fences; they also cover
fences without curly meta and confirm `{.class}` on prose still works
via `markdown-it-attrs`.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
cad773f. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>1 parent 047f48a commit bbfef6b
2 files changed
Lines changed: 62 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
85 | 93 | | |
86 | 94 | | |
87 | 95 | | |
88 | 96 | | |
89 | 97 | | |
90 | | - | |
| 98 | + | |
91 | 99 | | |
92 | 100 | | |
93 | 101 | | |
| |||
109 | 117 | | |
110 | 118 | | |
111 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
112 | 134 | | |
113 | 135 | | |
114 | 136 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
41 | 79 | | |
42 | 80 | | |
43 | 81 | | |
| |||
0 commit comments