@@ -194,7 +194,9 @@ function print_tree(printnode::Function, io::IO, node;
194194 prefix:: AbstractString = " " ,
195195 )
196196 # Get node representation as string
197- str = repr_node (node, context= io)
197+ buf = IOBuffer ()
198+ printnode (IOContext (buf, io), node)
199+ str = String (take! (buf))
198200
199201 # Copy buffer to output, prepending prefix to each line
200202 for (i, line) in enumerate (split (str, ' \n ' ))
@@ -249,7 +251,6 @@ function print_tree(printnode::Function, io::IO, node;
249251
250252 # Print key
251253 if this_printkeys
252- buf = IOBuffer ()
253254 print_child_key (IOContext (buf, io), child_key)
254255 key_str = String (take! (buf))
255256
@@ -271,14 +272,16 @@ print_tree(node; kw...) = print_tree(stdout, node; kw...)
271272
272273"""
273274 repr_tree(tree; context=nothing, kw...)
275+ repr_tree(f, tree; context=nothing, kw...)
274276
275277Get the string result of calling [`print_tree`](@ref) with the supplied arguments.
276278
277279The `context` argument works as it does in `Base.repr`.
278280"""
279- function repr_tree (tree; context= nothing , kw... )
281+ repr_tree (tree; context= nothing , kw... ) = repr_tree (printnode, tree; context= nothing , kw... )
282+ function repr_tree (f, tree; context= nothing , kw... )
280283 buf = IOBuffer ()
281284 io = context === nothing ? buf : IOContext (buf, context)
282- print_tree (io, tree; kw... )
285+ print_tree (f, io, tree; kw... )
283286 return String (take! (buf))
284287end
0 commit comments