Skip to content

Commit 39aaa3e

Browse files
committed
docs: improve line anchors documentation with usage examples
1 parent 6001806 commit 39aaa3e

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

apps/website/src/docs/shiki/line-anchors.mdx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@ description: Add clickable anchor links to line numbers for easy reference and s
44
category: [Shiki, Markdown, MDX]
55
---
66

7+
<Showcase>
8+
9+
```ts lineNumbers
10+
import { highlight } from "@/utils/shiki/highlight";
11+
import { lineAnchors } from "@/utils/shiki/transformers/line-anchors";
12+
13+
const code = `console.log('Hello World')`;
14+
const highlighter = await highlight();
15+
const html = highlighter.codeToHtml(code, {
16+
lang: "javascript",
17+
transformers: [lineAnchors()],
18+
});
19+
```
20+
21+
</Showcase>
22+
23+
The `lineAnchors` transformer adds clickable anchor links to line numbers. Each line gets an ID like `L1`, `L2`, etc.
24+
725
## Installation
826

927
### shadcn/ui
@@ -33,4 +51,12 @@ const rehypeShikiOptions: RehypeShikiCoreOptions = {
3351
export { rehypeShikiOptions };
3452
```
3553

36-
Then, each line in your code blocks will have an anchor link (e.g., `#L1`, `#L2`) that users can click to navigate to specific lines.
54+
## Usage
55+
56+
Once enabled, users can:
57+
58+
- Click line numbers to navigate to that line
59+
- Share URLs with line anchors: `yoursite.com/docs#L3`
60+
- Link to specific lines: `[See line 5](#L5)`
61+
62+
The clicked line will be highlighted with a blue background and the URL will update to include the line anchor.

0 commit comments

Comments
 (0)