-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollupPlugins.ts
41 lines (36 loc) · 912 Bytes
/
rollupPlugins.ts
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
import hljs from "highlight.js";
import { marked } from "marked";
const FILE_MATCH_REGEX = /.md$/;
marked.setOptions({
mangle: false,
headerIds: false,
highlight(code, lang) {
const language = hljs.getLanguage(lang) ? lang : "plaintext";
const highlighted = hljs.highlight(code, { language }).value;
return highlighted;
},
});
marked.use({
renderer: {
image(href, title, text) {
return `<figure><img src="${href}" alt="${text}" title="${title}" class="rounded-lg"></figure>`;
},
},
});
export function markdown() {
return {
name: "raw-text-import",
// @ts-ignore
transform(source, id) {
if (FILE_MATCH_REGEX.test(id)) {
const rawText = source.toString();
const html = marked(rawText);
return {
code: `export default ${JSON.stringify(html)}`,
map: null,
};
}
return null;
},
};
}