MyST-NB icon indicating copy to clipboard operation
MyST-NB copied to clipboard

Deal with attachments in Markdown cells

Open mtrbean opened this issue 5 years ago • 9 comments

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:

![Example Set 1](attachment:55e982a2-ff6d-4b22-ab40-ae563e0fb0a3.png)

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

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

mtrbean avatar Aug 13 '20 23:08 mtrbean

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:

welcome[bot] avatar Aug 13 '20 23:08 welcome[bot]

heya @mtrbean no IIRC we do not currently deal with attachments, I'm going to move this issue to myst-nb

chrisjsewell avatar Aug 13 '20 23:08 chrisjsewell

Hey Eric, I found this issue when I were dealing other attachment problems :-) Maybe change png file inclusion code to the following?

![Example Set 1](55e982a2-ff6d-4b22-ab40-ae563e0fb0a3.png)

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 avatar Aug 16 '20 07:08 ajz34

@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.

mtrbean avatar Aug 18 '20 22:08 mtrbean

Has anyone found a fix for this yet?

jaymefosa avatar Aug 27 '20 12:08 jaymefosa

not just yet I'm afraid, requires a number of changes:

  1. The attachments need to be extracted from the notebook, into the build folder
  2. ensure links with the attachments: prefix are not treated as external links (URLs)
  3. Add some form of transform/logic to tie the reference to the file

It do-able, but not trivial

chrisjsewell avatar Aug 27 '20 12:08 chrisjsewell

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

jaymefosa avatar Aug 27 '20 12:08 jaymefosa

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 😄

chrisjsewell avatar Aug 27 '20 13:08 chrisjsewell

2\. attachments:

Would this examples help?

  • https://gist.github.com/sglyon/5687b8455a0107afc6f4c60b5f313670
  • https://github.com/jupyter/nbconvert/issues/699#issuecomment-372441219

sherdim avatar May 28 '21 19:05 sherdim