Skip to content

Commit c4bec47

Browse files
committed
Don't break Markdown on multiple bolds on a single line.
Also highlight entire title for title lines rather than just the code. Fixes #193. Fixes #195.
1 parent 2a59c2c commit c4bec47

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

lexers/m/markdown.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ var Markdown = internal.Register(MustNewLexer(
1515
},
1616
Rules{
1717
"root": {
18-
{`^(#)([^#].+\n)`, ByGroups(GenericHeading, Text), nil},
19-
{`^(#{2,6})(.+\n)`, ByGroups(GenericSubheading, Text), nil},
18+
{`^(#[^#].+\n)`, ByGroups(GenericHeading), nil},
19+
{`^(#{2,6}.+\n)`, ByGroups(GenericSubheading), nil},
2020
{`^(\s*)([*-] )(\[[ xX]\])( .+\n)`, ByGroups(Text, Keyword, Keyword, UsingSelf("inline")), nil},
2121
{`^(\s*)([*-])(\s)(.+\n)`, ByGroups(Text, Keyword, Text, UsingSelf("inline")), nil},
2222
{`^(\s*)([0-9]+\.)( .+\n)`, ByGroups(Text, Keyword, UsingSelf("inline")), nil},
@@ -35,13 +35,13 @@ var Markdown = internal.Register(MustNewLexer(
3535
"inline": {
3636
{`\\.`, Text, nil},
3737
{`(\s)([*_][^*_]+[*_])(\W|\n)`, ByGroups(Text, GenericEmph, Text), nil},
38-
{`(\s)((\*\*|__).*\3)((?=\W|\n))`, ByGroups(Text, GenericStrong, None, Text), nil},
38+
{`(\s)((\*\*|__).*?)\3((?=\W|\n))`, ByGroups(Text, GenericStrong, GenericStrong, Text), nil},
3939
{`(\s)(~~[^~]+~~)((?=\W|\n))`, ByGroups(Text, GenericDeleted, Text), nil},
4040
{"`[^`]+`", LiteralStringBacktick, nil},
4141
{`[@#][\w/:]+`, NameEntity, nil},
4242
{`(!?\[)([^]]+)(\])(\()([^)]+)(\))`, ByGroups(Text, NameTag, Text, Text, NameAttribute, Text), nil},
4343
{`[^\\\s]+`, Text, nil},
44-
{`.`, Text, nil},
44+
{`.|\n`, Text, nil},
4545
},
4646
},
4747
))

lexers/testdata/markdown.actual

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# about
22

3+
Multiple **bold** on the **same line**.
4+
35
## user defined function in cql
46

57
```javascript

lexers/testdata/markdown.expected

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
[
2-
{"type":"GenericHeading","value":"#"},
3-
{"type":"Text","value":" about\n"},
4-
{"type":"Error","value":"\n"},
5-
{"type":"GenericSubheading","value":"##"},
6-
{"type":"Text","value":" user defined function in cql\n"},
7-
{"type":"Error","value":"\n"},
2+
{"type":"GenericHeading","value":"# about\n"},
3+
{"type":"Text","value":"\nMultiple "},
4+
{"type":"GenericStrong","value":"**bold**"},
5+
{"type":"Text","value":" on the "},
6+
{"type":"GenericStrong","value":"**same line**"},
7+
{"type":"Text","value":".\n\n"},
8+
{"type":"GenericSubheading","value":"## user defined function in cql\n"},
9+
{"type":"Text","value":"\n"},
810
{"type":"LiteralString","value":"```javascript\n"},
911
{"type":"Text","value":" "},
1012
{"type":"NameOther","value":"column"},
@@ -17,7 +19,7 @@
1719
{"type":"Punctuation","value":")"},
1820
{"type":"Text","value":" \n"},
1921
{"type":"LiteralString","value":"```"},
20-
{"type":"Error","value":"\n\n"},
22+
{"type":"Text","value":"\n\n"},
2123
{"type":"LiteralString","value":"```cql\n"},
2224
{"type":"Keyword","value":"CREATE"},
2325
{"type":"TextWhitespace","value":" "},
@@ -132,7 +134,7 @@
132134
{"type":"Punctuation","value":";"},
133135
{"type":"TextWhitespace","value":"\n"},
134136
{"type":"LiteralString","value":"```"},
135-
{"type":"Error","value":"\n\n"},
137+
{"type":"Text","value":"\n\n"},
136138
{"type":"LiteralString","value":"```postgres\n"},
137139
{"type":"Keyword","value":"DROP"},
138140
{"type":"Text","value":" "},
@@ -423,5 +425,5 @@
423425
{"type":"Punctuation","value":";"},
424426
{"type":"Text","value":"\n"},
425427
{"type":"LiteralString","value":"```"},
426-
{"type":"Error","value":"\n"}
428+
{"type":"Text","value":"\n"}
427429
]

0 commit comments

Comments
 (0)