forked from episphere/quest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
questProto.js
37 lines (31 loc) · 972 Bytes
/
questProto.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
console.log('quest.js loaded')
quest=function(){
//ini
}
quest.render=(txt)=>{
var html=''
var txt0=txt
// remove blocked out
txt=txt.replace(/\/\*[\s\S]+\*\//g,'')
txt=txt.replace(/\/\/.*\n/g,'')
// separate questions
txt = txt.split(/\n\n/).map(qq=>{
qq=qq.split('\n')
if(qq.length==1){
//html += `<h3>${qq[0]} <span style="font-size:small;cursor:hand;color:blue">[hide]</span></h3>`
html += `<h3>${qq[0]}</h3>`
}else if(qq.length>1){
html += `<p><b>${qq[0]}</b><br>`
qq.slice(1).forEach(q=>{
html += `${q}<br>`
})
html += '</p>'
}
})
// html elements
html = html.replace(/\[\]/g,'<input type="checkbox">')
html = html.replace(/[^_|]*_\|/g,'<input size=1>')
html = html.replace(/\|__\|/g,'<input>')
html = html.replace(/\|___\|/g,'<textarea></textarea>')
return html+'<hr>'//+txt0
}