-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
28 lines (25 loc) · 939 Bytes
/
utils.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
const utils = {
escapeHtml: function(text) {
return text
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'")
.replace(/\t/g, " ");
},
formatMarkdown: function(text) {
text = this.escapeHtml(text);
return text
.replace(/^### (.*$)/gm, '<h3>$1</h3>')
.replace(/^## (.*$)/gm, '<h2>$1</h2>')
.replace(/^# (.*$)/gm, '<h1>$1</h1>')
.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
.replace(/\*(.*?)\*/g, '<em>$1</em>')
.replace(/^\d\. (.*$)/gm, '<ol><li>$1</li></ol>')
.replace(/^- (.*$)/gm, '<ul><li>$1</li></ul>')
.replace(/`(.*?)`/g, '<code style="background-color: #f6f8fa; padding: 2px 4px; border-radius: 3px;">$1</code>')
.replace(/\n/g, '<br>');
}
};
window.utils = utils;