Skip to content

Commit

Permalink
joplin testing
Browse files Browse the repository at this point in the history
  • Loading branch information
djsudduth committed Jul 13, 2023
1 parent 8124f81 commit fc08f84
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
settings.cfg
settings*.cfg
skiptest.py
fuzzy.py
zz*.py
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ Notes will import into Logseq similar to the Obsidian Use description, however,
KIM markdown note exports seem to import into Notion successfully. However, Notion STILL fails to import linked image attachments (which seems to be a general Notion md import problem at this time). Notion also ties underlying ids to any cross-linked notes so that there is no automated cross-linking when importing (future feature). Also, tags are not supported in Notion so Keep labels will just be text hashtags within the note which are searchable.

## Joplin Use
KIM markdown note exports also import very well into Joplin. Most markdown types in Keep notes should convert successfully even if Keep cannot render them. However, wikilinks and tags are not supported in Joplin's manual markdown import so Keep labels will just be text hashtags within the note which are searchable.
KIM markdown note exports also import very well into Joplin. Using the -j flag will add Keep labels as Joplin front matter to add them as tags. Most markdown types in Keep notes should convert successfully even if Keep cannot render them. However, wikilinks are not supported in Joplin's manual markdown import.

## Typora Use
KIM tries to adhere to strict markdown to be as compatible as possible. No issues have been discovered using Typora on KIM markdown exports.
Expand Down
36 changes: 20 additions & 16 deletions kim.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
OUTPUTPATH = 'mdfiles'
MEDIADEFAULTPATH = "media"
INPUTDEFAULTPATH = "import/markdown_files"
DEFAULTLABELS = "my_label"
DEFAULT_LABELS = "my_label"
DEFAULT_SEPARATOR = "/"
MAX_FILENAME_LENGTH = 99
MISSING = 'null value'

Expand Down Expand Up @@ -54,7 +55,8 @@
'output_path': OUTPUTPATH,
'media_path': MEDIADEFAULTPATH,
'input_path': INPUTDEFAULTPATH,
'input_labels': DEFAULTLABELS
'input_labels': DEFAULT_LABELS,
'folder_separator': DEFAULT_SEPARATOR
}


Expand Down Expand Up @@ -83,6 +85,7 @@ class Note:
blobs: list
blob_names: list
media: list
header: str



Expand Down Expand Up @@ -179,12 +182,12 @@ def format_check_boxes(text):
return(text.replace(u"\u2610", '- [ ]').replace(u"\u2611", ' - [x]'))

@staticmethod
def format_path(path, name, media):
def format_path(path, name, media, replacement):
if media:
header = "!["
else:
header = "["
path = path.replace(" ", "%20")
path = path.replace(" ", replacement)
if name:
return (header + name + "](" + path + ")")
else:
Expand Down Expand Up @@ -410,7 +413,7 @@ def save_md_file(note, note_tags, note_date, overwrite, skip_existing):

for media in note.media:
md_text = Markdown().format_path(Config().get("media_path") +
"/" + media, "", True) + "\n" + md_text
"/" + media, "", True, "_") + "\n" + md_text


md_file = Path(fs.outpath(), note.title + ".md")
Expand All @@ -436,10 +439,11 @@ def save_md_file(note, note_tags, note_date, overwrite, skip_existing):
[ : note.timestamps["updated"].rfind('.') ] + "\n\n")

markdown_data = (
note.header +
Markdown().convert_urls(md_text) + "\n" +
"\n" + note_tags + "\n\n" +
timestamps +
Markdown().format_path(KEEP_NOTE_URL + str(note.id), "", False) + "\n\n")
Markdown().format_path(KEEP_NOTE_URL + str(note.id), "", False, "%20") + "\n\n")

fs.write_file(md_file, markdown_data)
return (1)
Expand Down Expand Up @@ -474,7 +478,7 @@ def keep_import_notes(keep):
def keep_get_blobs(keep, note):
fs = FileService()
for idx, blob in enumerate(note.blobs):
note.blob_names[idx] = note.title + str(idx)
note.blob_names[idx] = note.title.replace(" ", "_") + str(idx)
if blob != None:
url = keep.getmedia(blob)
blob_file = None
Expand Down Expand Up @@ -511,12 +515,13 @@ def keep_query_convert(keep, keepquery, opts):
gnote.text,
gnote.archived,
gnote.trashed,
{"created": str(gnote.timestamps.created),
{"created": str(gnote.timestamps.created),
"updated": str(gnote.timestamps.updated)},
[str(label) for label in gnote.labels.all()],
[blob for blob in gnote.blobs],
['' for blob in gnote.blobs],
[]
[],
""
)
)

Expand All @@ -533,8 +538,7 @@ def keep_query_convert(keep, keepquery, opts):
else:
note.title = note_date

note.title = re.sub('[' + re.escape(''.join(ILLEGAL_FILE_CHARS)) + ']', ' ', note.title[0:99]) #re.sub('[^A-z0-9-]', ' ', gnote.title)[0:99]
#note_text = gnote.text #gnote.text.replace('”','"').replace('“','"').replace("‘","'").replace("’","'").replace('•', "-").replace(u"\u2610", '[ ]').replace(u"\u2611", '[x]').replace(u'\xa0', u' ').replace(u'\u2013', '--').replace(u'\u2014', '--').replace(u'\u2026', '...').replace(u'\u00b1', '+/-')
note.title = re.sub('[' + re.escape(''.join(ILLEGAL_FILE_CHARS)) + ']', ' ', note.title[0:99])

labels = note.labels
note_labels = ""
Expand All @@ -545,7 +549,7 @@ def keep_query_convert(keep, keepquery, opts):
for label in labels:
note_labels = note_labels + " #" + str(label).replace(' ', '-').replace('&', 'and')
note_labels = re.sub('[' + re.escape(''.join(ILLEGAL_TAG_CHARS)) +
']', '-', note_labels) #re.sub('[^A-z0-9-_# ]', '-', note_labels)
']', '-', note_labels)

if opts.logseq_style:
c = note.text[:1]
Expand All @@ -556,13 +560,13 @@ def keep_query_convert(keep, keepquery, opts):

if opts.joplin_frontmatter:
joplin_labels = ""
for label in note.labels:
for label in note_labels.replace("#", "").split():
joplin_labels += " - " + label + "\n"
note.text = ("---\ntitle: " + note.title +
note.header = ("---\ntitle: " + note.title +
"\nupdated: " + note.timestamps["updated"] +
"Z\ncreated: " + note.timestamps["created"] +
"Z\ntags:\n" + joplin_labels +
"---\n\n" + note.text)
"---\n\n")
note_labels = ""
note.timestamps = {}

Expand Down Expand Up @@ -701,7 +705,7 @@ def main(r, o, a, p, s, c, l, j, i, search_term, master_token):

try:

l = True
#j = True
opts = Options(o, a, p, s, c, l, j, i)
click.echo("\r\nWelcome to Keep it Markdown or KIM!\r\n")

Expand Down

0 comments on commit fc08f84

Please sign in to comment.