aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--markdown/ast_external.go20
-rw-r--r--markdown/ast_paragraph.go4
-rw-r--r--markdown/ast_test.go2
3 files changed, 16 insertions, 10 deletions
diff --git a/markdown/ast_external.go b/markdown/ast_external.go
index e648ad5..ee00eab 100644
--- a/markdown/ast_external.go
+++ b/markdown/ast_external.go
@@ -9,8 +9,9 @@ import (
var externalLink = regexp.MustCompile(`https?://`)
type astLink struct {
- content block
- href block
+ content block
+ href block
+ addSpace bool
}
func (a *astLink) Eval(opt *Option) (template.HTML, *ParseError) {
@@ -22,7 +23,11 @@ func (a *astLink) Eval(opt *Option) (template.HTML, *ParseError) {
if err != nil {
return "", err
}
- return RenderLink(string(content), string(href)), nil
+ rr := RenderLink(string(content), string(href))
+ if a.addSpace {
+ return " " + rr, nil
+ }
+ return rr, nil
}
func RenderLink(content, href string) template.HTML {
@@ -68,22 +73,25 @@ func external(lxs *lexers) (block, *ParseError) {
if !lxs.Next() {
return astLiteral(tp), nil
}
- lxs.Before() // because we call Next
+ lxs.Before() // because we called Next
+ addSpace := lxs.Before() && lxs.Current().Type == lexerBreak
+ lxs.Next() // because we called Before
var b block
var err *ParseError
switch tp {
case "![":
b, err = image(lxs)
case "[":
- b, err = link(lxs)
+ b, err = link(lxs, addSpace)
default:
b = astLiteral(tp)
}
return b, err
}
-func link(lxs *lexers) (block, *ParseError) {
+func link(lxs *lexers, addSpace bool) (block, *ParseError) {
lk := new(astLink)
+ lk.addSpace = addSpace
start := lxs.current
content, href, _, ok := parseExternal(lxs, false)
if !ok {
diff --git a/markdown/ast_paragraph.go b/markdown/ast_paragraph.go
index ae1f657..ca5541f 100644
--- a/markdown/ast_paragraph.go
+++ b/markdown/ast_paragraph.go
@@ -87,9 +87,7 @@ func paragraph(lxs *lexers, oneLine bool) (*astParagraph, *ParseError) {
tree.content = append(tree.content, b)
}
}
- if !lxs.Finished() {
- lxs.Before() // because we never handle the last item
- }
+ lxs.Before() // because we never handle the last item
return tree, nil
}
diff --git a/markdown/ast_test.go b/markdown/ast_test.go
index ff11b1e..45eb49d 100644
--- a/markdown/ast_test.go
+++ b/markdown/ast_test.go
@@ -41,7 +41,7 @@ var parsed = `
<ul><li>hehe</li></ul>
<figure>
<img alt="Ceci est ma pfp :3" src="https://cdn.anhgelus.world/pfp.jpg">
-<figcaption><a href="https://now.anhgelus.world/" target="_blank" rel="noreferer">Ma pfp</a> hehe :D Elle est <b>magnifique</b>, n&#39;est-ce pas ?</figcaption>
+<figcaption> <a href="https://now.anhgelus.world/" target="_blank" rel="noreferer">Ma pfp</a> hehe :D Elle est <b>magnifique</b>, n&#39;est-ce pas ?</figcaption>
</figure>
`