From b6531c27793c5264465755a982b3167b5d959a5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ju=CC=88rgen=20Hasch?= Date: Sat, 12 Aug 2017 16:00:22 +0200 Subject: [PATCH 1/2] Fix html_embed exporter --- .../nbconvert_support/embedhtml.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/jupyter_contrib_nbextensions/nbconvert_support/embedhtml.py b/src/jupyter_contrib_nbextensions/nbconvert_support/embedhtml.py index 23b5f51b3..2c4bc2689 100644 --- a/src/jupyter_contrib_nbextensions/nbconvert_support/embedhtml.py +++ b/src/jupyter_contrib_nbextensions/nbconvert_support/embedhtml.py @@ -3,6 +3,7 @@ import base64 import re from nbconvert.exporters.html import HTMLExporter +from ipython_genutils.ipstruct import Struct try: from urllib.request import urlopen # py3 @@ -31,6 +32,17 @@ def replfunc(self, match): elif url.startswith('data'): img = ' Date: Sat, 12 Aug 2017 17:53:04 +0200 Subject: [PATCH 2/2] Add path when reading images --- .../nbconvert_support/embedhtml.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/jupyter_contrib_nbextensions/nbconvert_support/embedhtml.py b/src/jupyter_contrib_nbextensions/nbconvert_support/embedhtml.py index 2c4bc2689..4e16255fa 100644 --- a/src/jupyter_contrib_nbextensions/nbconvert_support/embedhtml.py +++ b/src/jupyter_contrib_nbextensions/nbconvert_support/embedhtml.py @@ -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 @@ -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)) @@ -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():