mirror of
https://github.com/rwinkhart/glamour-temp-MUTN.git
synced 2026-09-05 16:37:19 -04:00
Use textFromChildren to parse the aggregate content of Link nodes
This commit is contained in:
+19
-2
@@ -209,10 +209,9 @@ func (tr *ANSIRenderer) NewElement(node ast.Node, source []byte) Element {
|
|||||||
// Links
|
// Links
|
||||||
case ast.KindLink:
|
case ast.KindLink:
|
||||||
n := node.(*ast.Link)
|
n := node.(*ast.Link)
|
||||||
text := string(n.Text(source))
|
|
||||||
return Element{
|
return Element{
|
||||||
Renderer: &LinkElement{
|
Renderer: &LinkElement{
|
||||||
Text: text,
|
Text: textFromChildren(node, source),
|
||||||
BaseURL: ctx.options.BaseURL,
|
BaseURL: ctx.options.BaseURL,
|
||||||
URL: string(n.Destination),
|
URL: string(n.Destination),
|
||||||
},
|
},
|
||||||
@@ -381,3 +380,21 @@ func (tr *ANSIRenderer) NewElement(node ast.Node, source []byte) Element {
|
|||||||
return 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
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user