Skip to content

Commit 7edf0cf

Browse files
committed
fix: fixed word-wrap styles & transformers + docs
1 parent 0601e8e commit 7edf0cf

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

apps/website/src/docs/shiki/word-wrap.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ category: [Shiki, Markdown, MDX]
1616

1717
<ShowSource component="shiki-word-wrap" />
1818

19+
`shiki-word-wrap` styles are defined in the `shiki.css` file:
20+
21+
<DocCard folder="shiki" document="highlighter" anchor="styles" />
22+
1923
2. Import the transformer in your `rehypeShiki` plugin:
2024

2125
```ts title="Rehype Shiki Options"

apps/website/src/styles/shiki.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ pre.shiki span.line {
2424
@apply px-4 py-0.5;
2525
}
2626

27+
/* Shiki Word Wrap */
28+
pre.shiki-word-wrap {
29+
white-space: pre-wrap;
30+
word-break: break-word;
31+
}
32+
33+
pre.shiki-word-wrap span.line {
34+
display: inline-block;
35+
width: 100%;
36+
box-sizing: border-box;
37+
padding-top: 0.2px;
38+
padding-bottom: 0.2px;
39+
}
40+
2741
/* Shiki Line Numbers */
2842
pre.shiki-line-numbers code {
2943
counter-reset: step;

apps/website/src/utils/shiki/transformers/word-wrap.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ const wordWrapContent = (): ShikiTransformer => {
44
return {
55
name: "WordWrap",
66
pre(node) {
7-
node.properties.style = "white-space: pre-wrap;";
7+
const shikiStyles = node.properties.class;
8+
node.properties.class = `${shikiStyles} shiki-word-wrap`;
89
},
910
};
1011
};
1112

12-
export { wordWrapContent };
13+
export { wordWrapContent };

0 commit comments

Comments
 (0)