aboutsummaryrefslogtreecommitdiff
path: root/markdown
diff options
context:
space:
mode:
authorWilliam Hergès <william@herges.fr>2025-10-03 22:15:12 +0200
committerWilliam Hergès <william@herges.fr>2025-10-03 22:15:12 +0200
commitce6a2da035dc045510157a0eeefaebf56f0e8958 (patch)
tree47d6dca601372c110681a301f25f05279e456523 /markdown
parent9644afb7552d1b030beea6c8794f4419b9c686fe (diff)
fix(markdown): external source never stopped
Diffstat (limited to 'markdown')
-rw-r--r--markdown/ast_external.go4
-rw-r--r--markdown/ast_external_test.go4
-rw-r--r--markdown/ast_quote.go2
-rw-r--r--markdown/lexer.go2
4 files changed, 7 insertions, 5 deletions
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) != `<figure><img alt="image alt" src="image src"><figcaption>source 1 source 2</figcaption></figure>` {
+ if string(got) != `<figure><img alt="image alt" src="image src"><figcaption>source 1 source 2</figcaption></figure><p>Hors de la source</p>` {
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)
}