From bbdd863df043e6332a6f63720a744ca44681ae5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?benjamin=20melan=C3=A7on?= Date: Sun, 23 Jun 2024 23:50:33 -0400 Subject: [PATCH 1/2] Just go all out making it work for us --- zimwiki_txt_to_logseq_md.py | 39 ++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/zimwiki_txt_to_logseq_md.py b/zimwiki_txt_to_logseq_md.py index 21c081a..6056f3a 100644 --- a/zimwiki_txt_to_logseq_md.py +++ b/zimwiki_txt_to_logseq_md.py @@ -3,8 +3,10 @@ import os def rewrite_file(filepath): with open(filepath, 'r') as f: base = filepath[:-4] + base = base.replace("_", " ").strip() newfilepath = base + ".md" with open(newfilepath, 'w') as w: + in_block = False for i, line in enumerate(f): if ( (i == 0 and line == "Content-Type: text/x-zim-wiki\n") or (i == 1 and line == "Wiki-Format: zim 0.26\n") @@ -17,10 +19,41 @@ def rewrite_file(filepath): title_pieces = line.split("======") if len(title_pieces) == 3: title = title_pieces[1].strip() - w.write("---\n") - w.write("title: " + title + "\n") - w.write("---\n") + # If the filename is the same as the title, do not add + # the custom property. (If either this custom property + # or the 'actual' title is touched after import, Logseq + # will change the filename to that and the custom title + # becomes an out-of-date inactive property.) We set it + # if different because the initial import does use it! + if (title == base): + continue + w.write("title:: " + title + "\n") + w.write("\n") continue + if (i > 5 and line == "\"\"\"\n"): + if (in_block == False): + in_block = True + else: + in_block = False + continue + if (i > 5 and in_block == False): + test = line.strip() + if (test == ""): + continue + prefix = "" + temp = line.lstrip() + if (temp[0:2] == "* " or temp[0:2] == "- "): + temp = temp[2:] + prefix = prefix + "\t" + elif (line[0:1] == "\t" or line[0:2] == " "): + # If the source file has two indents without first + # having a single indent, Logseq does not blink, so we + # do two indents if we think it *might* be warranted + # without fear. + prefix = prefix + "\t" + if (line[0:2] == "\t\t" or line[0:4] == " "): + prefix = prefix + "\t" + line = prefix + "- " + temp w.write(line) From 6c5772ab9d60be5edbe7d39e2e7d85638f9cb06e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?benjamin=20melan=C3=A7on?= Date: Mon, 24 Jun 2024 09:46:14 -0400 Subject: [PATCH 2/2] Tweak how quotations work so we keep our old markers --- zimwiki_txt_to_logseq_md.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/zimwiki_txt_to_logseq_md.py b/zimwiki_txt_to_logseq_md.py index 6056f3a..cd90fe3 100644 --- a/zimwiki_txt_to_logseq_md.py +++ b/zimwiki_txt_to_logseq_md.py @@ -35,8 +35,10 @@ def rewrite_file(filepath): in_block = True else: in_block = False - continue - if (i > 5 and in_block == False): + # Close our self-styled quotation block without a bullet. + w.write(line) + continue + elif (i > 5 and in_block == False): test = line.strip() if (test == ""): continue