From ce6a2da035dc045510157a0eeefaebf56f0e8958 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Herg=C3=A8s?= Date: Fri, 3 Oct 2025 22:15:12 +0200 Subject: fix(markdown): external source never stopped --- markdown/ast_external.go | 4 ++-- markdown/ast_external_test.go | 4 +++- markdown/ast_quote.go | 2 +- markdown/lexer.go | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) (limited to 'markdown') diff --git a/markdown/ast_external.go b/markdown/ast_external.go index a172b2b..ea78450 100644 --- a/markdown/ast_external.go +++ b/markdown/ast_external.go @@ -119,7 +119,7 @@ func parseExternal(lxs *lexers, withSource bool) (string, string, []*astParagrap return "", "", nil, false } n += len(lxs.Current().Value) - if first != "" && end != "" { + if n < 2 && first != "" && end != "" { if !lxs.Next() { return first, end, ps, true } @@ -127,8 +127,8 @@ func parseExternal(lxs *lexers, withSource bool) (string, string, []*astParagrap if !ok { return "", "", nil, false } - lxs.Before() // because we must parse lexerBreak } + lxs.Before() // because we must parse lexerBreak and the next call must parse the next value case lexerExternal: if first != "" && end != "" { return "", "", nil, false diff --git a/markdown/ast_external_test.go b/markdown/ast_external_test.go index 6de512b..306b9d0 100644 --- a/markdown/ast_external_test.go +++ b/markdown/ast_external_test.go @@ -33,6 +33,8 @@ func TestExternal(t *testing.T) { ![image alt](image src) source 1 source 2 + +Hors de la source `) tree, err = ast(lxs) if err != nil { @@ -42,7 +44,7 @@ source 2 if err != nil { t.Fatal(err) } - if string(got) != `
image alt
source 1 source 2
` { + if string(got) != `
image alt
source 1 source 2

Hors de la source

` { t.Errorf("invalid value, got %s", got) } diff --git a/markdown/ast_quote.go b/markdown/ast_quote.go index 3dfede1..3040636 100644 --- a/markdown/ast_quote.go +++ b/markdown/ast_quote.go @@ -54,7 +54,7 @@ func quote(lxs *lexers) (*astQuote, *ParseError) { return tree, nil } quoteContinue = true - case lexerLiteral, lexerModifier, lexerCode: + case lexerLiteral, lexerModifier, lexerCode, lexerExternal: n = 0 if !quoteContinue { source = true diff --git a/markdown/lexer.go b/markdown/lexer.go index a02ec54..651e3aa 100644 --- a/markdown/lexer.go +++ b/markdown/lexer.go @@ -25,7 +25,7 @@ type lexer struct { Value string } -func (l *lexer) String() string { +func (l lexer) String() string { return fmt.Sprintf("%s(%s)", l.Type, l.Value) } -- cgit v1.2.3