mirror of
https://github.com/rwinkhart/glamour-temp-MUTN.git
synced 2026-09-05 16:37:19 -04:00
Detect mailto links and fix their markup
This commit is contained in:
+9
-3
@@ -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,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user