-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
48 lines (43 loc) · 1.2 KB
/
index.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
const visit = require("unist-util-visit-parents")
module.exports = ({ markdownAST }, pluginOptions) => {
visit(markdownAST, "heading", (node, ancestors) => {
let { depth } = node
node.data = {
hProperties: { class: `title is-${depth}` },
}
})
visit(markdownAST, "blockquote", (node, ancestors) => {
const div = {
type: "section",
data: {
hName: "div",
hProperties: { class: "content" },
},
children: [node],
}
const parent = ancestors[ancestors.length - 1]
const startIndex = parent.children.indexOf(node)
parent.children.splice(startIndex, 1, div)
})
visit(markdownAST, "list", (node, ancestors) => {
const div = {
type: "section",
data: {
hName: "div",
hProperties: { class: "content" },
},
children: [node],
}
const parent = ancestors[ancestors.length - 1]
const startIndex = parent.children.indexOf(node)
parent.children.splice(startIndex, 1, div)
})
visit(markdownAST, "paragraph", (node, ancestors) => {
if (ancestors[ancestors.length - 1].type === "root") {
node.data = {
hProperties: { class: "content" },
}
}
})
return markdownAST
}