diff --git a/docs/source/customizing.ipynb b/docs/source/customizing.ipynb index f8ea76a50..ec85806ea 100644 --- a/docs/source/customizing.ipynb +++ b/docs/source/customizing.ipynb @@ -11,7 +11,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Under the hood, nbconvert uses [Jinja templates](https://jinja2.readthedocs.io/en/latest/intro.html) to specify how the notebooks should be formatted. These templates can be fully customized, allowing you to use nbconvert to create notebooks in different formats with different styles as well." + "Under the hood, nbconvert uses [Jinja templates](http://jinja.pocoo.org/docs/) to specify how the notebooks should be formatted. These templates can be fully customized, allowing you to use nbconvert to create notebooks in different formats with different styles as well." ] }, { diff --git a/nbconvert/exporters/html.py b/nbconvert/exporters/html.py index e90bf927c..938ef7a28 100644 --- a/nbconvert/exporters/html.py +++ b/nbconvert/exporters/html.py @@ -6,7 +6,7 @@ import os -from traitlets import default, Unicode +from traitlets import default, Unicode, Bool from traitlets.config import Config from nbconvert.filters.highlight import Highlight2HTML @@ -26,6 +26,14 @@ class HTMLExporter(TemplateExporter): anchor_link_text = Unicode(u'ΒΆ', help="The text used as the text for anchor links.").tag(config=True) + use_local_libs = Bool(False, + help="If True, use local folder libs/ instead of fetching resources from CDN" + ).tag(config=True) + + use_sri_attr = Bool(False, + help="If True, use SRI hashes for sub-resources, i.e. external javascript and CSS" + ).tag(config=True) + @default('file_extension') def _file_extension_default(self): return '.html' @@ -88,11 +96,17 @@ def process_attachments(self, nb, output): return output def from_notebook_node(self, nb, resources=None, **kw): + resources = self._init_resources(resources) + if 'reveal' not in resources: + resources['reveal'] = {} + resources['reveal']['use_local_libs'] = self.use_local_libs + resources['reveal']['use_sri_attr'] = self.use_sri_attr + langinfo = nb.metadata.get('language_info', {}) lexer = langinfo.get('pygments_lexer', langinfo.get('name', None)) highlight_code = self.filters.get('highlight_code', Highlight2HTML(pygments_lexer=lexer, parent=self)) self.register_filter('highlight_code', highlight_code) - output, resources = super(HTMLExporter, self).from_notebook_node(nb, resources, **kw) + output, resources = super(HTMLExporter, self).from_notebook_node(nb, resources=resources, **kw) att_output = self.process_attachments(nb, output) return att_output, resources diff --git a/nbconvert/exporters/slides.py b/nbconvert/exporters/slides.py index bd2c09b02..8604e165a 100644 --- a/nbconvert/exporters/slides.py +++ b/nbconvert/exporters/slides.py @@ -100,7 +100,7 @@ def _reveal_url_prefix_default(self): warn("Please update RevealHelpPreprocessor.url_prefix to " "SlidesExporter.reveal_url_prefix in config files.") return self.config.RevealHelpPreprocessor.url_prefix - return 'https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.5.0' + return 'https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.7.0' reveal_theme = Unicode('simple', help=""" @@ -130,7 +130,7 @@ def _reveal_url_prefix_default(self): ).tag(config=True) require_js_url = Unicode( - "https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.10/require.min.js", + "https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js", help=""" URL to load require.js from. @@ -139,7 +139,7 @@ def _reveal_url_prefix_default(self): ).tag(config=True) jquery_url = Unicode( - "https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js", + "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js", help=""" URL to load jQuery from. diff --git a/nbconvert/templates/html/full.tpl b/nbconvert/templates/html/full.tpl index 8cdffc664..b20eed2a1 100644 --- a/nbconvert/templates/html/full.tpl +++ b/nbconvert/templates/html/full.tpl @@ -1,6 +1,18 @@ {%- extends 'basic.tpl' -%} {% from 'mathjax.tpl' import mathjax %} +{% from 'urls.tpl' import all_urls, all_attr %} +{% if resources['reveal']['use_local_libs'] == true %} + {% set urls = all_urls.local_paths %} +{% else %} + {% set urls = all_urls.default_cdn %} +{% endif %} + +{% if resources['reveal']['use_sri_attr'] == true %} + {% set attr = all_attr.sri_attr %} +{% else %} + {% set attr = all_attr.empty_attr %} +{% endif %} {%- block header -%} @@ -11,8 +23,8 @@ {% set nb_title = nb.metadata.get('title', '') or resources['metadata']['name'] %}