Skip to content

Commit b5e3a98

Browse files
author
Jürgen Hasch
committed
Add path when reading images
1 parent b6531c2 commit b5e3a98

File tree

1 file changed

+4
-1
lines changed
  • src/jupyter_contrib_nbextensions/nbconvert_support

1 file changed

+4
-1
lines changed

src/jupyter_contrib_nbextensions/nbconvert_support/embedhtml.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import re
55
from nbconvert.exporters.html import HTMLExporter
66
from ipython_genutils.ipstruct import Struct
7+
import os
78

89
try:
910
from urllib.request import urlopen # py3
@@ -44,7 +45,8 @@ def replfunc(self, match):
4445
return img
4546
raise ValueError('Could not find attachment for image "%s" in notebook' % imgname)
4647
else:
47-
with open(url, 'rb') as f:
48+
filename = os.path.join(self.path, url)
49+
with open(filename, 'rb') as f:
4850
data = f.read()
4951

5052
self.log.info("embedding url: %s, format: %s" % (url, imgformat))
@@ -64,6 +66,7 @@ def from_notebook_node(self, nb, resources=None, **kw):
6466
output, resources = super(
6567
EmbedHTMLExporter, self).from_notebook_node(nb, resources)
6668

69+
self.path = resources['metadata']['path']
6770
self.attachments = Struct()
6871
for cell in nb.cells:
6972
if 'attachments' in cell.keys():

0 commit comments

Comments
 (0)