Preprocessor to embed markdown images#1067
Conversation
|
Just to be explicit, looks like this only embeds MD referenced images. HTML embedding still needs to be done. Glad to see the progress though :D |
|
For some reason, I cant get attachments working with my jupyter nb (v5.0.0), so I can't test some things. Is it possible to refer to an attachment in the html? E.g.: if so that makes embedded images actually very nice to deal with in MD cells, and gives full html control over display. |
|
Attachments only work with markdown images. If you use base64 images in html So it will need to be a 2 step solution:
|
Thanks, this is an important detail. When does this happen? Upon render and kernel startup? This PR #1067 helps to embed MD images -- the What I am looking to achieve is:
It seems like step one is not possible for html base64 because of sanitization, which means step 2 will fail. Is the only option to re-implement the |
|
I believe you need a new exporter to embed images and convert to slides. Maybe @mpacer can share his thoughts what a good approach would be ? |
|
@juhasch Could you please have a look at my branch (where I tried to use your preprocessor inside embed_html) it is called but somehow does not work, key error in self.attachements, do you know why? |
|
Actually, all you need to do is copy the html_embed exporter and replace the base class: And instantiate your exporter in the Now, what I don't like is that we now have the code for embedding twice, so we should find a solution for that. You don't need the preprocessor. It is useful if you want to stay in higher-level formats, i.e. notebook to notebook conversion. |
|
Bugfix:
|
| Embedding images in notebooks | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| .. autoclass:: EmbedPreprocessor |
There was a problem hiding this comment.
I think this should be EmbedImagesPreprocessor, no?
There was a problem hiding this comment.
Would say so too, its more explicit :-)
There was a problem hiding this comment.
its more explicit
but more importantly, at the moment I don't think EmbedPreprocessor is an extant class, so I don't think it'll produce anything at all...
|
So where is this sat, at the moment? @gabyx are you saying there's a bug in the current implementation? Can you give a little more explanation as to what that is, and maybe an example of how to trigger it? |
| else: | ||
| return match.string | ||
| elif url.startswith('attachment'): | ||
| return match.string |
There was a problem hiding this comment.
[asd](attachement:asd.jpg) # this comment...
will result here in
[asd](attachement:asd.jpg) # this comment... # this comment...
it should be match.group(0)
There was a problem hiding this comment.
match.string is not what should be returned if we do not want to substitute... (no?)
match.string is the string passed to match/search... https://docs.python.org/3/library/re.html#re.match.string
| if self.embed_remote_images: | ||
| data = urlopen(url).read() | ||
| else: | ||
| return match.string |
|
Images in markdown
will be added as attachments to the cell.TODO