From 18ceb6bca53046b3ea75f7509f46c1a9ab39fb40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Mart=C3=ADnez=20Portela?= Date: Sat, 20 Aug 2022 17:50:40 +0200 Subject: [PATCH] Make debug `print_tree` more comprehensive. --- scripts/generate.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/scripts/generate.py b/scripts/generate.py index 086e7a5..a42a607 100644 --- a/scripts/generate.py +++ b/scripts/generate.py @@ -232,15 +232,28 @@ def main(src_top, dest_top): logging.info("Updated all in {:.2f}s".format(time.time() - t0)) -def print_tree(tree, indentation=0): +def print_tree(tree, indentation=0, headline=None): + # if headline and headline.id != INDEX_ID: + # return return for element in tree: - print(" " * indentation + "- " + str(type(element))) if "children" in dir(element): if len(element.children) > 0: - print_tree(element.children, indentation + 1) + print_element(element.children, indentation + 1, headline) print() + elif "content" in dir(element): + for content in element.content: + print_element(content, indentation + 1, headline) + +def print_element(element, indentation, headline): + if isinstance(element, org_rw.Link): + print(" " * indentation, "Link:", element.get_raw()) + elif isinstance(element, str): + print(" " * indentation, "{" + element + "}", type(element)) + else: + print_tree(element, indentation, headline) + def render_property_drawer(element, acc): pass @@ -334,7 +347,7 @@ def render(headline, doc, headlineLevel): except: logging.error("Error generating DOM for {}".format(doc.path)) raise - print_tree(dom) + print_tree(dom, indentation=2, headline=headline) content = [] render_tree(dom, content)