Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update nbconvert pinning #1161

Merged
merged 9 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ dependencies = [
"jupyter_core>=4.11.0",
"jupyter_server>=1.18,<2.0.0",
"jupyterlab_server>=2.3.0,<3",
"nbclient>=0.4.0,<0.7",
"nbconvert>=6.4.5,<7",
"nbclient>=0.4.0,<0.6",
martinRenou marked this conversation as resolved.
Show resolved Hide resolved
"nbconvert>=6.4.5,<8",
"traitlets>=5.0.3,<6",
"websockets>=9.0",
]
Expand Down Expand Up @@ -96,7 +96,7 @@ path = "hatch_build.py"
[tool.hatch.build.targets.sdist]
exclude = [
".github",
"*.gif",
"*.gif",
]

[tool.hatch.build.hooks.jupyter-builder]
Expand Down
4 changes: 2 additions & 2 deletions tests/notebooks/print_parameterized.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 4
}
"nbformat_minor": 5
}
15 changes: 12 additions & 3 deletions voila/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
except ImportError:
from jinja2 import contextfilter as pass_context

try:
from mistune import Renderer as MistuneRenderer
martinRenou marked this conversation as resolved.
Show resolved Hide resolved
except ImportError:
from mistune import HTMLRenderer as MistuneRenderer

from nbconvert.filters.markdown_mistune import IPythonRenderer, MarkdownWithMath
from nbconvert.exporters.html import HTMLExporter
from nbconvert.exporters.templateexporter import TemplateExporter
Expand All @@ -28,21 +33,25 @@
class VoilaMarkdownRenderer(IPythonRenderer):
"""Custom markdown renderer that inlines images"""

def __init__(self, contents_manager, *args, **kwargs):
self.contents_manager = contents_manager
super().__init__(*args, **kwargs)

def image(self, src, title, text):
contents_manager = self.options['contents_manager']
contents_manager = self.contents_manager
if contents_manager.file_exists(src):
content = contents_manager.get(src, format='base64')
data = content['content'].replace('\n', '') # remove the newline
mime_type, encoding = mimetypes.guess_type(src)
src = 'data:{mime_type};base64,{data}'.format(mime_type=mime_type, data=data)
return super(VoilaMarkdownRenderer, self).image(src, title, text)
return super().image(src, title, text)


class VoilaExporter(HTMLExporter):
"""Custom HTMLExporter that inlines the images using VoilaMarkdownRenderer"""

base_url = traitlets.Unicode(help="Base url for resources").tag(config=True)
markdown_renderer_class = traitlets.Type('mistune.Renderer').tag(config=True)
markdown_renderer_class = traitlets.Type(MistuneRenderer).tag(config=True)
# Can be a ContentsManager from notebook or jupyter_server, so Any will have to do for now
contents_manager = traitlets.Any()

Expand Down