Use textFromChildren to parse the aggregate content of Link nodes

This commit is contained in:
Christian Muehlhaeuser
2019-12-28 01:32:59 +01:00
parent 4c42a50164
commit 8405e35ac8
+19 -2
View File
@@ -209,10 +209,9 @@ func (tr *ANSIRenderer) NewElement(node ast.Node, source []byte) Element {
// Links
case ast.KindLink:
n := node.(*ast.Link)
text := string(n.Text(source))
return Element{
Renderer: &LinkElement{
Text: text,
Text: textFromChildren(node, source),
BaseURL: ctx.options.BaseURL,
URL: string(n.Destination),
},
@@ -381,3 +380,21 @@ func (tr *ANSIRenderer) NewElement(node ast.Node, source []byte) Element {
return Element{}
}
}
func textFromChildren(node ast.Node, source []byte) string {
var s string
for c := node.FirstChild(); c != nil; c = c.NextSibling() {
if c.Kind() == ast.KindText {
cn := c.(*ast.Text)
s += string(cn.Segment.Value(source))
if cn.HardLineBreak() || (cn.SoftLineBreak()) {
s += "\n"
}
} else {
s += string(c.Text(source))
}
}
return s
}