Detect mailto links and fix their markup

This commit is contained in:
Christian Muehlhaeuser
2019-12-13 22:50:18 +01:00
parent 6045dadccf
commit 46f0b9dbbd
+9 -3
View File
@@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
"strings"
"github.com/yuin/goldmark/ast" "github.com/yuin/goldmark/ast"
astext "github.com/yuin/goldmark/extension/ast" astext "github.com/yuin/goldmark/extension/ast"
@@ -208,12 +209,17 @@ func (tr *TermRenderer) NewElement(node ast.Node, source []byte) Element {
} }
case ast.KindAutoLink: case ast.KindAutoLink:
n := node.(*ast.AutoLink) n := node.(*ast.AutoLink)
text := string(n.Text(source)) u := string(n.URL(source))
label := string(n.Label(source))
if n.AutoLinkType == ast.AutoLinkEmail && !strings.HasPrefix(strings.ToLower(u), "mailto:") {
u = "mailto:" + u
}
return Element{ return Element{
Renderer: &LinkElement{ Renderer: &LinkElement{
Text: text, Text: label,
BaseURL: ctx.options.BaseURL, BaseURL: ctx.options.BaseURL,
URL: string(n.URL(source)), URL: u,
}, },
} }