all repos — grayfriday @ f1361aa0da306b57ae030017cc7451f2b2419942

blackfriday fork with a few changes

Make ForEachNode func a Walk method on Node
Vytautas Ĺ altenis vytas@rtfb.lt
Fri, 01 Apr 2016 12:36:56 +0300
commit

f1361aa0da306b57ae030017cc7451f2b2419942

parent

04673c9f2899eac2c8c1a44df63682963ad4e121

3 files changed, 13 insertions(+), 13 deletions(-)

jump to
M html.gohtml.go

@@ -1394,7 +1394,7 @@ //println("render_Blackfriday")

//dump(ast) // Run Smartypants if it's enabled or simply escape text if not sr := NewSmartypantsRenderer(r.extensions) - ForEachNode(ast, func(node *Node, entering bool) { + ast.Walk(func(node *Node, entering bool) { if node.Type == Text { if r.extensions&Smartypants != 0 { node.Literal = sr.Process(node.Literal)

@@ -1404,7 +1404,7 @@ }

} }) var buff bytes.Buffer - ForEachNode(ast, func(node *Node, entering bool) { + ast.Walk(func(node *Node, entering bool) { r.RenderNode(&buff, node, entering) }) return buff.Bytes()
M markdown.gomarkdown.go

@@ -450,7 +450,7 @@ for p.tip != nil {

p.finalize(p.tip) } // Walk the tree again and process inline markdown in each block - ForEachNode(p.doc, func(node *Node, entering bool) { + p.doc.Walk(func(node *Node, entering bool) { if node.Type == Paragraph || node.Type == Header || node.Type == TableCell { p.currBlock = node p.inline(node.content)

@@ -493,7 +493,7 @@ above := block.Parent

finalizeList(block) p.tip = above finalizeHtmlBlock(p.addBlock(HtmlBlock, []byte("</div>"))) - ForEachNode(block, func(node *Node, entering bool) { + block.Walk(func(node *Node, entering bool) { if node.Type == Paragraph || node.Type == Header { p.currBlock = node p.inline(node.content)
M node.gonode.go

@@ -216,6 +216,15 @@ }

return false } +func (root *Node) Walk(visitor func(node *Node, entering bool)) { + walker := NewNodeWalker(root) + node, entering := walker.next() + for node != nil { + visitor(node, entering) + node, entering = walker.next() + } +} + type NodeWalker struct { current *Node root *Node

@@ -261,15 +270,6 @@

func (nw *NodeWalker) resumeAt(node *Node, entering bool) { nw.current = node nw.entering = entering -} - -func ForEachNode(root *Node, f func(node *Node, entering bool)) { - walker := NewNodeWalker(root) - node, entering := walker.next() - for node != nil { - f(node, entering) - node, entering = walker.next() - } } func dump(ast *Node) {