|
@@ -53,27 +53,51 @@ from .mdx_liquid_tags import LiquidTags
|
|
import IPython
|
|
import IPython
|
|
IPYTHON_VERSION = IPython.version_info[0]
|
|
IPYTHON_VERSION = IPython.version_info[0]
|
|
|
|
|
|
|
|
+try:
|
|
|
|
+ import nbformat
|
|
|
|
+except:
|
|
|
|
+ pass
|
|
|
|
+
|
|
if not IPYTHON_VERSION >= 1:
|
|
if not IPYTHON_VERSION >= 1:
|
|
raise ValueError("IPython version 1.0+ required for notebook tag")
|
|
raise ValueError("IPython version 1.0+ required for notebook tag")
|
|
|
|
|
|
try:
|
|
try:
|
|
- from IPython.nbconvert.filters.highlight import _pygments_highlight
|
|
|
|
|
|
+ from nbconvert.filters.highlight import _pygments_highlight
|
|
except ImportError:
|
|
except ImportError:
|
|
- # IPython < 2.0
|
|
|
|
- from IPython.nbconvert.filters.highlight import _pygment_highlight as _pygments_highlight
|
|
|
|
|
|
+ try:
|
|
|
|
+ from IPython.nbconvert.filters.highlight import _pygments_highlight
|
|
|
|
+ except ImportError:
|
|
|
|
+ # IPython < 2.0
|
|
|
|
+ from IPython.nbconvert.filters.highlight import _pygment_highlight as _pygments_highlight
|
|
|
|
|
|
from pygments.formatters import HtmlFormatter
|
|
from pygments.formatters import HtmlFormatter
|
|
|
|
|
|
-from IPython.nbconvert.exporters import HTMLExporter
|
|
|
|
-from IPython.config import Config
|
|
|
|
|
|
+try:
|
|
|
|
+ from nbconvert.exporters import HTMLExporter
|
|
|
|
+except ImportError:
|
|
|
|
+ print("I was here 3")
|
|
|
|
+ from IPython.nbconvert.exporters import HTMLExporter
|
|
|
|
|
|
try:
|
|
try:
|
|
- from IPython.nbconvert.preprocessors import Preprocessor
|
|
|
|
|
|
+ from traitlets.config import Config
|
|
except ImportError:
|
|
except ImportError:
|
|
- # IPython < 2.0
|
|
|
|
- from IPython.nbconvert.transformers import Transformer as Preprocessor
|
|
|
|
|
|
+ from IPython.config import Config
|
|
|
|
+
|
|
|
|
+try:
|
|
|
|
+ from nbconvert.preprocessors import Preprocessor
|
|
|
|
+except ImportError:
|
|
|
|
+ try:
|
|
|
|
+ print("I was here 4")
|
|
|
|
+ from IPython.nbconvert.preprocessors import Preprocessor
|
|
|
|
+ except ImportError:
|
|
|
|
+ # IPython < 2.0
|
|
|
|
+ from IPython.nbconvert.transformers import Transformer as Preprocessor
|
|
|
|
+
|
|
|
|
+try:
|
|
|
|
+ from traitlets import Integer
|
|
|
|
+except ImportError:
|
|
|
|
+ from IPython.utils.traitlets import Integer
|
|
|
|
|
|
-from IPython.utils.traitlets import Integer
|
|
|
|
from copy import deepcopy
|
|
from copy import deepcopy
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
#----------------------------------------------------------------------
|
|
@@ -209,7 +233,7 @@ class SubCell(Preprocessor):
|
|
worksheet.cells = cells[self.start:self.end]
|
|
worksheet.cells = cells[self.start:self.end]
|
|
else:
|
|
else:
|
|
nbc.cells = nbc.cells[self.start:self.end]
|
|
nbc.cells = nbc.cells[self.start:self.end]
|
|
-
|
|
|
|
|
|
+
|
|
return nbc, resources
|
|
return nbc, resources
|
|
|
|
|
|
call = preprocess # IPython < 2.0
|
|
call = preprocess # IPython < 2.0
|
|
@@ -298,7 +322,10 @@ def notebook(preprocessor, tag, markup):
|
|
if IPYTHON_VERSION < 3:
|
|
if IPYTHON_VERSION < 3:
|
|
nb_json = IPython.nbformat.current.reads_json(nb_text)
|
|
nb_json = IPython.nbformat.current.reads_json(nb_text)
|
|
else:
|
|
else:
|
|
- nb_json = IPython.nbformat.reads(nb_text, as_version=4)
|
|
|
|
|
|
+ try:
|
|
|
|
+ nb_json = nbformat.reads(nb_text, as_version=4)
|
|
|
|
+ except:
|
|
|
|
+ nb_json = IPython.nbformat.reads(nb_text, as_version=4)
|
|
|
|
|
|
(body, resources) = exporter.from_notebook_node(nb_json)
|
|
(body, resources) = exporter.from_notebook_node(nb_json)
|
|
|
|
|