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

Can't insert picture #12

Open
rhymer opened this issue Jun 27, 2019 · 6 comments
Open

Can't insert picture #12

rhymer opened this issue Jun 27, 2019 · 6 comments

Comments

@rhymer
Copy link

rhymer commented Jun 27, 2019

I wonder if picture is supported? Neither ![name](some.png) nor attach picture (F3) works. Thanks.

@gregorrr
Copy link
Owner

Hey,

The add-on assumes that all content is text so the markdown image syntax should work. Does the following work for you:
![](https://upload.wikimedia.org/wikipedia/commons/7/70/Example.png)

However perhaps using copy + paste/attach image is required to add the image to collection.media? In which case you can use Edit Html (or Ctrl + Shift + X) after attaching the image to get the filename and use that where appropriate.

I know it's an annoying extra step and hopefully I'll get around to improving it at some point.

@rhymer
Copy link
Author

rhymer commented Jun 28, 2019

Thanks for your reply.

  1. Can confirm that ![](url) works. Didn't work for local images though. Tried file:///C:/... and other combinations, none works.
  2. Can also confirm the two-step method works. After copy and paste the image, ![](image.png) works. Like you said, the key is to have image.png added to collection.media.

Is it possible to add the conversion of <img src="image.png"><br> to ![](image.png) before parsing the text? That way copy-and-paste an image will work in 1 step.

@gregorrr
Copy link
Owner

gregorrr commented Jun 30, 2019

The way that the add-on works currently is to look at the innerText property of the field so there are no tags present, just text.

The copy and paste functionality could probably be modified to insert the html entities such as &lt;img src etc. so that they're present in the ìnnerText. That's an option, however, it does mean that you wouldn't get the image preview when editing the note.

Apart from basic stuff like changing <br> to \n, I'm not particularly keen on doing any HTML to markdown conversion. Mostly due to the potential work involved but also because Markdown is allowed to contain HTML.

Another option is to look at the innerHTML property. This would a hybrid of Markdown and HTML and would lead to some inconsistencies in the editor view. For example, one could have some text displaying bold from using the editor's bold button, but other text **not displaying bold** until the Markdown is processed:

multiple-ways-bold

Any thoughts?

@suvernev-d
Copy link

I'm using this addon for batch importing Markdown notes, and think that additional converting of HTML can do more harm than good.

For now, it's just about following two principles:

  1. Use ![desc]('url') for images on the web
  2. Copy any needed local images to your collection.media folder with an underscore, then reference them as ![desc]('_img.jpg') or something.

Let the plugin do it's job, and do not mix it with Anki's built-in editor, which tries to manipulate HTML.

@multimeric
Copy link

I think parsing innerHTML might be okay? It would allow users to add elements with the normal anki inputs (formatting, images etc), and then the whole chunk of HTML is parsed as markdown. I think this is fairly safe specifically because markdown can contain HTML - I expect the parser you're using should be fine with this.

Would you like a PR for this feature?

@edap
Copy link

edap commented Dec 27, 2021

Hey, many thanks for this addon. I have some problem with images, I have my image in the collection media folder, I have tried referencing it with ![desc]('_webgl-triangle-pipeline.svg') and ![desc]('webgl-triangle-pipeline.svg'), none of them worked.

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

5 participants