-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmarkdown.js
71 lines (47 loc) · 2.22 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
function md2html(text) {
//console.log("From md2html");
var splittext = text.split("\\n");
var formatted = "";
//first wee need to get rid of the \n's and replace them with <br> //
for(var num = 0;num < splittext.length;num = num + 1) {
var changeformat = "";
if(splittext[num].search("#### ") !== -1) {
changeformat = splittext[num].replace("#### ","<br><h4>").replace("\\n","");
formatted = formatted+changeformat+"</h4><br>";
} else
if(splittext[num].search("### ") !== -1) {
changeformat = splittext[num].replace("### ","<br><h3>").replace("\\n","");
formatted = formatted+changeformat+"</h3><br>";
} else
if(splittext[num].search("## ") !== -1) {
changeformat = splittext[num].replace("## ","<br><h2>").replace("\\n","");
formatted = formatted+changeformat+"</h2><br>";
} else
if(splittext[num].search("# ") !== -1) {
changeformat = splittext[num].replace("# ","<br><h1>").replace("\\n","");
formatted = formatted+changeformat+"</h1><br>";
} else
if(splittext[num].search("\\+ ") !== -1) {
changeformat = splittext[num].replace("\\+ ","<ul><li>").replace("\\n","");
formatted = formatted+changeformat+"</li></ul>";
} else
if(splittext[num].search("- ") !== -1){
changeformat = splittext[num].replace("- ","<ul><li>").replace("\\n","");
formatted = formatted+changeformat+"</li></ul>";
} else
if(splittext[num].search("```") !== -1){
changeformat = splittext[num].replace("```","<br><br>").replace("\\n","");
formatted = formatted+changeformat;
} else
if(splittext[num].search(/\!\[/) !== -1) {
changeformat = "<img source='"+splittext[num].split("](")[1].split(")")[0].replace(/\\/g,"")+"'>"
// console.log(changeformat);
formatted = formatted+changeformat;
}
else {
formatted = formatted+splittext[num].replace("\\n","<br>");
}
formatted = formatted.replace(/\\/g,"");
}
return formatted;
}