forked from dmarcwise/dmarc-wiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmdsvex.config.js
71 lines (67 loc) · 1.78 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
import rehypeRewrite from 'rehype-rewrite';
import { remarkSvelteAutoImport } from '@kasisoft/remark-svelte-auto-import';
const badge = function (value) {
return `
<span class="border border-slate-200 dark:border-slate-700 px-1.5 py-0.5 rounded-md">
${value}
</span>
`.trim();
};
/** @type {import('mdsvex').MdsvexOptions} */
const mdsvexOptions = {
extensions: ['.svelte.md'],
layout: 'src/lib/mdsvex/layout.svelte',
// Disable syntax highlighting
highlight: {
highlighter: (text) => {
return `<pre>${text}</pre>`;
}
},
remarkPlugins: [
// In code blocks, replace [...] with <DotsBadge />
() => {
return (tree) => {
for (const node of tree.children) {
if (node.type === 'code') {
node.value = node.value.replace('[...]', '<DotsBadge />');
}
}
};
},
// Auto-import some components to avoid importing them manually in each file
[
remarkSvelteAutoImport,
{
// debug: ['ComponentMap'],
componentMap: {
Block: '$lib/mdsvex/block.svelte',
// TODO: this doesn't work because this plugin looks at the file content, not the modified tree.
// find a way to always import it maybe?
DotsBadge: '$lib/mdsvex/dots-badge.svelte'
}
}
]
],
rehypePlugins: [
[
rehypeRewrite,
{
rewrite: (node) => {
// Remove rel="nofollow" from links to dmarcwise.io
if (node.tagName === 'a' && node.properties.href.startsWith('https://dmarcwise.io')) {
node.properties.rel = undefined;
}
// Replace textual example domain with stylized badge
if (node.tagName === 'code') {
for (const child of node.children) {
if (child.type === 'text') {
child.value = child.value.replace(/\[([\w.@]+)]/g, badge('$1'));
}
}
}
}
}
]
]
};
export default mdsvexOptions;