1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-03-17 20:58:08 +02:00

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.
This commit is contained in:
Alec Thomas 2018-12-31 19:32:29 +11:00
parent 2a59c2c77e
commit c4bec47e7d
3 changed files with 17 additions and 13 deletions

View File

@ -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},
@ -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},
},
},
))

View File

@ -1,5 +1,7 @@
# about
Multiple **bold** on the **same line**.
## user defined function in cql
```javascript

View File

@ -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"},
@ -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":" "},
@ -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":" "},
@ -423,5 +425,5 @@
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n"},
{"type":"LiteralString","value":"```"},
{"type":"Error","value":"\n"}
{"type":"Text","value":"\n"}
]