-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.js
More file actions
56 lines (47 loc) · 1.67 KB
/
parser.js
File metadata and controls
56 lines (47 loc) · 1.67 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
function parser(mdText) {
const htmlText = mdText.replace(/^# (.*$)/igm, "<h1>$1</h1>")
.replace(/^## (.*$)/igm, "<h2>$1</h2>")
.replace(/^### (.*$)/igm, "<h3>$1</h3>")
.replace(/\*\*(.*)\*\*/gim, "<b>$1</b>")
.replace(/\*(.*)\*/igm, "<i>$1</i>")
.replace(/\~\~(.*)\~\~/igm, "<del>$1</del>")
.replace(/^\> (.*$)/gim, "<blockquote>$1</blockquote>")
.replace(/!\[(.*?)\]\((.*?)\)/gim,"<img alt='$1' src='$2'/>")
.replace(/\[(.*?)\]\((.*?)\)/gim, '<a href="$2">$1</a>')
.replace(/\n$/gim, "<br />")
return htmlText
}
const test_Test = `Now is the time for all good men to come to
the aid of their country. This is just a
regular paragraph.
The quick brown fox jumped over the lazy
dog's back.
### Header 3
> This is a blockquote.
>
> This is the second paragraph in the blockquote.
>
> ## This is an H2 in a blockquote
Some of these words *are emphasized*.
Use two asterisks for **strong emphasis**.
This is an [example link](http://example.com/).

`
console.log(parser(test_Test));
const input = "[GitHub Pages](https://pages.github.com/)"
const h1 = /^#(.*$)/igm;
const h2 = /^##(.*$)/igm;
const h3 = /^###(.*$)/igm;
const h4 = /^####(.*$)/igm;
const h5 = /^#####(.*$)/igm;
const h6 = /^######(.*$)/igm;
const bold = /\*\*(.*)\*\*/igm;
const italic = /^\*(.*)\*/igm;
const strikethrough = /^\~\~(.*)\~\~/igm;
const blockQuote = /\>(.*$)/gim;
const link = /\[(.*?)\]\((.*?)\)/gi;
const unorderedList = /^\- (.*)/ig;
const image = /!\[(.*?)\]\((.*?)\)/gim;
const lineBreak = /\n$/gim
const result = input.replace(link, '<a href="$2">$1</a>');
console.log(result);