drivendataorg / nbautoexport

Automatically export Jupyter notebooks to various file formats (.py, .html, and more) on save.
https://nbautoexport.drivendata.org/
MIT License
72 stars 9 forks source link

Referencing images with markdown not carried over in output #73

Open adfi opened 3 years ago

adfi commented 3 years ago

I have a jupyter notebook and I have an image together in the same folder. I then inserted the image into the notebook using markdown i.e. ![png](image.png). This displays fine within the notebook.

When running nbautoexport to export the notebook to markdown the result is placed in a separate folder called markdown. However the path to the image stays the same which causes it to not be displayed. Is there a way to update the path such that it points to the original file?

There is a workaround which involves displaying the image using code. The image then does get copied over to the markdown folder.

What is your preferred use? Should we not use markdown to insert images?

pjbull commented 3 years ago

@adfi A few options that are workarounds: (1) You could use absolute paths (local only, so maybe not that useful) (2) You could edit jupyter_notebook_config.py to customize the save function like we do to also copy the files you reference in markdown separately to the markdown folder.

A couple options for us to better support this scenario: (3) Would it work for you if the markdown and the original notebook just lived in the same folder? That the relative links to resources would be the same. We could provide an organize_by option that does not place the output in a subfolder. (4) Would it work for you to specify a folder in .nbautoexport of assets to be copied to the subfolder? That's another possible implementation on our end.

adfi commented 3 years ago

Thanks for your reply.

(1) As you say this one isn't what we're looking for (2) I don't really know how to customize the save function, if you have an example that would be helpful.

(3) That would be helpful in general (4) This would be a good backup in case (3) doesn't work

pjbull commented 3 years ago

Awesome, we'd definitely take a PR for 3, which should be easy. Here's the relevant code block: https://github.com/drivendataorg/nbautoexport/blob/3e9a1ed2e15e5089e3f2b20a849f26513a77ff05/nbautoexport/export.py#L99-L102

To implement it, we'd need a few things:

adfi commented 3 years ago

Thanks for the guidance, I'll try to work on it this week.