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

Function rehypeShiki

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

Source from the content-addressed store, hash-verified

24let highlighter;
25
26export function rehypeShiki() {
27 return async tree => {
28 highlighter =
29 highlighter ??
30 (await shiki.getHighlighter({ theme: theme, langs: lang }));
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 => {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected