-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmdsvex.config.js
More file actions
59 lines (51 loc) · 1.72 KB
/
Copy pathmdsvex.config.js
File metadata and controls
59 lines (51 loc) · 1.72 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { join, dirname } from "path";
import { fileURLToPath } from "url";
import remarkFootnotes from "remark-footnotes";
import { escapeSvelte } from "mdsvex";
import { createHighlighter } from "shiki";
import { rehypeEnhancedImg } from "./src/lib/rehype-plugins/rehype-enhanced-img.js";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const path_to_layout = join(__dirname, "./src/lib/markdown-layouts");
// Initialize Shiki highlighter singleton (top-level await)
const shikiHighlighter = await createHighlighter({
themes: ["github-dark", "github-light"],
langs: ["typescript", "tsx", "python", "yaml", "shellscript", "text", "glsl"],
});
const config = {
extensions: ['.md', '.svx'],
smartypants: {
dashes: 'oldschool'
},
layout: {
links: path_to_layout + '/links.svelte',
article: path_to_layout + '/article.svelte',
work: path_to_layout + '/work.svelte',
_: path_to_layout + '/default.svelte'
},
remarkPlugins: [remarkFootnotes],
rehypePlugins: [rehypeEnhancedImg],
highlight: {
highlighter: async (code, lang = "text") => {
// Skip mermaid blocks — let downstream renderers handle them
if (lang === "mermaid") {
return `<pre class="mermaid">{@html \`${escapeSvelte(code)}\`}</pre>`;
}
// Resolve language: fall back to 'text' for unsupported languages
const loadedLangs = shikiHighlighter.getLoadedLanguages();
const resolvedLang = loadedLangs.includes(lang) ? lang : "text";
const html = escapeSvelte(
shikiHighlighter.codeToHtml(code, {
lang: resolvedLang,
themes: {
dark: "github-dark",
light: "github-light",
},
defaultColor: false,
})
);
return `{@html \`${html}\`}`;
},
},
};
export default config;