mirror of
https://github.com/alecthomas/chroma.git
synced 2025-03-19 21:10:15 +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:
parent
2a59c2c77e
commit
c4bec47e7d
@ -15,8 +15,8 @@ var Markdown = internal.Register(MustNewLexer(
|
|||||||
},
|
},
|
||||||
Rules{
|
Rules{
|
||||||
"root": {
|
"root": {
|
||||||
{`^(#)([^#].+\n)`, ByGroups(GenericHeading, Text), nil},
|
{`^(#[^#].+\n)`, ByGroups(GenericHeading), nil},
|
||||||
{`^(#{2,6})(.+\n)`, ByGroups(GenericSubheading, Text), nil},
|
{`^(#{2,6}.+\n)`, ByGroups(GenericSubheading), nil},
|
||||||
{`^(\s*)([*-] )(\[[ xX]\])( .+\n)`, ByGroups(Text, Keyword, Keyword, UsingSelf("inline")), nil},
|
{`^(\s*)([*-] )(\[[ xX]\])( .+\n)`, ByGroups(Text, Keyword, Keyword, UsingSelf("inline")), nil},
|
||||||
{`^(\s*)([*-])(\s)(.+\n)`, ByGroups(Text, Keyword, Text, UsingSelf("inline")), nil},
|
{`^(\s*)([*-])(\s)(.+\n)`, ByGroups(Text, Keyword, Text, UsingSelf("inline")), nil},
|
||||||
{`^(\s*)([0-9]+\.)( .+\n)`, ByGroups(Text, Keyword, UsingSelf("inline")), nil},
|
{`^(\s*)([0-9]+\.)( .+\n)`, ByGroups(Text, Keyword, UsingSelf("inline")), nil},
|
||||||
@ -35,13 +35,13 @@ var Markdown = internal.Register(MustNewLexer(
|
|||||||
"inline": {
|
"inline": {
|
||||||
{`\\.`, Text, nil},
|
{`\\.`, Text, nil},
|
||||||
{`(\s)([*_][^*_]+[*_])(\W|\n)`, ByGroups(Text, GenericEmph, 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},
|
{`(\s)(~~[^~]+~~)((?=\W|\n))`, ByGroups(Text, GenericDeleted, Text), nil},
|
||||||
{"`[^`]+`", LiteralStringBacktick, nil},
|
{"`[^`]+`", LiteralStringBacktick, nil},
|
||||||
{`[@#][\w/:]+`, NameEntity, nil},
|
{`[@#][\w/:]+`, NameEntity, nil},
|
||||||
{`(!?\[)([^]]+)(\])(\()([^)]+)(\))`, ByGroups(Text, NameTag, Text, Text, NameAttribute, Text), nil},
|
{`(!?\[)([^]]+)(\])(\()([^)]+)(\))`, ByGroups(Text, NameTag, Text, Text, NameAttribute, Text), nil},
|
||||||
{`[^\\\s]+`, Text, nil},
|
{`[^\\\s]+`, Text, nil},
|
||||||
{`.`, Text, nil},
|
{`.|\n`, Text, nil},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
|
2
lexers/testdata/markdown.actual
vendored
2
lexers/testdata/markdown.actual
vendored
@ -1,5 +1,7 @@
|
|||||||
# about
|
# about
|
||||||
|
|
||||||
|
Multiple **bold** on the **same line**.
|
||||||
|
|
||||||
## user defined function in cql
|
## user defined function in cql
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
|
20
lexers/testdata/markdown.expected
vendored
20
lexers/testdata/markdown.expected
vendored
@ -1,10 +1,12 @@
|
|||||||
[
|
[
|
||||||
{"type":"GenericHeading","value":"#"},
|
{"type":"GenericHeading","value":"# about\n"},
|
||||||
{"type":"Text","value":" about\n"},
|
{"type":"Text","value":"\nMultiple "},
|
||||||
{"type":"Error","value":"\n"},
|
{"type":"GenericStrong","value":"**bold**"},
|
||||||
{"type":"GenericSubheading","value":"##"},
|
{"type":"Text","value":" on the "},
|
||||||
{"type":"Text","value":" user defined function in cql\n"},
|
{"type":"GenericStrong","value":"**same line**"},
|
||||||
{"type":"Error","value":"\n"},
|
{"type":"Text","value":".\n\n"},
|
||||||
|
{"type":"GenericSubheading","value":"## user defined function in cql\n"},
|
||||||
|
{"type":"Text","value":"\n"},
|
||||||
{"type":"LiteralString","value":"```javascript\n"},
|
{"type":"LiteralString","value":"```javascript\n"},
|
||||||
{"type":"Text","value":" "},
|
{"type":"Text","value":" "},
|
||||||
{"type":"NameOther","value":"column"},
|
{"type":"NameOther","value":"column"},
|
||||||
@ -17,7 +19,7 @@
|
|||||||
{"type":"Punctuation","value":")"},
|
{"type":"Punctuation","value":")"},
|
||||||
{"type":"Text","value":" \n"},
|
{"type":"Text","value":" \n"},
|
||||||
{"type":"LiteralString","value":"```"},
|
{"type":"LiteralString","value":"```"},
|
||||||
{"type":"Error","value":"\n\n"},
|
{"type":"Text","value":"\n\n"},
|
||||||
{"type":"LiteralString","value":"```cql\n"},
|
{"type":"LiteralString","value":"```cql\n"},
|
||||||
{"type":"Keyword","value":"CREATE"},
|
{"type":"Keyword","value":"CREATE"},
|
||||||
{"type":"TextWhitespace","value":" "},
|
{"type":"TextWhitespace","value":" "},
|
||||||
@ -132,7 +134,7 @@
|
|||||||
{"type":"Punctuation","value":";"},
|
{"type":"Punctuation","value":";"},
|
||||||
{"type":"TextWhitespace","value":"\n"},
|
{"type":"TextWhitespace","value":"\n"},
|
||||||
{"type":"LiteralString","value":"```"},
|
{"type":"LiteralString","value":"```"},
|
||||||
{"type":"Error","value":"\n\n"},
|
{"type":"Text","value":"\n\n"},
|
||||||
{"type":"LiteralString","value":"```postgres\n"},
|
{"type":"LiteralString","value":"```postgres\n"},
|
||||||
{"type":"Keyword","value":"DROP"},
|
{"type":"Keyword","value":"DROP"},
|
||||||
{"type":"Text","value":" "},
|
{"type":"Text","value":" "},
|
||||||
@ -423,5 +425,5 @@
|
|||||||
{"type":"Punctuation","value":";"},
|
{"type":"Punctuation","value":";"},
|
||||||
{"type":"Text","value":"\n"},
|
{"type":"Text","value":"\n"},
|
||||||
{"type":"LiteralString","value":"```"},
|
{"type":"LiteralString","value":"```"},
|
||||||
{"type":"Error","value":"\n"}
|
{"type":"Text","value":"\n"}
|
||||||
]
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user