Merge pull request #4588 from t-makaro/downloadas

fix duplicates in download as menu
pull/4642/head
Thomas Kluyver 7 years ago committed by GitHub
commit 9425250005
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -15,17 +15,54 @@ from ..utils import url_escape
from ..transutils import _
def get_custom_frontend_exporters():
def get_frontend_exporters():
from nbconvert.exporters.base import get_export_names, get_exporter
# name=exporter_name, display=export_from_notebook+extension
ExporterInfo = namedtuple('ExporterInfo', ['name', 'display'])
for name in sorted(get_export_names()):
exporter = get_exporter(name)()
ux_name = getattr(exporter, 'export_from_notebook', None)
if ux_name is not None:
display = _('{} ({})'.format(ux_name, exporter.file_extension))
yield ExporterInfo(name, display)
default_exporters = [
ExporterInfo(name='html', display='HTML (.html)'),
ExporterInfo(name='latex', display='LaTeX (.tex)'),
ExporterInfo(name='markdown', display='Markdown (.md)'),
ExporterInfo(name='notebook', display='Notebook (.ipynb)'),
ExporterInfo(name='pdf', display='PDF via LaTeX (.pdf)'),
ExporterInfo(name='rst', display='reST (.rst)'),
ExporterInfo(name='script', display='Script (.txt)'),
ExporterInfo(name='slides', display='Reveal.js slides (.slides.html)')
]
frontend_exporters = []
for name in get_export_names():
exporter_class = get_exporter(name)
exporter_instance = exporter_class()
ux_name = getattr(exporter_instance, 'export_from_notebook', None)
super_uxname = getattr(super(exporter_class, exporter_instance),
'export_from_notebook', None)
# Ensure export_from_notebook is explicitly defined & not inherited
if ux_name is not None and ux_name != super_uxname:
display = _('{} ({})'.format(ux_name,
exporter_instance.file_extension))
frontend_exporters.append(ExporterInfo(name, display))
# Ensure default_exporters are in frontend_exporters if not already
# This protects against nbconvert versions lower than 5.5
names = set(exporter.name.lower() for exporter in frontend_exporters)
for exporter in default_exporters:
if exporter.name not in names:
frontend_exporters.append(exporter)
# Protect against nbconvert 5.5.0
python_exporter = ExporterInfo(name='python', display='python (.py)')
if python_exporter in frontend_exporters:
frontend_exporters.remove(python_exporter)
# Protect against nbconvert 5.4.x
template_exporter = ExporterInfo(name='custom', display='custom (.txt)')
if template_exporter in frontend_exporters:
frontend_exporters.remove(template_exporter)
return sorted(frontend_exporters)
class NotebookHandler(IPythonHandler):
@ -56,7 +93,7 @@ class NotebookHandler(IPythonHandler):
kill_kernel=False,
mathjax_url=self.mathjax_url,
mathjax_config=self.mathjax_config,
get_custom_frontend_exporters=get_custom_frontend_exporters
get_frontend_exporters=get_frontend_exporters
)
)

@ -111,15 +111,7 @@ data-notebook-path="{{notebook_path | urlencode}}"
<li id="print_preview"><a href="#">{% trans %}Print Preview{% endtrans %}</a></li>
<li class="dropdown-submenu"><a href="#">{% trans %}Download as{% endtrans %}</a>
<ul id="download_menu" class="dropdown-menu">
<li id="download_ipynb"><a href="#">{% trans %}Notebook (.ipynb){% endtrans %}</a></li>
<li id="download_script"><a href="#">{% trans %}Script{% endtrans %}</a></li>
<li id="download_html"><a href="#">{% trans %}HTML (.html){% endtrans %}</a></li>
<li id="download_slides"><a href="#">{% trans %}Reveal.js slides (.html){% endtrans %}</a></li>
<li id="download_markdown"><a href="#">{% trans %}Markdown (.md){% endtrans %}</a></li>
<li id="download_rst"><a href="#">{% trans %}reST (.rst){% endtrans %}</a></li>
<li id="download_latex"><a href="#">{% trans %}LaTeX (.tex){% endtrans %}</a></li>
<li id="download_pdf"><a href="#">{% trans %}PDF via LaTeX (.pdf){% endtrans %}</a></li>
{% for exporter in get_custom_frontend_exporters() %}
{% for exporter in get_frontend_exporters() %}
<li id="download_{{ exporter.name }}">
<a href="#">{{ exporter.display }}</a>
</li>

Loading…
Cancel
Save