From 5a1a0f6457a0dcf13e408e1a8b32151d70cfddff Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Sat, 28 Dec 2019 00:37:56 +0100 Subject: [PATCH] Traverse through parents to detect ignored AST children --- ansi/renderer.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/ansi/renderer.go b/ansi/renderer.go index 7c65b31..c14217c 100644 --- a/ansi/renderer.go +++ b/ansi/renderer.go @@ -129,17 +129,15 @@ func (r *ANSIRenderer) renderNode(w util.BufWriter, source []byte, node ast.Node } func isChild(node ast.Node) bool { - if node.Parent() == nil { - return false + for n := node.Parent(); n != nil; n = n.Parent() { + // These types are already rendered by their parent + switch n.Kind() { + case ast.KindLink, ast.KindImage, ast.KindEmphasis, astext.KindStrikethrough, ast.KindBlockquote, astext.KindTableCell: + return true + } } - // These types are already rendered by their parent - switch node.Parent().Kind() { - case ast.KindLink, ast.KindImage, ast.KindEmphasis, astext.KindStrikethrough, ast.KindBlockquote, astext.KindTableCell: - return true - default: - return false - } + return false } func resolveRelativeURL(baseURL string, rel string) string {