MCPcopy Create free account
hub / github.com/Borrus-sudo/tinypages / transform

Function transform

packages/compiler/lib/plugins/code.ts:25–74  ·  view source on GitHub ↗
(id: string, payload: string, { persistentCache })

Source from the content-addressed store, hash-verified

23 config = _config;
24 },
25 transform(id: string, payload: string, { persistentCache }) {
26 if (lang) {
27 if (lang.startsWith("mermaid")) {
28 if (config.renderMermaid) {
29 mermaidGraphs.push({ code, lang });
30 payload = "<GRAPH></GRAPH>";
31 }
32 } else if (lang.startsWith("katex")) {
33 if (config.renderKatex)
34 payload = katexRenderer(code, {
35 type: lang,
36 inlineRender: id === "codespan",
37 config,
38 persistentCache,
39 });
40 } else {
41 let keyValue: string | string[] = [];
42 let options: Record<string, string> = { lang };
43 if (lang.includes(" ")) {
44 [lang, ...keyValue] = lang.split(" ");
45 options = { ...JSON.parse(keyValue.join(" ")) };
46 }
47 try {
48 if (options.include) {
49 payload = renderTwoSlash({
50 persistentCache,
51 code,
52 highlighter,
53 lang,
54 options,
55 entryId: options.include,
56 });
57 } else if (options.name) {
58 addMainIncludeTwoSlash(code, options.name);
59 payload = "";
60 } else {
61 payload = renderShiki({
62 persistentCache,
63 highlighter,
64 code,
65 lang,
66 options,
67 });
68 }
69 } catch {}
70 }
71 code = lang = "";
72 return payload;
73 }
74 },
75 tapArgs(id: string, args: any[]) {
76 if (id === "code") {
77 code = args[0];

Callers

nothing calls this directly

Calls 3

renderTwoSlashFunction · 0.90
addMainIncludeTwoSlashFunction · 0.90
renderShikiFunction · 0.90

Tested by

no test coverage detected