-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (29 loc) · 761 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
34
35
36
37
38
const visit = require('unist-util-visit');
const newSlide = {
type: 'slide',
data: {
hName: 'section',
hProperties: {
className: 'slide'
}
}
};
function createSlides(tree) {
let index = 0;
const slides = [];
function visitor(node) {
const children = tree.children.slice(index, tree.children.indexOf(node));
index = tree.children.indexOf(node) + 1;
slides.push(Object.assign({}, node, newSlide, {children}));
}
visit(tree, 'thematicBreak', visitor);
const remaining = tree.children.slice(index);
if (remaining.length > 0) {
slides.push(Object.assign({}, newSlide, {children: remaining}));
}
return Object.assign({}, tree, {children: slides});
}
function splitSlides() {
return createSlides;
}
module.exports = splitSlides;