From 47a4fd67d6d3826ce33c7db06dadea6cac1b217c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20D=C3=B6rfelt?= Date: Thu, 19 Sep 2024 18:30:42 +0200 Subject: [PATCH] tomboy-ng/gnote: add internal links --- src/formats/tomboy_ng.py | 29 +++++++++++++++++++---------- test/example_commands.sh | 1 + 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/formats/tomboy_ng.py b/src/formats/tomboy_ng.py index 6f85f65..5e1881e 100644 --- a/src/formats/tomboy_ng.py +++ b/src/formats/tomboy_ng.py @@ -15,12 +15,17 @@ class Converter(converter.BaseConverter): def parse_content(self, node): # TODO # pylint: disable=too-many-branches + note_links = [] # https://stackoverflow.com/a/26870728 md_content = [node.text] if node.text is not None else [] for child_index, child in enumerate(node): # match case doesn't work with fstrings - if child.tag.endswith("bold"): + if ( + child.tag.endswith("bold") + or child.tag.endswith("large") + or child.tag.endswith("huge") + ): md_content.append(f"**{child.text}**") elif child.tag.endswith("highlight"): md_content.append(child.text) # TODO @@ -40,19 +45,21 @@ def parse_content(self, node): if child_index != 0: # Don't put note title again in the note body. md_content.append(f"++{child.text}++") - elif ( - child.tag.endswith("small") - or child.tag.endswith("large") - or child.tag.endswith("huge") - ): - md_content.append(child.text) # TODO + elif child.tag.endswith("small"): + md_content.append(child.text) # TODO: How to handle? + elif child.tag.endswith("internal"): + # Just some arbitrary format. It gets replaced later. + md_content.append(f"[[{child.text}]]") + note_links.append( + imf.NoteLink(f"[[{child.text}]]", child.text, child.text) + ) else: self.logger.warning(f"ignoring tag {child.tag}") if child.tail is not None: md_content.append(child.tail) if node.tail is not None: md_content.append(node.tail) - return "".join(md_content).strip() + return "".join(md_content).strip(), note_links def convert_note(self, note_file: Path): # Format: https://wiki.gnome.org/Apps/Tomboy/NoteXmlFormat @@ -73,7 +80,7 @@ def convert_note(self, note_file: Path): return # ignore templates content = root_node.find("{*}text/{*}note-content") - body = self.parse_content(content) + body, note_links = self.parse_content(content) if ( note_title := root_node.find("{*}title") @@ -81,7 +88,9 @@ def convert_note(self, note_file: Path): title = note_title.text else: title = body.split("\n", 1)[0] - note_imf = imf.Note(title, body, tags=[imf.Tag(tag) for tag in tags]) + note_imf = imf.Note( + title, body, tags=[imf.Tag(tag) for tag in tags], note_links=note_links + ) if (date_ := root_node.find("{*}create-date")) is not None: note_imf.created = dt.datetime.fromisoformat(str(date_.text)) if (date_ := root_node.find("{*}last-change-date")) is not None: diff --git a/test/example_commands.sh b/test/example_commands.sh index 3a69063..135438a 100755 --- a/test/example_commands.sh +++ b/test/example_commands.sh @@ -40,6 +40,7 @@ $EXECUTABLE "$CACHE/textbundle/example.textpack" --format textbundle $EXECUTABLE "$CACHE/tiddlywiki/tiddlyhost.json" --format tiddlywiki # $EXECUTABLE "$CACHE/todo_txt/examples_from_readme.txt" --format todo_txt # $EXECUTABLE "$CACHE/todoist/Privates.csv" --format todoist +$EXECUTABLE "$CACHE/tomboy_ng/gnote/" --format tomboy_ng $EXECUTABLE "$CACHE/tomboy_ng/tomboy-ng/" --format tomboy_ng # $EXECUTABLE "$CACHE/toodledo/toodledo_completed_240427.csv" --format toodledo # $EXECUTABLE "$CACHE/toodledo/toodledo_current_240427.csv" --format toodledo