Skip to content

Commit 43c05cb

Browse files
committed
docs: update documentation for Shiki transformers with usage examples and style customization
1 parent 74d9826 commit 43c05cb

File tree

5 files changed

+69
-35
lines changed

5 files changed

+69
-35
lines changed

apps/website/src/docs/shiki/add-properties.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const rehypeShikiOptions: RehypeShikiCoreOptions = {
6464
export { rehypeShikiOptions };
6565
```
6666

67-
### Properties
67+
## Properties
6868

6969
### `addTitleProperty`
7070

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

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,17 @@ const html = highlighter.codeToHtml(code, {
3131

3232
<ShowSource component="shiki-show-line-numbers" />
3333

34-
2. Import the transformer in your `rehypeShiki` plugin:
34+
2. Customize the styles in your CSS file if needed:
3535

36-
```ts title="Rehype Shiki Options"
36+
<DocCard folder="shiki" document="highlighter" anchor="styles" />
37+
38+
## Usage
39+
40+
### `shikijs/rehype`
41+
42+
1. Import the transformer in your `rehypeShiki` plugin:
43+
44+
```ts {1,5} title="Rehype Shiki Options"
3745
import { showLineNumbers } from "@/utils/shiki/transformers/show-line-numbers";
3846

3947
const rehypeShikiOptions: RehypeShikiCoreOptions = {
@@ -44,16 +52,36 @@ const rehypeShikiOptions: RehypeShikiCoreOptions = {
4452
export { rehypeShikiOptions };
4553
```
4654

47-
3. Customize the styles in your CSS file if needed:
48-
49-
<DocCard folder="shiki" document="highlighter" anchor="styles" />
50-
51-
## Usage
52-
53-
To enable line numbers in your code blocks, add the `lineNumbers` property to the code block in your MDX files:
55+
2. To enable line numbers in your code blocks, add the `lineNumbers` property to the code block in your MDX files:
5456

5557
````mdx title="MDX Code Block with Line Numbers"
5658
```ts lineNumbers
5759
// Your TypeScript code here
5860
```
5961
````
62+
63+
### `highlight`
64+
65+
1. Import the transformer in your [`highlight()`](/docs/shiki/highlighter):
66+
67+
```ts {2,8} title="Using lineNumbers with highlighter"
68+
import { highlight } from "@/utils/shiki";
69+
import { showLineNumbers } from "@/utils/shiki/transformers/show-line-numbers";
70+
71+
const code = `console.log('hello')`;
72+
const highlighter = await highlight();
73+
const html = highlighter.codeToHtml(code, {
74+
//...
75+
transformers: [showLineNumbers()],
76+
});
77+
```
78+
79+
2. Add ``shiki-line-numbers`` class to the `<pre>` element:
80+
81+
```html
82+
<pre class="shiki-line-numbers">
83+
<code>
84+
<!-- Highlighted code lines here -->
85+
</code>
86+
</pre>
87+
```

apps/website/src/docs/shiki/meta-highlight.mdx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@ const html = highlighter.codeToHtml(code, {
2727
command="@shikijs/transformers -D"
2828
/>
2929

30-
2. Set up `transformerMetaHighlight`:
30+
2. Customize the styles in your CSS file if needed:
31+
32+
<DocCard folder="shiki" document="highlighter" anchor="styles" />
33+
34+
## Usage
35+
36+
### `shikijs/rehype`
37+
38+
1. Set up `transformerMetaHighlight`:
3139

3240
```ts title="Shiki Notation Highlight Transformer"
3341
import { transformerMetaHighlight } from "@shikijs/transformers";
@@ -44,16 +52,10 @@ const rehypeShikiOptions: RehypeShikiCoreOptions = {
4452
export { rehypeShikiOptions };
4553
```
4654

47-
3. Customize the styles in your CSS file if needed:
48-
49-
<DocCard folder="shiki" document="highlighter" anchor="styles" />
50-
51-
## Usage
52-
53-
To highlight specific lines in your code blocks, use the `meta` prop with the line numbers you want to highlight. For example, to highlight lines 2 and 3, use the following syntax:
55+
2. To highlight specific lines in your code blocks, use the `meta` prop with the line numbers you want to highlight. For example, to highlight lines 2 and 3, use the following syntax:
5456

5557
````mdx {1}
56-
``` {4,5}
58+
```{4,5}
5759
const code = `console.log('hello')`;
5860
const highlighter = await highlight();
5961
const html = highlighter.codeToHtml(code, {

apps/website/src/docs/shiki/notation-diff.mdx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,15 @@ const html = highlighter.codeToHtml(code, {
2828
command="@shikijs/transformers -D"
2929
/>
3030

31-
2. Set up `transformerNotationDiff`:
31+
2. Customize the styles in your CSS file if needed:
32+
33+
<DocCard folder="shiki" document="highlighter" anchor="styles" />
34+
35+
## Usage
36+
37+
### `shikijs/rehype`
38+
39+
1. Set up `transformerNotationDiff`:
3240

3341
```ts title="Shiki Notation Highlight Transformer"
3442
import { transformerNotationDiff } from "@shikijs/transformers";
@@ -41,13 +49,7 @@ const rehypeShikiOptions: RehypeShikiCoreOptions = {
4149
export { rehypeShikiOptions };
4250
```
4351

44-
3. Customize the styles in your CSS file if needed:
45-
46-
<DocCard folder="shiki" document="highlighter" anchor="styles" />
47-
48-
## Usage
49-
50-
To add diff notation to your code blocks, use the `[!code ++]` and `[!code --]` markers to indicate added and removed lines, respectively:
52+
2. To add diff notation to your code blocks, use the `[!code ++]` and `[!code --]` markers to indicate added and removed lines, respectively:
5153

5254
````mdx {5,6}
5355
```

apps/website/src/docs/shiki/notation-focus.mdx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@ const html = highlighter.codeToHtml(code, {
2727
command="@shikijs/transformers -D"
2828
/>
2929

30-
2. Set up `transformerNotationFocus`:
30+
2. Customize the styles in your CSS file if needed:
31+
32+
<DocCard folder="shiki" document="highlighter" anchor="styles" />
33+
34+
## Usage
35+
36+
### `shikijs/rehype`
37+
38+
1. Set up `transformerNotationFocus`:
3139

3240
```ts title="Shiki Notation Highlight Transformer"
3341
import { transformerNotationFocus } from "@shikijs/transformers";
@@ -44,13 +52,7 @@ const rehypeShikiOptions: RehypeShikiCoreOptions = {
4452
export { rehypeShikiOptions };
4553
```
4654

47-
3. Customize the styles in your CSS file if needed:
48-
49-
<DocCard folder="shiki" document="highlighter" anchor="styles" />
50-
51-
## Usage
52-
53-
To add diff notation to your code blocks, use the `[!code ++]` and `[!code --]` markers to indicate added and removed lines, respectively:
55+
2. Use the `[!code ++]` and `[!code --]` markers to indicate added and removed lines, respectively:
5456

5557
````mdx {3}
5658
```

0 commit comments

Comments
 (0)