-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsvelte.config.js
45 lines (37 loc) · 1.39 KB
/
svelte.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
import adapter from '@sveltejs/adapter-cloudflare';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
import { mdsvex } from 'mdsvex';
import { remarkSections } from './remark-plugins/sectionize.js';
import { buildToc } from './remark-plugins/extract-toc.js';
import Prism from 'prismjs';
import loadLanguages from 'prismjs/components/index.js';
loadLanguages();
function escapeHtml(code) {
return code.replace(
/[{}`]/g,
// (character) => ({ '{': '{', '}': '}', '`': '`' }[character]),
(character) => ({ '{': '{', '}': '}', '`': '`' }[character]),
);
}
/** @type {import('@sveltejs/kit').Config} */
export default {
extensions: ['.svelte', '.md'],
preprocess: [
vitePreprocess(),
mdsvex({
extension: '.md',
remarkPlugins: [remarkSections, buildToc],
highlight: {
async highlighter(code, langAndPath) {
const [lang, path] = langAndPath.split('=');
const pathDiv = path ? `<div class="path">${path}</div>` : '';
const html = escapeHtml(Prism.highlight(code, Prism.languages[lang], lang));
return `<pre class="prismjs">${pathDiv}<code class="language-${lang}">${html}</code></pre>`;
},
},
}),
],
kit: {
adapter: adapter(),
},
};