mirror of
https://github.com/rwinkhart/glamour-temp-MUTN.git
synced 2026-08-30 21:56:44 -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
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user