Skip to content

Commit dc73c34

Browse files
authored
perf(legacy-html): stop re-parsing shiki themes per code block (#1169)
1 parent 560c042 commit dc73c34

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@node-core/doc-kit-legacy': patch
3+
---
4+
5+
`legacy-html` builds about 30% faster: Shiki no longer parses its themes again for every code block.

‎packages/node-legacy/src/legacy-html/plugins/shiki.mjs‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import shikiConfig from '@doc-kit/core/shiki.config.mjs';
55
import { h as createElement } from 'hastscript';
66
import { SKIP, visit } from 'unist-util-visit';
77

8-
const highlighter = await createHighlighter();
8+
const [lightTheme, darkTheme] = shikiConfig.themes;
9+
10+
const highlighter = await createHighlighter({
11+
themes: { light: lightTheme, dark: darkTheme },
12+
});
913

1014
// This is what Remark will use as prefix within a <pre> className
1115
// to attribute the current language of the <pre> element
@@ -93,8 +97,9 @@ export default function rehypeShikiji() {
9397
preElement.children[0].value,
9498
{
9599
lang: highlighter.resolveLanguage(languageId),
96-
// Allows support for dual themes (light, dark) for Shiki
97-
themes: { light: shikiConfig.themes[0], dark: shikiConfig.themes[1] },
100+
// Allows support for dual themes (light, dark) for Shiki. Given by
101+
// name, as Shiki parses a theme object again for every highlight
102+
themes: { light: lightTheme.name, dark: darkTheme.name },
98103
}
99104
);
100105

0 commit comments

Comments
 (0)