-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathpreproc.js
More file actions
35 lines (35 loc) · 1.16 KB
/
preproc.js
File metadata and controls
35 lines (35 loc) · 1.16 KB
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
module.exports = (markdown, options) => {
return new Promise((resolve, reject) => {
var rnd = 0;
var is_open = false;
return resolve(
markdown
.split('\n')
.map((line, index) => {
if(line=="```echarts"){
is_open = true;
rnd = Math.ceil(Math.random()*1000000);
line = "<!-- html -->\n<div id=\"chart_"+rnd+"\" style=\"width: 600px;height:400px;margin: 0 auto;\"></div>\n\
<script>\n\
document.addEventListener('DOMContentLoaded', function() {\n\
var mychart_"+rnd+" = echarts.init(document.getElementById('chart_"+rnd+"'));\n\
var option = {\n";
return line
}
if(line=="```"){
line = "mychart_"+rnd+".setOption(option);\n\
});\n\
</script>";
return line;
}
if(line.trim()=="{" && is_open == true){
is_open = false;
return "";
} else {
return line;
}
})
.join('\n')
);
});
};