diff options
| -rw-r--r-- | markdown/lexer.go | 19 | ||||
| -rw-r--r-- | markdown/lexer_test.go | 5 |
2 files changed, 23 insertions, 1 deletions
diff --git a/markdown/lexer.go b/markdown/lexer.go index afdc4a0..f79b2ec 100644 --- a/markdown/lexer.go +++ b/markdown/lexer.go @@ -19,6 +19,7 @@ const ( lexerList lexerType = "list" lexerExternal lexerType = "external" + lexerCallout lexerType = "callout" lexerLiteral lexerType = "literal" lexerReplace lexerType = "replace" @@ -134,7 +135,23 @@ func lex(s string, opt *Option) *lexers { fn(c, lexerHeading, nil) case '>': fn(c, lexerQuote, nil) - case '[', ']', '(', ')', '!': + case '[', ']', '!': + if !newLine && i < len(runes)-1 { + next := runes[i+1] + runes := []rune(previous) + if c == '[' && next == '!' { + fn(c, lexerCallout, nil) + continue + } else if c == '!' && len(runes) > 0 && previous[len(previous)-1] == '[' { + fn(c, lexerCallout, nil) + continue + } else if c == ']' && next != '(' { + fn(c, lexerCallout, nil) + continue + } + } + fallthrough + case '(', ')': fn(c, lexerExternal, func(c rune) bool { return validExternal(previous + string(c)) }) case '-', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.': fn(c, lexerList, nil) diff --git a/markdown/lexer_test.go b/markdown/lexer_test.go index d8ec3ba..5736b2a 100644 --- a/markdown/lexer_test.go +++ b/markdown/lexer_test.go @@ -28,6 +28,11 @@ func TestLex(t *testing.T) { if lxs.String() != `Lexers[list(*) literal( list) ]` { t.Errorf("invalid lex, got %s", lxs) } + lxs = lex(`> [!NOTE] title +> hey`, opt) + if lxs.String() != `Lexers[quote(>) literal( ) callout([!) literal(NOTE) callout(]) literal( title) break({\n}) quote(>) literal( hey) ]` { + t.Errorf("invalid lex, got %s", lxs) + } } func TestLex_Replacer(t *testing.T) { |
