1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-11-27 22:38:42 +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 ( import (
. "github.com/alecthomas/chroma" // nolint . "github.com/alecthomas/chroma" // nolint
"github.com/alecthomas/chroma/lexers/h"
"github.com/alecthomas/chroma/lexers/internal" "github.com/alecthomas/chroma/lexers/internal"
) )
// Markdown lexer. // Markdown lexer.
var Markdown = internal.Register(MustNewLexer( var Markdown = internal.Register(DelegatingLexer(h.HTML, MustNewLexer(
&Config{ &Config{
Name: "markdown", Name: "markdown",
Aliases: []string{"md", "mkd"}, Aliases: []string{"md", "mkd"},
@@ -40,8 +41,8 @@ var Markdown = internal.Register(MustNewLexer(
{"`[^`]+`", 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]+`, Other, nil},
{`.|\n`, Text, nil}, {`.|\n`, Other, nil},
}, },
}, },
)) )))

View File

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

View File

@@ -1,6 +1,18 @@
[ [
{"type":"GenericHeading","value":"# about\n"}, {"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":"GenericStrong","value":"**bold**"},
{"type":"Text","value":" on the "}, {"type":"Text","value":" on the "},
{"type":"GenericStrong","value":"**same line**"}, {"type":"GenericStrong","value":"**same line**"},