forked from chrisg86/gatsby-remark-classes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
33 lines (26 loc) · 845 Bytes
/
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
const visit = require('unist-util-visit');
const applyClassesToNode = require('./src/applyClassesToNode');
module.exports = (
{ markdownAST },
{ classMap = {} }
) => {
// @see: https://github.com/syntax-tree/mdast#nodes
visit(markdownAST, `heading`, node => {
const selector = `h${node.depth}`;
if (selector in classMap) {
node = applyClassesToNode(node, classMap[selector]);
}
});
visit(markdownAST, `table`, node => {
const selector = `table`;
if (selector in classMap) {
node = applyClassesToNode(node, classMap[selector]);
}
});
visit(markdownAST, `paragraph`, node => {
const selector = `paragraph`;
if (selector in classMap) {
node = applyClassesToNode(node, classMap[selector]);
}
});
}