Skip to content

Commit 1f48e65

Browse files
committed
fix(markdown): don't delegate to HTML lexer
This causes issues whereby Markdown code fragments such as: ``` `<script>` ``` Are treated as HTML, resulting in errors and backtracking. Note that this does mean that HTML in Markdown is not highlighted, but we can potentially add rules to the Markdown lexer to solve that. Fixes #1119
1 parent ea89498 commit 1f48e65

File tree

2 files changed

+4
-16
lines changed

2 files changed

+4
-16
lines changed

lexers/markdown.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import (
55
)
66

77
// Markdown lexer.
8-
var Markdown = Register(DelegatingLexer(HTML, MustNewLexer(
8+
var Markdown = Register(MustNewLexer(
99
&Config{
1010
Name: "markdown",
1111
Aliases: []string{"md", "mkd"},
1212
Filenames: []string{"*.md", "*.mkd", "*.markdown"},
1313
MimeTypes: []string{"text/x-markdown"},
1414
},
1515
markdownRules,
16-
)))
16+
))
1717

1818
func markdownRules() Rules {
1919
return Rules{
@@ -40,7 +40,7 @@ func markdownRules() Rules {
4040
{"`[^`]+`", LiteralStringBacktick, nil},
4141
{`[@#][\w/:]+`, NameEntity, nil},
4242
{`(!?\[)([^]]+)(\])(\()([^)]+)(\))`, ByGroups(Text, NameTag, Text, Text, NameAttribute, Text), nil},
43-
{`.|\n`, Other, nil},
43+
{`.|\n`, Text, nil},
4444
},
4545
}
4646
}

lexers/testdata/markdown.expected

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
[
22
{"type":"GenericHeading","value":"# about\n"},
3-
{"type":"Text","value":"\n"},
4-
{"type":"Punctuation","value":"\u003c"},
5-
{"type":"NameTag","value":"div"},
6-
{"type":"Text","value":" "},
7-
{"type":"NameAttribute","value":"class"},
8-
{"type":"Operator","value":"="},
9-
{"type":"LiteralString","value":"\"html\""},
10-
{"type":"Punctuation","value":"\u003e"},
11-
{"type":"Text","value":"HTML"},
12-
{"type":"Punctuation","value":"\u003c/"},
13-
{"type":"NameTag","value":"div"},
14-
{"type":"Punctuation","value":"\u003e"},
15-
{"type":"Text","value":"\n\nMultiple "},
3+
{"type":"Text","value":"\n\u003cdiv class=\"html\"\u003eHTML\u003c/div\u003e\n\nMultiple "},
164
{"type":"GenericStrong","value":"**bold**"},
175
{"type":"Text","value":" on the "},
186
{"type":"GenericStrong","value":"**same line**"},

0 commit comments

Comments
 (0)