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

Fallback to HTML lexer for Markdown text.

Fixes #321.
This commit is contained in:
Alec Thomas 2020-03-05 15:04:15 +11:00
parent 34d9c7143b
commit 4f3623dce6
3 changed files with 20 additions and 5 deletions

View File

@ -2,11 +2,12 @@ package m
import (
. "github.com/alecthomas/chroma" // nolint
"github.com/alecthomas/chroma/lexers/h"
"github.com/alecthomas/chroma/lexers/internal"
)
// Markdown lexer.
var Markdown = internal.Register(MustNewLexer(
var Markdown = internal.Register(DelegatingLexer(h.HTML, MustNewLexer(
&Config{
Name: "markdown",
Aliases: []string{"md", "mkd"},
@ -40,8 +41,8 @@ var Markdown = internal.Register(MustNewLexer(
{"`[^`]+`", LiteralStringBacktick, nil},
{`[@#][\w/:]+`, NameEntity, nil},
{`(!?\[)([^]]+)(\])(\()([^)]+)(\))`, ByGroups(Text, NameTag, Text, Text, NameAttribute, Text), nil},
{`[^\\\s]+`, Text, nil},
{`.|\n`, Text, nil},
{`[^\\\s]+`, Other, nil},
{`.|\n`, Other, nil},
},
},
))
)))

View File

@ -1,5 +1,7 @@
# about
<div class="html">HTML</div>
Multiple **bold** on the **same line**.
## user defined function in cql

View File

@ -1,6 +1,18 @@
[
{"type":"GenericHeading","value":"# about\n"},
{"type":"Text","value":"\nMultiple "},
{"type":"Text","value":"\n"},
{"type":"Punctuation","value":"\u003c"},
{"type":"NameTag","value":"div"},
{"type":"Text","value":" "},
{"type":"NameAttribute","value":"class"},
{"type":"Operator","value":"="},
{"type":"LiteralString","value":"\"html\""},
{"type":"Punctuation","value":"\u003e"},
{"type":"Text","value":"HTML"},
{"type":"Punctuation","value":"\u003c/"},
{"type":"NameTag","value":"div"},
{"type":"Punctuation","value":"\u003e"},
{"type":"Text","value":"\n\nMultiple "},
{"type":"GenericStrong","value":"**bold**"},
{"type":"Text","value":" on the "},
{"type":"GenericStrong","value":"**same line**"},