Skip to content

Commit

Permalink
Add path when reading images
Browse files Browse the repository at this point in the history
  • Loading branch information
Jürgen Hasch committed Aug 12, 2017
1 parent b6531c2 commit b5e3a98
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
from nbconvert.exporters.html import HTMLExporter
from ipython_genutils.ipstruct import Struct
import os

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

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

self.path = resources['metadata']['path']
self.attachments = Struct()
for cell in nb.cells:
if 'attachments' in cell.keys():
Expand Down

0 comments on commit b5e3a98

Please sign in to comment.