aboutsummaryrefslogtreecommitdiff
path: root/markdown
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2025-12-10 12:20:21 +0100
committerAnhgelus Morhtuuzh <william@herges.fr>2025-12-10 12:20:21 +0100
commit707121c88e2a97d3bfceaba850dcdda79c0f4f37 (patch)
tree55a3b37fa6f57d784a059bd8cacba5cb8e746a58 /markdown
parent1da34bf7dd198f2cf2a287be4262c61e0e54c275 (diff)
fix(markdown): bad render of external images in rare cases
Diffstat (limited to 'markdown')
-rw-r--r--markdown/ast_external_test.go3
-rw-r--r--markdown/ast_paragraph.go4
-rw-r--r--markdown/lexer.go7
-rw-r--r--markdown/lexer_test.go2
4 files changed, 12 insertions, 4 deletions
diff --git a/markdown/ast_external_test.go b/markdown/ast_external_test.go
index f3ac976..514cc89 100644
--- a/markdown/ast_external_test.go
+++ b/markdown/ast_external_test.go
@@ -32,6 +32,7 @@ func TestExternal(t *testing.T) {
}
lxs = lex(`
+Avant la source
![image alt](image src)
source 1
source 2
@@ -46,7 +47,7 @@ Hors de la source
if err != nil {
t.Fatal(err)
}
- if string(got) != `<figure><img alt="image alt" src="image src"><figcaption>source 1 source 2</figcaption></figure><p>Hors de la source</p>` {
+ if string(got) != `<p>Avant la source</p><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_paragraph.go b/markdown/ast_paragraph.go
index 361b2f2..197c7e3 100644
--- a/markdown/ast_paragraph.go
+++ b/markdown/ast_paragraph.go
@@ -65,6 +65,10 @@ func paragraph(lxs *lexers, oneLine bool) (*astParagraph, *ParseError) {
}
tree.content = append(tree.content, mod)
case lexerExternal:
+ if n > 0 && lxs.Current().Value == "![" {
+ lxs.Before() // because we did not use it
+ return tree, nil
+ }
n = 0
if lxs.Current().Value == "!" {
tree.content = append(tree.content, astLiteral(lxs.Current().Value))
diff --git a/markdown/lexer.go b/markdown/lexer.go
index d5c0f5f..30587e4 100644
--- a/markdown/lexer.go
+++ b/markdown/lexer.go
@@ -1,6 +1,9 @@
package markdown
-import "fmt"
+import (
+ "fmt"
+ "strings"
+)
type lexerType string
@@ -26,7 +29,7 @@ type lexer struct {
}
func (l lexer) String() string {
- return fmt.Sprintf("%s(%s)", l.Type, l.Value)
+ return fmt.Sprintf("%s(%s)", l.Type, strings.ReplaceAll(l.Value, "\n", `{\n}`))
}
type lexers struct {
diff --git a/markdown/lexer_test.go b/markdown/lexer_test.go
index c670753..e994142 100644
--- a/markdown/lexer_test.go
+++ b/markdown/lexer_test.go
@@ -12,7 +12,7 @@ func TestLex(t *testing.T) {
t.Errorf("invalid lex, got %s", lxs)
}
lxs = lex("# bonjour les gens\nComment ça va ?")
- if lxs.String() != "Lexers[header(#) literal( bonjour les gens) break(\n) literal(Comment ça va ?) ]" {
+ if lxs.String() != `Lexers[header(#) literal( bonjour les gens) break({\n}) literal(Comment ça va ?) ]` {
t.Errorf("invalid lex, got %s", lxs)
}
lxs = lex("***hey***, what's up?")