em tags in imported image paths
PretzelVector opened this issue · 2 comments
PretzelVector commented
Hello,
trilium-py has been invaluable. Thank you for all your work.
I am using trilium-py version 0.8.2.
After importing an obsidian vault using obsidian-export
and importing it using upload_md_folder
, I ended up with a series of images that had the underscores replaced with em tags. For example: 2023_abandoned_canyon.png
becomes 2023<em>abandoned</em>canyon.png
.
Below is a simple python script to fix entries that have been corrupted in that way that worked for me™️ and provides a workaround for the issue.
res = ea.search_note("</em>")
for r in res['results']:
if r["type"] == "image" and "</em>" in r['title']:
orig_title = r['title']
new_title = orig_title.replace("<em>", "_").replace("</em>", "_")
ea.patch_note(r['noteId'], title=new_title)
print(f" [!] {orig_title} -> {new_title}")
for n in r['parentNoteIds']:
id = n
n = ea.get_note(id)
print(f" [ ] - {n['title']}")
c = ea.get_note_content(id)
c = c.replace(orig_title, new_title)
ea.update_note_content(id, c)
print(" [-] Fixed")
Nriver commented
Interesting, it looks like markdown2 converted
![1_1_2](1_1_2.png)
to
<p><img src="1_1_2.png" alt="1<em>1</em>2" /></p>
Nriver commented
I've found a solution from a issue about 10 years ago. trentm/python-markdown2#158
This should be fixed by now.