MCPcopy Create free account
hub / github.com/CommandCodeAI/BaseAI / rehypeShiki

Function rehypeShiki

apps/baseai.dev/src/mdx/rehype.ts:23–59  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

21let highlighter: any;
22
23export function rehypeShiki() {
24 return async (tree: any) => {
25 highlighter =
26 highlighter ??
27 (await shiki.getHighlighter({
28 theme: theme as any,
29 langs: lang as any
30 }));
31
32 visit(tree, 'element', node => {
33 if (
34 node.tagName === 'pre' &&
35 node.children[0]?.tagName === 'code'
36 ) {
37 let codeNode = node.children[0];
38 let textNode = codeNode.children[0];
39
40 node.properties.code = textNode.value;
41
42 if (node.properties.language) {
43 let tokens = highlighter.codeToThemedTokens(
44 textNode.value,
45 node.properties.language
46 );
47
48 textNode.value = shiki.renderToHtml(tokens, {
49 elements: {
50 pre: ({ children }) => children,
51 code: ({ children }) => children,
52 line: ({ children }) => `<span>${children}</span>`
53 }
54 });
55 }
56 }
57 });
58 };
59}
60
61export function rehypeSlugify() {
62 return (tree: any) => {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected