Skip to content

Commit

Permalink
tomboy-ng/gnote: add internal links
Browse files Browse the repository at this point in the history
  • Loading branch information
marph91 committed Sep 19, 2024
1 parent b6439a2 commit 47a4fd6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/formats/tomboy_ng.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -73,15 +80,17 @@ 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")
) is not None and note_title.text is not None:
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:
Expand Down
1 change: 1 addition & 0 deletions test/example_commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 47a4fd6

Please sign in to comment.