-
Notifications
You must be signed in to change notification settings - Fork 99
/
index.js
47 lines (38 loc) · 1.35 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
import fs from 'fs';
import {unified} from 'unified'
import remarkParse from 'remark-parse'
function assert(condition, message) {
if (!condition) {
throw new Error(message || "Assertion failed");
}
}
const content = fs.readFileSync('TemplateForm.md', 'utf-8');
let myResult = unified()
.use(remarkParse)
.parse(content);
myResult.children.forEach(element => {
delete(element["position"])
delete(element["type"])
if ("children" in element) {
element.children.forEach(element => {
delete(element["position"])
delete(element["type"])
})
}
});
// console.log(myResult.children[1].children[0].value.split("\n"))
let json_output = '{"header":{'
let splited_line = ''
assert(myResult.children.length === 16)
myResult.children[1].children[0].value.split("\n").forEach(line => {
json_output = json_output + '"' + line + '",'
})
json_output = json_output.substring(0, json_output.length - 1)
json_output = json_output + '},'
for (let pas = 3; pas < 15; pas = pas + 2) {
let title = myResult.children[pas].children[0].value
let paragraph = myResult.children[pas + 1].children[0].value
json_output = json_output + '"' + title.replace("\n","") + '":'+ '"'+ paragraph.replace("\n","") + '",'
}
console.log(json_output)
// console.log(JSON.stringify(myResult.children, null, " "));