Deal with attachments in Markdown cells
Attachment image not showing up when writing content with jupyter notebook
This was originally reported in https://github.com/executablebooks/jupyter-book/issues/321. Apparently it was working back then but I couldn't get it working with the latest version of jupyter-book.
(The attachment is showing correctly if I generate an html directly using nbconvert jupyter nbconvert mynotebook.ipynb)
To Reproduce
Include an attachment in a markdown cell in a jupyter notebook, for example by pasting an image directly into the cell:

and then build the project. Opening in browser will see a broken image:

Expected behavior
image is displayed in the html
Environment
- Python: 3.7.6
- jupyter-book: 0.7.4
- nbconvert: 5.6.1
- Operating System: linux
Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.
If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).
Welcome to the EBP community! :tada:
heya @mtrbean no IIRC we do not currently deal with attachments, I'm going to move this issue to myst-nb
Hey Eric, I found this issue when I were dealing other attachment problems :-) Maybe change png file inclusion code to the following?

i.e. attachment: may not be included. Otherwise warning info may come (The warning info comes from my project):
WARNING: image file not readable: Project_01/attachment:assets/acetaldehyde.png
@ajz34 The warning does go away by removing attachment:, however it still results in a broken image in the browser. In fact it thinks that 55e982a2-ff6d-4b22-ab40-ae563e0fb0a3.png exists as an asset in the same relative location as the html document. I think when ipynb files are parsed and attachments are encountered, they should should be exported as an actual file like matplotlib chart in cell outputs.
Has anyone found a fix for this yet?
not just yet I'm afraid, requires a number of changes:
- The attachments need to be extracted from the notebook, into the build folder
- ensure links with the
attachments:prefix are not treated as external links (URLs) - Add some form of transform/logic to tie the reference to the file
It do-able, but not trivial
Alright thanks for the update.
I'd just like to add that videos opened using:
from IPython.display import Video
Video("test.mp4")
Also aren't moved to the build content
Also aren't moved to the build content
That is because the video is not actually stored in the notebook like other media:
"outputs": [
{
"data": {
"text/html": [
"<video src=\"file_example_MP4_480_1_5MG.mp4\" controls >\n",
" Your browser does not support the <code>video</code> element.\n",
" </video>"
],
"text/plain": [
"<IPython.core.display.Video object>"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
You would have to somehow know to look for videos in html, parse it to get the path, etc. Thats is really not trivial lol 😬
But yeh we are always happy to accept PRs If anyone wants to give it a go 😄
2\. attachments:
Would this examples help?
- https://gist.github.com/sglyon/5687b8455a0107afc6f4c60b5f313670
- https://github.com/jupyter/nbconvert/issues/699#issuecomment-372441219