forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
35 lines (31 loc) · 820 Bytes
/
index.js
File metadata and controls
35 lines (31 loc) · 820 Bytes
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
/**
* We add a section around headers + content. This way we can create cards
*/
module.exports = ({ markdownAST }) => {
let headingMode = false;
for (let i = 0; i < markdownAST.children.length; i++) {
const child = markdownAST.children[i];
if (i === markdownAST.children.length - 1 && headingMode) {
markdownAST.children.push({
type: 'html',
value: '</section>',
});
return;
}
if (child.type === 'heading' && child.depth === 2) {
if (headingMode) {
markdownAST.children.splice(i, 0, {
type: 'html',
value: '</section>',
});
} else {
markdownAST.children.splice(i, 0, {
type: 'html',
value: '<section>',
});
i++;
}
headingMode = !headingMode;
}
}
};