-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarkdown.js
78 lines (78 loc) · 1.68 KB
/
markdown.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
var Markdown = {
h1:function(str=""){
if(str=="") return "# ";
else return "# "+str.trim()+" ";
},
h2:function(str=""){
if(str=="") return "## ";
else return "## "+str.trim()+" ";
},
h3:function(str=""){
if(str=="") return "### ";
else return "### "+str.trim()+" ";
},
h4:function(str=""){
if(str=="") return "#### ";
else return "#### "+str.trim()+" ";
},
h5:function(str=""){
if(str=="") return "##### ";
else return "##### "+str.trim()+" ";
},
h6:function(str=""){
if(str=="") return "###### ";
else return "###### "+str.trim()+" ";
},
hr:function(){
return "---";
},
bold:function(str){
return " **"+str.trim()+"** ";
},
italic:function(str){
return " _"+str.trim()+"_ ";
},
strike:function(str){
return " ~~"+str.trim()+"~~ ";
},
blockquote:function(str){
return "> "+str.trim();
},
code:function(str){
return "`"+str.trim()+"`";
},
codeblock:function(str,lang=""){
if(str==null) return "";
else if(typeof str == "object"){
var new_str = ""
str.forEach(function(o,i){
if(o.enabled) new_str+="["+o.type+"] "+o.key+" = "+((o.value==null)?"":o.value)+"\n";
});
str = new_str;
}
if(str!="") str = str.replace(/^[\s\n]+|[\s\n]+$/g, '')+"\n";
return "```"+lang+"\n"+str+"```";
},
href:function(url,str=""){
return "["+str.trim()+"]"+"("+url+")";
},
table:function(headers,rows){
var table = "";
headers.forEach(function(o,i){
table+="| "+o.trim()+" ";
});
table+="|\n";
headers.forEach(function(o,i){
table+="| --- ";
});
table+="|\n";
rows.forEach(function(o,i){
o.forEach(function(oo,ii){
table+="| "+oo.trim()+" ";
});
table+="|\n";
});
return table;
}
};
module.exports = Markdown;