Skip to content

Commit

Permalink
Don't break Markdown on multiple bolds on a single line.
Browse files Browse the repository at this point in the history
Also highlight entire title for title lines rather than just the code.

Fixes #193. Fixes #195.
  • Loading branch information
alecthomas committed Dec 31, 2018
1 parent 2a59c2c commit c4bec47
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
8 changes: 4 additions & 4 deletions lexers/m/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ var Markdown = internal.Register(MustNewLexer(
},
Rules{
"root": {
{`^(#)([^#].+\n)`, ByGroups(GenericHeading, Text), nil},
{`^(#{2,6})(.+\n)`, ByGroups(GenericSubheading, Text), nil},
{`^(#[^#].+\n)`, ByGroups(GenericHeading), nil},
{`^(#{2,6}.+\n)`, ByGroups(GenericSubheading), nil},
{`^(\s*)([*-] )(\[[ xX]\])( .+\n)`, ByGroups(Text, Keyword, Keyword, UsingSelf("inline")), nil},
{`^(\s*)([*-])(\s)(.+\n)`, ByGroups(Text, Keyword, Text, UsingSelf("inline")), nil},
{`^(\s*)([0-9]+\.)( .+\n)`, ByGroups(Text, Keyword, UsingSelf("inline")), nil},
Expand All @@ -35,13 +35,13 @@ var Markdown = internal.Register(MustNewLexer(
"inline": {
{`\\.`, Text, nil},
{`(\s)([*_][^*_]+[*_])(\W|\n)`, ByGroups(Text, GenericEmph, Text), nil},
{`(\s)((\*\*|__).*\3)((?=\W|\n))`, ByGroups(Text, GenericStrong, None, Text), nil},
{`(\s)((\*\*|__).*?)\3((?=\W|\n))`, ByGroups(Text, GenericStrong, GenericStrong, Text), nil},
{`(\s)(~~[^~]+~~)((?=\W|\n))`, ByGroups(Text, GenericDeleted, Text), nil},
{"`[^`]+`", LiteralStringBacktick, nil},
{`[@#][\w/:]+`, NameEntity, nil},
{`(!?\[)([^]]+)(\])(\()([^)]+)(\))`, ByGroups(Text, NameTag, Text, Text, NameAttribute, Text), nil},
{`[^\\\s]+`, Text, nil},
{`.`, Text, nil},
{`.|\n`, Text, nil},
},
},
))
2 changes: 2 additions & 0 deletions lexers/testdata/markdown.actual
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# about

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

## user defined function in cql

```javascript
Expand Down
20 changes: 11 additions & 9 deletions lexers/testdata/markdown.expected
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
[
{"type":"GenericHeading","value":"#"},
{"type":"Text","value":" about\n"},
{"type":"Error","value":"\n"},
{"type":"GenericSubheading","value":"##"},
{"type":"Text","value":" user defined function in cql\n"},
{"type":"Error","value":"\n"},
{"type":"GenericHeading","value":"# about\n"},
{"type":"Text","value":"\nMultiple "},
{"type":"GenericStrong","value":"**bold**"},
{"type":"Text","value":" on the "},
{"type":"GenericStrong","value":"**same line**"},
{"type":"Text","value":".\n\n"},
{"type":"GenericSubheading","value":"## user defined function in cql\n"},
{"type":"Text","value":"\n"},
{"type":"LiteralString","value":"```javascript\n"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"column"},
Expand All @@ -17,7 +19,7 @@
{"type":"Punctuation","value":")"},
{"type":"Text","value":" \n"},
{"type":"LiteralString","value":"```"},
{"type":"Error","value":"\n\n"},
{"type":"Text","value":"\n\n"},
{"type":"LiteralString","value":"```cql\n"},
{"type":"Keyword","value":"CREATE"},
{"type":"TextWhitespace","value":" "},
Expand Down Expand Up @@ -132,7 +134,7 @@
{"type":"Punctuation","value":";"},
{"type":"TextWhitespace","value":"\n"},
{"type":"LiteralString","value":"```"},
{"type":"Error","value":"\n\n"},
{"type":"Text","value":"\n\n"},
{"type":"LiteralString","value":"```postgres\n"},
{"type":"Keyword","value":"DROP"},
{"type":"Text","value":" "},
Expand Down Expand Up @@ -423,5 +425,5 @@
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n"},
{"type":"LiteralString","value":"```"},
{"type":"Error","value":"\n"}
{"type":"Text","value":"\n"}
]

0 comments on commit c4bec47

Please sign in to comment.