From 4f3623dce67a1a19f99b87be1168cf3bac708c07 Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Thu, 5 Mar 2020 15:04:15 +1100 Subject: [PATCH] Fallback to HTML lexer for Markdown text. Fixes #321. --- lexers/m/markdown.go | 9 +++++---- lexers/testdata/markdown.actual | 2 ++ lexers/testdata/markdown.expected | 14 +++++++++++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lexers/m/markdown.go b/lexers/m/markdown.go index 3720da2b4..dd78ec08d 100644 --- a/lexers/m/markdown.go +++ b/lexers/m/markdown.go @@ -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}, }, }, -)) +))) diff --git a/lexers/testdata/markdown.actual b/lexers/testdata/markdown.actual index c621f2824..146ae3c3e 100644 --- a/lexers/testdata/markdown.actual +++ b/lexers/testdata/markdown.actual @@ -1,5 +1,7 @@ # about +
HTML
+ Multiple **bold** on the **same line**. ## user defined function in cql diff --git a/lexers/testdata/markdown.expected b/lexers/testdata/markdown.expected index 1d39de5fc..0c5008486 100644 --- a/lexers/testdata/markdown.expected +++ b/lexers/testdata/markdown.expected @@ -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**"},