forked from willin/svelte-turbo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmdsvex.config.js
74 lines (67 loc) · 1.71 KB
/
mdsvex.config.js
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { defineMDSveXConfig as defineConfig } from 'mdsvex';
import remarkGfm from 'remark-gfm';
import remarkGithub from 'remark-github';
import rehypeSlug from 'rehype-slug';
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
import { codeToHtml } from 'shikiji';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
/**
* @param {string} code
* @param {string | undefined} lang
*/
async function highlighter(code, lang = '') {
/**
* escape curlies, backtick, \t, \r, \n to avoid breaking output of {@html `here`} in .svelte
* @param {string} str the string to escape
* @returns the escaped string
*/
const escape_svelty = (str) =>
str
.replace(/[{}`]/g, (c) => ({ '`': '`', '{': '{', '}': '}' })[c])
.replace(/\\([trn])/g, '\$1');
const html = await codeToHtml(code, {
lang,
theme: 'nord'
});
return escape_svelty(html);
}
const config = defineConfig({
extensions: ['.svelte.md', '.md', '.svx'],
layout: {
// blog: './path/to/blog/layout.svelte',
// article: './path/to/article/layout.svelte',
// _: './path/to/fallback/layout.svelte'
_: path.resolve(__dirname, './src/components/mdsvex.svelte')
},
highlight: {
highlighter
},
rehypePlugins: [
rehypeSlug,
[
rehypeAutolinkHeadings,
{
behavior: 'wrap',
properties: {
className: ['anchor']
}
}
]
],
remarkPlugins: [
remarkGfm,
[
remarkGithub,
{
repository: 'willin/svelte-turbo'
}
]
],
smartypants: {
dashes: 'oldschool'
}
});
export default config;