diff --git a/config.example.ini b/config.example.ini index e616169..5536fba 100644 --- a/config.example.ini +++ b/config.example.ini @@ -7,3 +7,4 @@ import_media=true [notion] token=Copy it from Notion cookies: token_v2 root_url=https://www.notion.so/PAGE-ID Create a root url in your Notion +merge_paragraphs=False \ No newline at end of file diff --git a/gkeep2notion.py b/gkeep2notion.py index e3d23a8..e14d9cd 100755 --- a/gkeep2notion.py +++ b/gkeep2notion.py @@ -86,7 +86,7 @@ def add_chunk(self, text: str, url: str = ''): self._chunks.append({ "type": "text", "text": { - "content": text + "content": text } }) @@ -180,6 +180,7 @@ def __init__(self, ini: ConfigParser): self.import_media = ini['gkeep']['import_media'].lower() == 'true' self.token = ini['notion']['token'] self.root_url = ini['notion']['root_url'] + self.merge_paragraphs = ini['notion']['merge_paragraphs'] def get_config(path='config.ini') -> Config: @@ -262,12 +263,26 @@ def parseBlock(p: str) -> dict: } -def parseTextToPage(text: str, page: Page): +def parseTextToPage(text: str, page: Page, config: Config): lines = text.splitlines() + lines.insert(len(lines), '') + last_block = None print(f"Parsing {len(lines)} blocks") - for p in lines: + for x in range(0, len(lines)): + p = lines[x] block = parseBlock(p) - page.add_text(block['text'], block['type']) + if not config.merge_paragraphs: + page.add_text(block['text'], block['type']) + continue + if last_block: + if last_block['type'] == BlockType.Paragraph and last_block['type'] == block['type'] and len( + last_block['text']) + len(block['text']) < 2000: + last_block['text'] += "\n" + block['text'] + if x < len(lines) - 1: + continue + page.add_text(last_block['text'], last_block['type']) + last_block = block + def getNoteCategories(note: node.TopLevelNode) -> list[str]: @@ -331,7 +346,7 @@ def parseNote(note: node.TopLevelNode, page: Page, keep: Keep, config: Config): # Text text = note.text # Render page blocks - parseTextToPage(text, page) + parseTextToPage(text, page, config) def parseList(list: node.List, page: Page):