From 1a0e3a8bb67db3b0d2508ea7fc81eb36c293d6e0 Mon Sep 17 00:00:00 2001 From: Sean Dockray Date: Sun, 7 Jun 2020 00:08:12 +1000 Subject: [PATCH] handle nested lists --- custom_syadmin/build_from_notion.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/custom_syadmin/build_from_notion.py b/custom_syadmin/build_from_notion.py index 42e73c6..0c90ac6 100644 --- a/custom_syadmin/build_from_notion.py +++ b/custom_syadmin/build_from_notion.py @@ -94,7 +94,7 @@ def hugo(hugo_site_path, dest, hugo_environment='gitea', base_url=None): hugo_output = cmd([HUGO_PATH, '-e', hugo_environment, '-d', dest, '--noTimes'], cwd=hugo_site_path, env=env) -def get_record_text(post): +def get_record_text(post, level=0): """ Generates the markdown text of a Notion page see: # https://github.com/brentbaum/brentbaum-notion-publishing/blob/master/notion/get_posts.py """ text = "" @@ -111,10 +111,15 @@ def get_record_text(post): text += f"![{caption}]({child.source})\n" elif child.type == "divider": text += "---" + elif child.type == "bulleted_list": + prefix = prefixes.get(child.type, "") + text += ' ' * (level * 4) + prefix + child.title.encode('utf-8').decode('utf-8') + "\n\n" + if len(child.children): + text += get_record_text(child, level + 1) else: prefix = prefixes.get(child.type, "") text += prefix + child.title.encode('utf-8').decode('utf-8') + "\n\n" - + text = re.sub('`bib:([a-zA-Z0-9-]+)`', r'![](bib:\1)', text) return text