const fs require fs let file fs readFileSync Contents md utf-8 let lin

 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
const fs = require('fs');
let file = fs.readFileSync('./0. Contents.md', 'utf-8');
let lines = file.split('\n');
console.log(lines);
let result = `<ol>\n`;
for (let i = 2; i < lines.length - 1; i++) {
result += ` <li>${lines[i].replace(/^\d+\. /, '')}`;
if (lines[i + 1].match(/^-/)) {
i++;
result += `\n <ul>\n`;
for (; lines[i].match(/^-/); i++) {
result += ` <li>${lines[i].replace(/^- /, '')}`;
if (lines[i + 1].match(/^\+/)) {
i++;
result += `\n <ul>\n`;
for (; lines[i].match(/^\+/); i++) {
result += ` <li>${lines[i].replace(/^\+ /, '')}</li>\n`;
}
i--;
result += ` </ul>\n`;
}
result += `</li>\n`;
}
i--;
result += ` </ul>\n`;
}
result += `</li>\n`;
}
result += `</ol>\n`;
fs.writeFileSync('./Zmist.html', result, 'utf8');