parser.leg: print_tree: write to an io.Writer
This commit is contained in:
parent
4c6a2bc6b5
commit
0cbfa7b920
11
parser.leg
11
parser.leg
@ -22,6 +22,7 @@ package markdown
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
"log"
|
"log"
|
||||||
"sync"
|
"sync"
|
||||||
@ -992,24 +993,24 @@ func (d *Doc) find_note(label string) (*element, bool) {
|
|||||||
|
|
||||||
/* print tree of elements, for debugging only.
|
/* print tree of elements, for debugging only.
|
||||||
*/
|
*/
|
||||||
func print_tree(elt *element, indent int) {
|
func print_tree(w io.Writer, elt *element, indent int) {
|
||||||
var key string
|
var key string
|
||||||
|
|
||||||
for elt != nil {
|
for elt != nil {
|
||||||
for i := 0; i < indent; i++ {
|
for i := 0; i < indent; i++ {
|
||||||
fmt.Print("\t")
|
fmt.Fprint(w, "\t")
|
||||||
}
|
}
|
||||||
key = keynames[elt.key]
|
key = keynames[elt.key]
|
||||||
if key == "" {
|
if key == "" {
|
||||||
key = "?"
|
key = "?"
|
||||||
}
|
}
|
||||||
if elt.key == STR {
|
if elt.key == STR {
|
||||||
fmt.Printf("%p:\t%s\t'%s'\n", elt, key, elt.contents.str)
|
fmt.Fprintf(w, "%p:\t%s\t'%s'\n", elt, key, elt.contents.str)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("%p:\t%s %p\n", elt, key, elt.next)
|
fmt.Fprintf(w, "%p:\t%s %p\n", elt, key, elt.next)
|
||||||
}
|
}
|
||||||
if elt.children != nil {
|
if elt.children != nil {
|
||||||
print_tree(elt.children, indent+1)
|
print_tree(w, elt.children, indent+1)
|
||||||
}
|
}
|
||||||
elt = elt.next
|
elt = elt.next
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user