diff --git a/ansi/elements.go b/ansi/elements.go index b8fdc81..7c6c3c1 100644 --- a/ansi/elements.go +++ b/ansi/elements.go @@ -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 +}