Nriver / trilium-py

Python client for ETAPI of Trilium Note. Trilium 的 Python版 ETAPI 客户端
GNU Affero General Public License v3.0
118 stars 27 forks source link

em tags in imported image paths #23

Closed PretzelVector closed 1 year ago

PretzelVector commented 1 year ago

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 1 year ago

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 1 year ago

I've found a solution from a issue about 10 years ago. https://github.com/trentm/python-markdown2/issues/158

This should be fixed by now.