Copy newick escaping code from treemachine