Handle nested content inside links

This commit is contained in:
Christian Muehlhaeuser
2019-11-25 02:40:34 +01:00
parent d082cb2124
commit 6eb2d04812
+10
View File
@@ -221,14 +221,22 @@ func NewElement(node *bf.Node) Element {
Style: Del, Style: Del,
}}, }},
} }
case bf.Link: case bf.Link:
f := []Fragment{} f := []Fragment{}
if node.LastChild != nil {
if node.LastChild.Type == bf.Image {
el := NewElement(node.LastChild)
f = el.Fragments
}
if len(node.LastChild.Literal) > 0 { if len(node.LastChild.Literal) > 0 {
f = append(f, Fragment{ f = append(f, Fragment{
Token: string(node.LastChild.Literal), Token: string(node.LastChild.Literal),
Style: LinkText, Style: LinkText,
}) })
} }
}
if len(node.LinkData.Destination) > 0 { if len(node.LinkData.Destination) > 0 {
f = append(f, Fragment{ f = append(f, Fragment{
Token: string(node.LinkData.Destination), Token: string(node.LinkData.Destination),
@@ -243,6 +251,7 @@ func NewElement(node *bf.Node) Element {
Post: "", Post: "",
Fragments: f, Fragments: f,
} }
case bf.Image: case bf.Image:
f := []Fragment{} f := []Fragment{}
if len(node.LastChild.Literal) > 0 { if len(node.LastChild.Literal) > 0 {
@@ -265,6 +274,7 @@ func NewElement(node *bf.Node) Element {
Post: "", Post: "",
Fragments: f, Fragments: f,
} }
case bf.Text: case bf.Text:
return Element{ return Element{
Pre: "", Pre: "",