Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with certain images when importing .md #34

Closed
alglez opened this issue Feb 12, 2024 · 5 comments
Closed

Problem with certain images when importing .md #34

alglez opened this issue Feb 12, 2024 · 5 comments

Comments

@alglez
Copy link

alglez commented Feb 12, 2024

There are certain images that are not recognized correctly when importing markdown files.

<p><img width="736" height="414" src="../certainpath.jpg"/></p>

that is due to the fact that the regex expression in

pat = '<img (.*?) />'
is expecting a white space just before "/>". And that is not always the case (even with though all the code is generated by markdown2markdown.

the simplest solution is to change that line to:

pat = '<img (.*?)/>'
But i'm not sure that that change could generate problems with other images (not that i can think of)

@Nriver
Copy link
Owner

Nriver commented Feb 13, 2024

I think your solution can solve this issue.

I'm interested in how the data becomes without space. Cause I can see that space in many other softwares. Could you provide more details like the sample data and the code/software you use?

@alglez
Copy link
Author

alglez commented Feb 13, 2024

Hi,

I was using trilium_py to import md files from joplin. While testing I realize that some images were not uploaded correctly. Those md are directly joplin generated. So i check the Html file generated by markdown2.markdown and realize that the imgs in question are not detected because based on the regex expression there is a missing white space.

I decided to create an small md example and attach it. In the first example all the images are correctly rendered (but it's not because is detecting all the images, but because all the images are pointing to the same file) in the exampleTwo.md, "example 2" and "example 3" are not imported correctly because those are not detected by the regex expression.
examplemd.zip

this:

[<img width="400" height="262" src="./calvin_hobbes-2.jpg"/>](https://news.artnet.com/app/news-upload/2015/01/CalvinHobbes1.jpg)

it's translated to this in html:

<p><a href="https://news.artnet.com/app/news-upload/2015/01/CalvinHobbes1.jpg"><img width="400" height="262" src="./calvin_hobbes-2.jpg"/></a></p>

and this:

<img width="400" height="262" src="./calvin_hobbes-3.jpg"/>

is translated to this:

<p><img width="400" height="262" src="./calvin_hobbes-3.jpg"/></p>

But if you can test the exampleTwo.md let me know if you experience the same problem.

`
Name: trilium-py
Version: 0.8.6

Name: markdown2
Version: 2.4.12

python version: 3.11.6`

@Nriver
Copy link
Owner

Nriver commented Feb 14, 2024

Hi, thank you for providing the detailed reproduction process and examples. I see you've made several test examples, that could really help.

But I'm on vacation now, and do not have a computer at hand. I will have a good look at this once I come back.

@Nriver
Copy link
Owner

Nriver commented Feb 20, 2024

I've just applied the fix and published a new version.

@alglez
Copy link
Author

alglez commented Feb 23, 2024

Perfect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants