-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathhighlight.ts
More file actions
34 lines (31 loc) · 1.06 KB
/
Copy pathhighlight.ts
File metadata and controls
34 lines (31 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import {
codeToHtml,
createCssVariablesTheme,
type ShikiTransformer,
} from "shiki";
// Shiki emits inline styles like `color: var(--shiki-token-keyword)`. The
// CSS-variable mapping onto the project's palette tokens lives in
// `globals.css` (`.blog-article-body pre`, `.code-body`, …) so colors stay
// theme-coherent and adjustable in one place.
export const sqlriteShikiTheme = createCssVariablesTheme({
name: "sqlrite-css-vars",
});
// `createCssVariablesTheme` still sets `background: var(--shiki-background)`
// on the outer <pre>; that would force the figure to override our existing
// container backgrounds. Strip the inline style so the surrounding wrapper
// (.code-body, .blog-article-body pre, etc.) drives layout/colors.
const stripContainerStyle: ShikiTransformer = {
pre(node) {
if (node.properties) delete node.properties.style;
},
};
export async function highlightCode(
code: string,
lang: string,
): Promise<string> {
return codeToHtml(code, {
lang,
theme: sqlriteShikiTheme,
transformers: [stripContainerStyle],
});
}