Skip to content

Commit e86123a

Browse files
zhangyuanniealecthomas
authored andcommitted
better markdown lexer
1 parent 9de08fc commit e86123a

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

Diff for: lexers/m/markdown.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func markdownRules() Rules {
4040
},
4141
"inline": {
4242
{`\\.`, Text, nil},
43-
{`(\s)([*_][^*_]+[*_])(\W|\n)`, ByGroups(Text, GenericEmph, Text), nil},
43+
{`(\s)(\*|_)((?:(?!\2).)*)(\2)((?=\W|\n))`, ByGroups(Text, GenericEmph, GenericEmph, GenericEmph, Text), nil},
4444
{`(\s)((\*\*|__).*?)\3((?=\W|\n))`, ByGroups(Text, GenericStrong, GenericStrong, Text), nil},
4545
{`(\s)(~~[^~]+~~)((?=\W|\n))`, ByGroups(Text, GenericDeleted, Text), nil},
4646
{"`[^`]+`", LiteralStringBacktick, nil},

Diff for: lexers/testdata/markdown.actual

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,20 @@
44

55
Multiple **bold** on the **same line**.
66

7+
Multiple _italic_ on the *same_line*.
8+
79
## user defined function in cql
810

911
```javascript
10-
column.substring(0,num)
12+
column.substring(0,num)
1113
```
1214

1315
```cql
1416
CREATE FUNCTION IF NOT EXISTS cycling.left (column TEXT,num int)
1517
RETURNS NULL ON NULL INPUT
1618
RETURNS text
17-
LANGUAGE javascript AS $$
18-
column.substring(0,num)
19+
LANGUAGE javascript AS $$
20+
column.substring(0,num)
1921
$$;
2022

2123
CREATE OR REPLACE FUNCTION cycling.fLog (input double)
@@ -34,7 +36,7 @@ CREATE TABLE emp (
3436
last_user text
3537
);
3638

37-
select
39+
select
3840
$my_tag$aoeuaoeu$my_tag$ as blah
3941
;
4042

Diff for: lexers/testdata/markdown.expected

+8-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
{"type":"GenericStrong","value":"**bold**"},
1717
{"type":"Text","value":" on the "},
1818
{"type":"GenericStrong","value":"**same line**"},
19+
{"type":"Text","value":".\n\nMultiple "},
20+
{"type":"GenericEmph","value":"_italic_"},
21+
{"type":"Text","value":" on the "},
22+
{"type":"GenericEmph","value":"*same_line*"},
1923
{"type":"Text","value":".\n\n"},
2024
{"type":"GenericSubheading","value":"## user defined function in cql\n"},
2125
{"type":"Text","value":"\n"},
@@ -29,7 +33,7 @@
2933
{"type":"Punctuation","value":","},
3034
{"type":"NameOther","value":"num"},
3135
{"type":"Punctuation","value":")"},
32-
{"type":"Text","value":" \n"},
36+
{"type":"Text","value":"\n"},
3337
{"type":"LiteralString","value":"```"},
3438
{"type":"Text","value":"\n\n"},
3539
{"type":"LiteralString","value":"```cql\n"},
@@ -78,7 +82,7 @@
7882
{"type":"Keyword","value":"AS"},
7983
{"type":"TextWhitespace","value":" "},
8084
{"type":"LiteralStringHeredoc","value":"$$"},
81-
{"type":"Text","value":" \n "},
85+
{"type":"Text","value":"\n "},
8286
{"type":"NameOther","value":"column"},
8387
{"type":"Punctuation","value":"."},
8488
{"type":"NameOther","value":"substring"},
@@ -87,7 +91,7 @@
8791
{"type":"Punctuation","value":","},
8892
{"type":"NameOther","value":"num"},
8993
{"type":"Punctuation","value":")"},
90-
{"type":"Text","value":" \n"},
94+
{"type":"Text","value":"\n"},
9195
{"type":"LiteralStringHeredoc","value":"$$"},
9296
{"type":"Punctuation","value":";"},
9397
{"type":"TextWhitespace","value":"\n\n"},
@@ -191,7 +195,7 @@
191195
{"type":"Punctuation","value":");"},
192196
{"type":"Text","value":"\n\n"},
193197
{"type":"Keyword","value":"select"},
194-
{"type":"Text","value":" \n "},
198+
{"type":"Text","value":"\n "},
195199
{"type":"LiteralStringHeredoc","value":"$my_tag$aoeuaoeu$my_tag$"},
196200
{"type":"Text","value":" "},
197201
{"type":"Keyword","value":"as"},

0 commit comments

Comments
 (0)