-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (31 loc) · 854 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
39
40
41
42
import marked from 'marked';
import text from './text/the-black-stack.md';
import each from 'lodash/each';
import styles from './style.css'
const $root = document.getElementById('root');
function breakSections(text) {
let sections = [];
let section;
function add() {
if(section) sections.push(section.join('\n'));
}
each(text.split('\n'), line => {
if(line === '----') {
add();
section = []
} else {
(section = section || []).push(line);
}
});
add();
return sections;
}
each(breakSections(text), sectionText => {
const markdown = marked(sectionText);
const $section = document.createElement('section');
$section.classList.add('page');
const $content = document.createElement('div');
$content.innerHTML = markdown;
$section.appendChild($content);
$root.appendChild($section);
});