-
-
Notifications
You must be signed in to change notification settings - Fork 76
/
markdown.js
52 lines (44 loc) · 1.11 KB
/
markdown.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
import {
markdownIt,
markdownItAttrs,
markdownItDeflist,
markdownItReplaceLink,
} from "../deps/markdown_it.js";
import loader from "../loaders/text.js";
import Markdown from "../engines/markdown.js";
import { merge } from "../utils.js";
// Default options
const defaults = {
extensions: [".md"],
options: {
html: true,
},
plugins: [
markdownItAttrs,
markdownItDeflist,
markdownItReplaceLink,
],
};
export default function (userOptions) {
const options = merge(defaults, userOptions);
return function (site) {
const engine = createMarkdown(site, options);
site.loadPages(options.extensions, loader, new Markdown(site, engine));
site.filter("md", filter);
function filter(string, inline = false) {
return inline
? engine.renderInline(string || "").trim()
: engine.render(string || "").trim();
}
};
}
function createMarkdown(site, options) {
const markdown = markdownIt({
replaceLink(link) {
return site.url(link);
},
...options.options,
});
options.plugins.forEach((plugin) => markdown.use(plugin));
return markdown;
}