-
Notifications
You must be signed in to change notification settings - Fork 185
Closed
Description
I'm planning to extend the gomarkdown markdown renderer to render links at the bottom of the page, rather than inline. The best way that I've found to do that (I'm open to other suggestions!) is to override the renderer for links like this:
func (r *CustomMDRenderer) fmtLink(w io.Writer, node ast.Node, entering bool) ast.WalkStatus {
if entering {
w.Write([]byte("["))
} else {
w.Write([]byte("]"))
linkNode, ok := node.(*ast.Link)
if !ok {
return ast.GoToNext
}
child := ast.GetFirstChild(node)
if child == nil {
return ast.GoToNext
}
if reflect.TypeOf(child) != reflect.TypeOf(&ast.Text{}) {
return ast.GoToNext
}
textChild, ok := child.(*ast.Text)
if !ok {
return ast.GoToNext
}
linkStr := fmt.Sprintf("[%s]: %s", textChild.Leaf.Literal, linkNode.Destination)
r.linkcache[linkStr] = true
}
return ast.GoToNext
}
...and then write out the linkcache in the footer. However, this depends on directly referencing textChild.Leaf.Literal and linkNode.Destination, which makes my code fragile in case those field names change in the future. Any chance of getting methods on ast.Link that return those values? (e.g. Link.Text() and Link.Destination())
Metadata
Metadata
Assignees
Labels
No labels