From 929aaa23215fabd40e21ba329f706511a0a7bdc7 Mon Sep 17 00:00:00 2001 From: Mark Schmitz Date: Wed, 27 Feb 2019 12:32:53 +0000 Subject: [PATCH 01/11] fix url for Jinja2 docs in customizing --- docs/source/customizing.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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." ] }, { From 6c90ca9a58d7a9fa8fddf0d6b82dbcfb8f39b9a8 Mon Sep 17 00:00:00 2001 From: Mark Schmitz Date: Wed, 27 Feb 2019 14:09:28 +0000 Subject: [PATCH 02/11] fix jinja syntax and import behaviour --- nbconvert/templates/html/full.tpl | 5 +++-- nbconvert/templates/html/mathjax.tpl | 5 +++-- nbconvert/templates/html/urls.tpl | 7 +++++++ 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 nbconvert/templates/html/urls.tpl diff --git a/nbconvert/templates/html/full.tpl b/nbconvert/templates/html/full.tpl index 8cdffc664..0997d8361 100644 --- a/nbconvert/templates/html/full.tpl +++ b/nbconvert/templates/html/full.tpl @@ -1,4 +1,5 @@ {%- extends 'basic.tpl' -%} +{% from 'urls.tpl' import urls %} {% from 'mathjax.tpl' import mathjax %} @@ -11,8 +12,8 @@ {% set nb_title = nb.metadata.get('title', '') or resources['metadata']['name'] %} {{nb_title}} - - + + {% block ipywidgets %} {%- if "widgets" in nb.metadata -%} diff --git a/nbconvert/templates/html/mathjax.tpl b/nbconvert/templates/html/mathjax.tpl index 43e49c669..28543bf07 100644 --- a/nbconvert/templates/html/mathjax.tpl +++ b/nbconvert/templates/html/mathjax.tpl @@ -1,6 +1,7 @@ -{%- macro mathjax(url='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS_HTML') -%} +{%- macro mathjax() -%} +{% from 'urls.tpl' import urls %} - + + {% block ipywidgets %} diff --git a/nbconvert/templates/html/urls.tpl b/nbconvert/templates/html/urls.tpl index 0e7c2c05f..e9e75e9fe 100644 --- a/nbconvert/templates/html/urls.tpl +++ b/nbconvert/templates/html/urls.tpl @@ -1,7 +1,21 @@ -{% set base_url = 'https://cdnjs.cloudflare.com/ajax/libs/' %} +{% set cdn1_url = 'https://cdnjs.cloudflare.com/ajax/libs/' %} +{# set cdn2_url = 'https://cdn.jsdelivr.net/npm/' #} -{% set mathjax_url = base_url ~ 'mathjax/2.7.5/latest.js?config=TeX-AMS_HTML' %} -{% set requirejs_url = base_url ~ 'require.js/2.1.10/require.min.js' %} -{% set jquery_url = base_url ~ 'jquery/2.0.3/jquery.min.js' %} +{% set mathjax_url = cdn1_url ~ 'mathjax/2.7.5/latest.js?config=TeX-AMS_HTML' %} +{# set mathjax_url = cdn2_url ~ 'mathjax@2.7.5/unpacked/MathJax.min.js' #} +{% set require_js_url = cdn1_url ~ 'require.js/2.3.6/require.min.js' %} +{# set require_js_url = 'https://requirejs.org/docs/release/2.3.6/minified/require.js' #} +{% set jquery_url = cdn1_url ~ 'jquery/3.3.1/jquery.min.js' %} +{# set jquery_url = cdn2_url ~ 'jquery@3.3.1/dist/jquery.min.js' #} +{% set reveal_js = cdn1_url ~ 'reveal.js/3.7.0/js/reveal.min.js' %} +{# set reveal_js = cdn2_url ~ 'reveal.js@3.7.0/js/reveal.min.js' #} +{% set font_awesome_url = cdn1_url ~ 'font-awesome/4.7.0/css/font-awesome.css' %} +{# set font_awesome_url = 'https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css' #} -{% set urls = { 'mathjax_url' : mathjax_url, 'requirejs_url' : requirejs_url, 'jquery_url' : jquery_url } %} \ No newline at end of file +{% set urls = { + 'mathjax_url' : mathjax_url, + 'require_js_url' : require_js_url, + 'jquery_url' : jquery_url, + 'reveal_js' : reveal_js, + 'font_awesome_url' : font_awesome_url + } %} \ No newline at end of file From 00cfe5e20b6ca24434e62133b80033270d0f8eda Mon Sep 17 00:00:00 2001 From: Mark Schmitz Date: Wed, 27 Feb 2019 17:51:13 +0000 Subject: [PATCH 04/11] update js libs to latest versions, also in slides.py - add alternatives in comments --- nbconvert/exporters/slides.py | 6 +++--- nbconvert/templates/html/full.tpl | 2 +- nbconvert/templates/html/urls.tpl | 24 +++++++++++++++++++----- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/nbconvert/exporters/slides.py b/nbconvert/exporters/slides.py index bd2c09b02..b1ab5ca28 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/js/reveal.min.js' 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 0997d8361..688f8a4b5 100644 --- a/nbconvert/templates/html/full.tpl +++ b/nbconvert/templates/html/full.tpl @@ -12,7 +12,7 @@ {% set nb_title = nb.metadata.get('title', '') or resources['metadata']['name'] %} {{nb_title}} - + {% block ipywidgets %} diff --git a/nbconvert/templates/html/urls.tpl b/nbconvert/templates/html/urls.tpl index 0e7c2c05f..e9e75e9fe 100644 --- a/nbconvert/templates/html/urls.tpl +++ b/nbconvert/templates/html/urls.tpl @@ -1,7 +1,21 @@ -{% set base_url = 'https://cdnjs.cloudflare.com/ajax/libs/' %} +{% set cdn1_url = 'https://cdnjs.cloudflare.com/ajax/libs/' %} +{# set cdn2_url = 'https://cdn.jsdelivr.net/npm/' #} -{% set mathjax_url = base_url ~ 'mathjax/2.7.5/latest.js?config=TeX-AMS_HTML' %} -{% set requirejs_url = base_url ~ 'require.js/2.1.10/require.min.js' %} -{% set jquery_url = base_url ~ 'jquery/2.0.3/jquery.min.js' %} +{% set mathjax_url = cdn1_url ~ 'mathjax/2.7.5/latest.js?config=TeX-AMS_HTML' %} +{# set mathjax_url = cdn2_url ~ 'mathjax@2.7.5/unpacked/MathJax.min.js' #} +{% set require_js_url = cdn1_url ~ 'require.js/2.3.6/require.min.js' %} +{# set require_js_url = 'https://requirejs.org/docs/release/2.3.6/minified/require.js' #} +{% set jquery_url = cdn1_url ~ 'jquery/3.3.1/jquery.min.js' %} +{# set jquery_url = cdn2_url ~ 'jquery@3.3.1/dist/jquery.min.js' #} +{% set reveal_js = cdn1_url ~ 'reveal.js/3.7.0/js/reveal.min.js' %} +{# set reveal_js = cdn2_url ~ 'reveal.js@3.7.0/js/reveal.min.js' #} +{% set font_awesome_url = cdn1_url ~ 'font-awesome/4.7.0/css/font-awesome.css' %} +{# set font_awesome_url = 'https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css' #} -{% set urls = { 'mathjax_url' : mathjax_url, 'requirejs_url' : requirejs_url, 'jquery_url' : jquery_url } %} \ No newline at end of file +{% set urls = { + 'mathjax_url' : mathjax_url, + 'require_js_url' : require_js_url, + 'jquery_url' : jquery_url, + 'reveal_js' : reveal_js, + 'font_awesome_url' : font_awesome_url + } %} \ No newline at end of file From f513c96624a963f78bd62631dc4218e1dc70579d Mon Sep 17 00:00:00 2001 From: Mark Schmitz Date: Wed, 27 Feb 2019 18:04:28 +0000 Subject: [PATCH 05/11] fix reveal_url_prefix in slides.py --- nbconvert/exporters/slides.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nbconvert/exporters/slides.py b/nbconvert/exporters/slides.py index b1ab5ca28..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.7.0/js/reveal.min.js' + return 'https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.7.0' reveal_theme = Unicode('simple', help=""" From ef7b0b8613b68bb5985ba3296c067069c6512e51 Mon Sep 17 00:00:00 2001 From: Mark Schmitz Date: Wed, 27 Feb 2019 23:10:38 +0000 Subject: [PATCH 06/11] add local libs option in urls.tpl --- nbconvert/templates/html/urls.tpl | 32 +++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/nbconvert/templates/html/urls.tpl b/nbconvert/templates/html/urls.tpl index e9e75e9fe..7c8afd186 100644 --- a/nbconvert/templates/html/urls.tpl +++ b/nbconvert/templates/html/urls.tpl @@ -1,16 +1,24 @@ -{% set cdn1_url = 'https://cdnjs.cloudflare.com/ajax/libs/' %} -{# set cdn2_url = 'https://cdn.jsdelivr.net/npm/' #} +{% set default_cdn = true %} -{% set mathjax_url = cdn1_url ~ 'mathjax/2.7.5/latest.js?config=TeX-AMS_HTML' %} -{# set mathjax_url = cdn2_url ~ 'mathjax@2.7.5/unpacked/MathJax.min.js' #} -{% set require_js_url = cdn1_url ~ 'require.js/2.3.6/require.min.js' %} -{# set require_js_url = 'https://requirejs.org/docs/release/2.3.6/minified/require.js' #} -{% set jquery_url = cdn1_url ~ 'jquery/3.3.1/jquery.min.js' %} -{# set jquery_url = cdn2_url ~ 'jquery@3.3.1/dist/jquery.min.js' #} -{% set reveal_js = cdn1_url ~ 'reveal.js/3.7.0/js/reveal.min.js' %} -{# set reveal_js = cdn2_url ~ 'reveal.js@3.7.0/js/reveal.min.js' #} -{% set font_awesome_url = cdn1_url ~ 'font-awesome/4.7.0/css/font-awesome.css' %} -{# set font_awesome_url = 'https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css' #} +{%-if default_cdn %} + {% set cdn1_url = 'https://cdnjs.cloudflare.com/ajax/libs/' %} + + {% set mathjax_url = cdn1_url ~ 'mathjax/2.7.5/latest.js?config=TeX-AMS_HTML' %} + {% set require_js_url = cdn1_url ~ 'require.js/2.3.6/require.min.js' %} + {% set jquery_url = cdn1_url ~ 'jquery/3.3.1/jquery.min.js' %} + {% set reveal_js = cdn1_url ~ 'reveal.js/3.7.0/js/reveal.min.js' %} + {% set font_awesome_url = cdn1_url ~ 'font-awesome/4.7.0/css/font-awesome.css' %} + +{% else %} + {% set libs_dir = 'libs/' %} + + {% set mathjax_url = libs_dir ~ 'mathjax/2.7.5/latest.js?config=TeX-AMS_HTML' %} + {% set require_js_url = libs_dir ~ 'require.min.js' %} + {% set jquery_url = libs_dir ~ 'jquery.min.js' %} + {% set reveal_js = libs_dir ~ 'reveal.min.js' %} + {% set font_awesome_url = libs_dir ~ 'font-awesome.css' %} + +{% endif %} {% set urls = { 'mathjax_url' : mathjax_url, From 02962f1e50f1c56571ca4ea0f2a2b549e0af94b4 Mon Sep 17 00:00:00 2001 From: Mark Schmitz Date: Wed, 27 Feb 2019 23:19:17 +0000 Subject: [PATCH 07/11] add alternative external urls for js libs in urls.tpl --- nbconvert/templates/html/urls.tpl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/nbconvert/templates/html/urls.tpl b/nbconvert/templates/html/urls.tpl index 7c8afd186..7d6329f91 100644 --- a/nbconvert/templates/html/urls.tpl +++ b/nbconvert/templates/html/urls.tpl @@ -1,4 +1,5 @@ {% set default_cdn = true %} +{% set cdn_alternative = false %} {%-if default_cdn %} {% set cdn1_url = 'https://cdnjs.cloudflare.com/ajax/libs/' %} @@ -9,6 +10,15 @@ {% set reveal_js = cdn1_url ~ 'reveal.js/3.7.0/js/reveal.min.js' %} {% set font_awesome_url = cdn1_url ~ 'font-awesome/4.7.0/css/font-awesome.css' %} +{% elif cdn_alternative %} + {% set cdn2_url = 'https://cdn.jsdelivr.net/npm/' %} + + {% set mathjax_url = cdn2_url ~ 'mathjax@2.7.5/unpacked/MathJax.min.js' %} + {% set require_js_url = 'https://requirejs.org/docs/release/2.3.6/minified/require.js' %} + {% set jquery_url = cdn2_url ~ 'jquery@3.3.1/dist/jquery.min.js' %} + {% set reveal_js = cdn2_url ~ 'reveal.js@3.7.0/js/reveal.min.js' %} + {% set font_awesome_url = 'https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css' %} + {% else %} {% set libs_dir = 'libs/' %} From 2203173cc807ff52b28fc5720fa081e26e7da39b Mon Sep 17 00:00:00 2001 From: Mark Schmitz Date: Thu, 28 Feb 2019 00:36:09 +0000 Subject: [PATCH 08/11] add option to include SRI link attributes --- nbconvert/templates/html/full.tpl | 4 +-- nbconvert/templates/html/mathjax.tpl | 2 +- nbconvert/templates/html/urls.tpl | 38 +++++++++++++++++++++++----- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/nbconvert/templates/html/full.tpl b/nbconvert/templates/html/full.tpl index 688f8a4b5..1c226caba 100644 --- a/nbconvert/templates/html/full.tpl +++ b/nbconvert/templates/html/full.tpl @@ -12,8 +12,8 @@ {% set nb_title = nb.metadata.get('title', '') or resources['metadata']['name'] %} {{nb_title}} - - + + {% block ipywidgets %} {%- if "widgets" in nb.metadata -%} diff --git a/nbconvert/templates/html/mathjax.tpl b/nbconvert/templates/html/mathjax.tpl index 28543bf07..8e0fa6685 100644 --- a/nbconvert/templates/html/mathjax.tpl +++ b/nbconvert/templates/html/mathjax.tpl @@ -1,7 +1,7 @@ {%- macro mathjax() -%} {% from 'urls.tpl' import urls %} - + diff --git a/nbconvert/templates/html/urls.tpl b/nbconvert/templates/html/urls.tpl index 800fd8604..3a4b555a5 100644 --- a/nbconvert/templates/html/urls.tpl +++ b/nbconvert/templates/html/urls.tpl @@ -1,65 +1,88 @@ -{% set default_cdn = true %} -{% set cdn_alternative = false %} +{# not yet implemented as switch #} +{% set mathjax_attr = '' %} +{% set require_js_attr = '' %} +{% set jquery_attr = '' %} +{% set reveal_js_attr = '' %} +{% set font_awesome_attr = '' %} + {% set set_link_attr = false %} +{% if set_link_attr %} + {% set mathjax_attr = 'integrity="sha256-WUED7NFzpsmHtLO7bswSz4JSfkhE+cD4ncKeOznwFSY= sha384-paYjEtNXu9X/q6SBQB9EivI88vKEc/TiZWUaaH5j2Hi4vAOnVYmcahbzUELr3LHw sha512-BlZeGCIONWMdv9uCBB3I3hpY94r8I2e4DdNxyl4OOHYg0Y/LwwWDC4ioJr9vRaLNHwQG0oHiFdmqt7UaTCAZ0A==" crossorigin="anonymous"' %} + {% set require_js_attr = 'integrity="sha256-1fEPhSsRKlFKGfK3eO710tEweHh1fwokU5wFGDHO+vg= sha384-38qS6ZDmuc4fn68ICZ1CTMDv4+Yrqtpijvp5fwMNdbumNGNJ7JVJHgWr2X+nJfqM sha512-c3Nl8+7g4LMSTdrm621y7kf9v3SDPnhxLNhcjFJbKECVnmZHTdo+IRO05sNLTH/D3vA6u1X32ehoLC7WFVdheg==" crossorigin="anonymous"' %} + {% set jquery_attr = 'integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8= sha384-tsQFqpEReu7ZLhBV2VZlAu7zcOV+rXbYlF2cqB8txI/8aZajjp4Bqd+V6D5IgvKT sha512-+NqPlbbtM1QqiK8ZAo4Yrj2c4lNQoGv8P79DPtKzj++l5jnN39rHA/xsqn8zE9l0uSoxaCdrOgFs6yjyfbBxSg==" crossorigin="anonymous"' %} + {% set reveal_js_attr = 'integrity="sha256-Xr6ZH+/kc7hDVReZLO5khBknteLqu5oen/xnSraXrVk= sha384-YSZJq04Xw1k1QeTgkujYtdAjgN/sspQx01Qx4JPksOst7V7juBOa/XBwsIK+mJ7c sha512-47qp+bUV262nwngjB+lBR1txpTKevoQKlz3d1+0uvu6Zly3Q+Y+tR19xDDk4NnutJ9vu6uojPXQS4S3sOB06qw==" crossorigin="anonymous"' %} + {% set font_awesome_attr = 'integrity="sha256-NuCn4IvuZXdBaFKJOAcsU2Q3ZpwbdFisd5dux4jkQ5w= sha384-FckWOBo7yuyMS7In0aXZ0aoVvnInlnFMwCv77x9sZpFgOonQgnBj1uLwenWVtsEj sha512-5A8nwdMOWrSz20fDsjczgUidUBR8liPYU+WymTZP1lmY9G6Oc7HlZv156XqnsgNUzTyMefFTcsFH/tnJE/+xBg==" crossorigin="anonymous"' %} +{% endif %} -{%-if default_cdn %} - {% set cdn1_url = 'https://cdnjs.cloudflare.com/ajax/libs/' %} +{# default configuration #} +{% set cdn1_base = 'https://cdnjs.cloudflare.com/ajax/libs/' %} - {% set mathjax_url = cdn1_url ~ 'mathjax/2.7.5/latest.js?config=TeX-AMS_HTML' %} - {% set require_js_url = cdn1_url ~ 'require.js/2.3.6/require.min.js' %} - {% set jquery_url = cdn1_url ~ 'jquery/3.3.1/jquery.min.js' %} - {% set reveal_js_url = cdn1_url ~ 'reveal.js/3.7.0/js/reveal.min.js' %} - {% set font_awesome_url = cdn1_url ~ 'font-awesome/4.7.0/css/font-awesome.css' %} +{% set mathjax_url_1 = cdn1_base ~ 'mathjax/2.7.5/latest.js?config=TeX-AMS_HTML' %} +{% set require_js_url_1 = cdn1_base ~ 'require.js/2.3.6/require.min.js' %} +{% set jquery_url_1 = cdn1_base ~ 'jquery/3.3.1/jquery.min.js' %} +{% set reveal_js_url_1 = cdn1_base ~ 'reveal.js/3.7.0/js/reveal.min.js' %} +{% set font_awesome_url_1 = cdn1_base ~ 'font-awesome/4.7.0/css/font-awesome.css' %} -{% elif cdn_alternative %} - {% set cdn2_url = 'https://cdn.jsdelivr.net/npm/' %} +{% set default_cdn = { + 'mathjax_url' : mathjax_url_1, + 'require_js_url' : require_js_url_1, + 'jquery_url' : jquery_url_1, + 'reveal_js_url' : reveal_js_url_1, + 'font_awesome_url' : font_awesome_url_1, + 'mathjax_attr' : mathjax_attr, + 'require_js_attr' : require_js_attr, + 'jquery_attr' : jquery_attr, + 'reveal_js_attr' : reveal_js_attr, + 'font_awesome_attr' : font_awesome_attr, + } %} - {% set mathjax_url = cdn2_url ~ 'mathjax@2.7.5/unpacked/MathJax.min.js' %} - {% set require_js_url = 'https://requirejs.org/docs/release/2.3.6/minified/require.js' %} - {% set jquery_url = cdn2_url ~ 'jquery@3.3.1/dist/jquery.min.js' %} - {% set reveal_js_url = cdn2_url ~ 'reveal.js@3.7.0/js/reveal.min.js' %} - {% set font_awesome_url = 'https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css' %} +{# alternative external resources - not yet implemented as switch #} +{% set cdn2_base = 'https://cdn.jsdelivr.net/npm/' %} -{% else %} - {% set libs_dir = 'libs/' %} +{% set mathjax_url_2 = cdn2_base ~ 'mathjax@2.7.5/unpacked/MathJax.min.js' %} +{% set require_js_url_2 = 'https://requirejs.org/docs/release/2.3.6/minified/require.js' %} +{% set jquery_url_2 = cdn2_base ~ 'jquery@3.3.1/dist/jquery.min.js' %} +{% set reveal_js_url_2 = cdn2_base ~ 'reveal.js@3.7.0/js/reveal.min.js' %} +{% set font_awesome_url_2 = 'https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css' %} - {% set mathjax_url = libs_dir ~ 'mathjax/2.7.5/latest.js?config=TeX-AMS_HTML' %} - {% set require_js_url = libs_dir ~ 'require.min.js' %} - {% set jquery_url = libs_dir ~ 'jquery.min.js' %} - {% set reveal_js_url = libs_dir ~ 'reveal.min.js' %} - {% set font_awesome_url = libs_dir ~ 'font-awesome.css' %} - -{% endif %} - -{% set urls = { - 'mathjax_url' : mathjax_url, - 'require_js_url' : require_js_url, - 'jquery_url' : jquery_url, - 'reveal_js_url' : reveal_js_url, - 'font_awesome_url' : font_awesome_url, - 'mathjax_attr' : '', - 'require_js_attr' : '', - 'jquery_attr' : '', - 'reveal_js_attr' : '', - 'font_awesome_attr' : '', +{% set alternative_cdn = { + 'mathjax_url' : mathjax_url_2, + 'require_js_url' : require_js_url_2, + 'jquery_url' : jquery_url_2, + 'reveal_js_url' : reveal_js_url_2, + 'font_awesome_url' : font_awesome_url_2, + 'mathjax_attr' : mathjax_attr, + 'require_js_attr' : require_js_attr, + 'jquery_attr' : jquery_attr, + 'reveal_js_attr' : reveal_js_attr, + 'font_awesome_attr' : font_awesome_attr, } %} -{%-if set_link_attr %} - {% set urls = { - 'mathjax_url' : mathjax_url, - 'require_js_url' : require_js_url, - 'jquery_url' : jquery_url, - 'reveal_js_url' : reveal_js_url, - 'font_awesome_url' : font_awesome_url, - - 'mathjax_attr' : 'integrity="sha256-WUED7NFzpsmHtLO7bswSz4JSfkhE+cD4ncKeOznwFSY= sha384-paYjEtNXu9X/q6SBQB9EivI88vKEc/TiZWUaaH5j2Hi4vAOnVYmcahbzUELr3LHw sha512-BlZeGCIONWMdv9uCBB3I3hpY94r8I2e4DdNxyl4OOHYg0Y/LwwWDC4ioJr9vRaLNHwQG0oHiFdmqt7UaTCAZ0A==" crossorigin="anonymous"', +{# set local paths for resources #} +{% set libs_dir = 'libs/' %} - 'require_js_attr' : 'integrity="sha256-1fEPhSsRKlFKGfK3eO710tEweHh1fwokU5wFGDHO+vg= sha384-38qS6ZDmuc4fn68ICZ1CTMDv4+Yrqtpijvp5fwMNdbumNGNJ7JVJHgWr2X+nJfqM sha512-c3Nl8+7g4LMSTdrm621y7kf9v3SDPnhxLNhcjFJbKECVnmZHTdo+IRO05sNLTH/D3vA6u1X32ehoLC7WFVdheg==" crossorigin="anonymous"', +{% set mathjax_path = libs_dir ~ 'mathjax/2.7.5/latest.js?config=TeX-AMS_HTML' %} +{% set require_js_path = libs_dir ~ 'require.min.js' %} +{% set jquery_path = libs_dir ~ 'jquery.min.js' %} +{% set reveal_js_path = libs_dir ~ 'reveal.min.js' %} +{% set font_awesome_path = libs_dir ~ 'font-awesome.css' %} - 'jquery_attr' : 'integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8= sha384-tsQFqpEReu7ZLhBV2VZlAu7zcOV+rXbYlF2cqB8txI/8aZajjp4Bqd+V6D5IgvKT sha512-+NqPlbbtM1QqiK8ZAo4Yrj2c4lNQoGv8P79DPtKzj++l5jnN39rHA/xsqn8zE9l0uSoxaCdrOgFs6yjyfbBxSg==" crossorigin="anonymous"', +{% set local_paths = { + 'mathjax_url' : mathjax_path, + 'require_js_url' : require_js_path, + 'jquery_url' : jquery_path, + 'reveal_js_url' : reveal_js_path, + 'font_awesome_url' : font_awesome_path, + 'mathjax_attr' : mathjax_attr, + 'require_js_attr' : require_js_attr, + 'jquery_attr' : jquery_attr, + 'reveal_js_attr' : reveal_js_attr, + 'font_awesome_attr' : font_awesome_attr, + } %} - 'reveal_js_attr' : 'integrity="sha256-Xr6ZH+/kc7hDVReZLO5khBknteLqu5oen/xnSraXrVk= sha384-YSZJq04Xw1k1QeTgkujYtdAjgN/sspQx01Qx4JPksOst7V7juBOa/XBwsIK+mJ7c sha512-47qp+bUV262nwngjB+lBR1txpTKevoQKlz3d1+0uvu6Zly3Q+Y+tR19xDDk4NnutJ9vu6uojPXQS4S3sOB06qw==" crossorigin="anonymous"', +{% set all_urls = { + 'default_cdn' : default_cdn , + 'alternative_cdn' : alternative_cdn , + 'local_paths' : local_paths , +} %} - 'font_awesome_attr' : 'integrity="sha256-NuCn4IvuZXdBaFKJOAcsU2Q3ZpwbdFisd5dux4jkQ5w= sha384-FckWOBo7yuyMS7In0aXZ0aoVvnInlnFMwCv77x9sZpFgOonQgnBj1uLwenWVtsEj sha512-5A8nwdMOWrSz20fDsjczgUidUBR8liPYU+WymTZP1lmY9G6Oc7HlZv156XqnsgNUzTyMefFTcsFH/tnJE/+xBg==" crossorigin="anonymous"', - } %} -{% endif %} \ No newline at end of file From dfddd9b5ec7d6804b5162dc69d759d89f2b8722c Mon Sep 17 00:00:00 2001 From: Mark Schmitz Date: Fri, 1 Mar 2019 15:34:31 +0000 Subject: [PATCH 10/11] add switch use_sri_attr in HTMLExporter and adjust template --- nbconvert/exporters/html.py | 5 ++ nbconvert/nbconvertapp.py | 5 -- nbconvert/templates/html/full.tpl | 14 ++-- nbconvert/templates/html/urls.tpl | 104 +++++++++++------------------- 4 files changed, 51 insertions(+), 77 deletions(-) diff --git a/nbconvert/exporters/html.py b/nbconvert/exporters/html.py index 9b69d1f59..938ef7a28 100644 --- a/nbconvert/exporters/html.py +++ b/nbconvert/exporters/html.py @@ -30,6 +30,10 @@ class HTMLExporter(TemplateExporter): 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' @@ -96,6 +100,7 @@ def from_notebook_node(self, nb, resources=None, **kw): 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)) diff --git a/nbconvert/nbconvertapp.py b/nbconvert/nbconvertapp.py index a820b5d28..032c1b6f6 100755 --- a/nbconvert/nbconvertapp.py +++ b/nbconvert/nbconvertapp.py @@ -123,11 +123,6 @@ def validate(self, obj, value): """Exclude input cells and output prompts from converted document. This mode is ideal for generating code-free reports.""" ), - # this does not seem to work yet - # 'local-libs' : ( - # {'HTMLExporter' : { 'use_local_libs' : True}}, - # "Use local folder libs/ instead of fetching resources from CDN" - # ), }) diff --git a/nbconvert/templates/html/full.tpl b/nbconvert/templates/html/full.tpl index 1f3b0ab93..ed2033b19 100644 --- a/nbconvert/templates/html/full.tpl +++ b/nbconvert/templates/html/full.tpl @@ -1,12 +1,18 @@ {%- extends 'basic.tpl' -%} -{% from 'urls.tpl' import all_urls %} +{% 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 %} -{% from 'mathjax.tpl' import mathjax %} +{% if resources['reveal']['use_sri_attr'] == true %} + {% set attr = all_attr.sri_attr %} +{% else %} + {% set attr = all_attr.empty_attr %} +{% endif %} {%- block header -%} @@ -17,8 +23,8 @@ {% set nb_title = nb.metadata.get('title', '') or resources['metadata']['name'] %} {{nb_title}} - - + + {% block ipywidgets %} {%- if "widgets" in nb.metadata -%} diff --git a/nbconvert/templates/html/urls.tpl b/nbconvert/templates/html/urls.tpl index 3a4b555a5..98792b9c1 100644 --- a/nbconvert/templates/html/urls.tpl +++ b/nbconvert/templates/html/urls.tpl @@ -1,88 +1,56 @@ -{# not yet implemented as switch #} -{% set mathjax_attr = '' %} -{% set require_js_attr = '' %} -{% set jquery_attr = '' %} -{% set reveal_js_attr = '' %} -{% set font_awesome_attr = '' %} - -{% set set_link_attr = false %} -{% if set_link_attr %} - {% set mathjax_attr = 'integrity="sha256-WUED7NFzpsmHtLO7bswSz4JSfkhE+cD4ncKeOznwFSY= sha384-paYjEtNXu9X/q6SBQB9EivI88vKEc/TiZWUaaH5j2Hi4vAOnVYmcahbzUELr3LHw sha512-BlZeGCIONWMdv9uCBB3I3hpY94r8I2e4DdNxyl4OOHYg0Y/LwwWDC4ioJr9vRaLNHwQG0oHiFdmqt7UaTCAZ0A==" crossorigin="anonymous"' %} - {% set require_js_attr = 'integrity="sha256-1fEPhSsRKlFKGfK3eO710tEweHh1fwokU5wFGDHO+vg= sha384-38qS6ZDmuc4fn68ICZ1CTMDv4+Yrqtpijvp5fwMNdbumNGNJ7JVJHgWr2X+nJfqM sha512-c3Nl8+7g4LMSTdrm621y7kf9v3SDPnhxLNhcjFJbKECVnmZHTdo+IRO05sNLTH/D3vA6u1X32ehoLC7WFVdheg==" crossorigin="anonymous"' %} - {% set jquery_attr = 'integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8= sha384-tsQFqpEReu7ZLhBV2VZlAu7zcOV+rXbYlF2cqB8txI/8aZajjp4Bqd+V6D5IgvKT sha512-+NqPlbbtM1QqiK8ZAo4Yrj2c4lNQoGv8P79DPtKzj++l5jnN39rHA/xsqn8zE9l0uSoxaCdrOgFs6yjyfbBxSg==" crossorigin="anonymous"' %} - {% set reveal_js_attr = 'integrity="sha256-Xr6ZH+/kc7hDVReZLO5khBknteLqu5oen/xnSraXrVk= sha384-YSZJq04Xw1k1QeTgkujYtdAjgN/sspQx01Qx4JPksOst7V7juBOa/XBwsIK+mJ7c sha512-47qp+bUV262nwngjB+lBR1txpTKevoQKlz3d1+0uvu6Zly3Q+Y+tR19xDDk4NnutJ9vu6uojPXQS4S3sOB06qw==" crossorigin="anonymous"' %} - {% set font_awesome_attr = 'integrity="sha256-NuCn4IvuZXdBaFKJOAcsU2Q3ZpwbdFisd5dux4jkQ5w= sha384-FckWOBo7yuyMS7In0aXZ0aoVvnInlnFMwCv77x9sZpFgOonQgnBj1uLwenWVtsEj sha512-5A8nwdMOWrSz20fDsjczgUidUBR8liPYU+WymTZP1lmY9G6Oc7HlZv156XqnsgNUzTyMefFTcsFH/tnJE/+xBg==" crossorigin="anonymous"' %} -{% endif %} - {# default configuration #} {% set cdn1_base = 'https://cdnjs.cloudflare.com/ajax/libs/' %} - -{% set mathjax_url_1 = cdn1_base ~ 'mathjax/2.7.5/latest.js?config=TeX-AMS_HTML' %} -{% set require_js_url_1 = cdn1_base ~ 'require.js/2.3.6/require.min.js' %} -{% set jquery_url_1 = cdn1_base ~ 'jquery/3.3.1/jquery.min.js' %} -{% set reveal_js_url_1 = cdn1_base ~ 'reveal.js/3.7.0/js/reveal.min.js' %} -{% set font_awesome_url_1 = cdn1_base ~ 'font-awesome/4.7.0/css/font-awesome.css' %} - {% set default_cdn = { - 'mathjax_url' : mathjax_url_1, - 'require_js_url' : require_js_url_1, - 'jquery_url' : jquery_url_1, - 'reveal_js_url' : reveal_js_url_1, - 'font_awesome_url' : font_awesome_url_1, - 'mathjax_attr' : mathjax_attr, - 'require_js_attr' : require_js_attr, - 'jquery_attr' : jquery_attr, - 'reveal_js_attr' : reveal_js_attr, - 'font_awesome_attr' : font_awesome_attr, + 'mathjax_url' : cdn1_base ~ 'mathjax/2.7.5/latest.js?config=TeX-AMS_HTML', + 'require_js_url' : cdn1_base ~ 'require.js/2.3.6/require.min.js', + 'jquery_url' : cdn1_base ~ 'jquery/3.3.1/jquery.min.js', + 'reveal_js_url' : cdn1_base ~ 'reveal.js/3.7.0/js/reveal.min.js', + 'font_awesome_url' : cdn1_base ~ 'font-awesome/4.7.0/css/font-awesome.css', } %} {# alternative external resources - not yet implemented as switch #} {% set cdn2_base = 'https://cdn.jsdelivr.net/npm/' %} - -{% set mathjax_url_2 = cdn2_base ~ 'mathjax@2.7.5/unpacked/MathJax.min.js' %} -{% set require_js_url_2 = 'https://requirejs.org/docs/release/2.3.6/minified/require.js' %} -{% set jquery_url_2 = cdn2_base ~ 'jquery@3.3.1/dist/jquery.min.js' %} -{% set reveal_js_url_2 = cdn2_base ~ 'reveal.js@3.7.0/js/reveal.min.js' %} -{% set font_awesome_url_2 = 'https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css' %} - {% set alternative_cdn = { - 'mathjax_url' : mathjax_url_2, - 'require_js_url' : require_js_url_2, - 'jquery_url' : jquery_url_2, - 'reveal_js_url' : reveal_js_url_2, - 'font_awesome_url' : font_awesome_url_2, - 'mathjax_attr' : mathjax_attr, - 'require_js_attr' : require_js_attr, - 'jquery_attr' : jquery_attr, - 'reveal_js_attr' : reveal_js_attr, - 'font_awesome_attr' : font_awesome_attr, + 'mathjax_url' : cdn2_base ~ 'mathjax@2.7.5/unpacked/MathJax.min.js', + 'require_js_url' : 'https://requirejs.org/docs/release/2.3.6/minified/require.js', + 'jquery_url' : cdn2_base ~ 'jquery@3.3.1/dist/jquery.min.js', + 'reveal_js_url' : cdn2_base ~ 'reveal.js@3.7.0/js/reveal.min.js', + 'font_awesome_url' : 'https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css', } %} {# set local paths for resources #} {% set libs_dir = 'libs/' %} - -{% set mathjax_path = libs_dir ~ 'mathjax/2.7.5/latest.js?config=TeX-AMS_HTML' %} -{% set require_js_path = libs_dir ~ 'require.min.js' %} -{% set jquery_path = libs_dir ~ 'jquery.min.js' %} -{% set reveal_js_path = libs_dir ~ 'reveal.min.js' %} -{% set font_awesome_path = libs_dir ~ 'font-awesome.css' %} - {% set local_paths = { - 'mathjax_url' : mathjax_path, - 'require_js_url' : require_js_path, - 'jquery_url' : jquery_path, - 'reveal_js_url' : reveal_js_path, - 'font_awesome_url' : font_awesome_path, - 'mathjax_attr' : mathjax_attr, - 'require_js_attr' : require_js_attr, - 'jquery_attr' : jquery_attr, - 'reveal_js_attr' : reveal_js_attr, - 'font_awesome_attr' : font_awesome_attr, + 'mathjax_url' : libs_dir ~ 'mathjax/2.7.5/latest.js?config=TeX-AMS_HTML', + 'require_js_url' : libs_dir ~ 'require.min.js', + 'jquery_url' : libs_dir ~ 'jquery.min.js', + 'reveal_js_url' : libs_dir ~ 'reveal.min.js', + 'font_awesome_url' : libs_dir ~ 'font-awesome.css', } %} {% set all_urls = { 'default_cdn' : default_cdn , 'alternative_cdn' : alternative_cdn , 'local_paths' : local_paths , -} %} + } %} + +{% set empty_attr = { + 'mathjax_attr' : '', + 'require_js_attr' : '', + 'jquery_attr' : '', + 'reveal_js_attr' : '', + 'font_awesome_attr' : '', + } %} + +{% set sri_attr = { +'mathjax_attr' : 'integrity="sha256-WUED7NFzpsmHtLO7bswSz4JSfkhE+cD4ncKeOznwFSY= sha384-paYjEtNXu9X/q6SBQB9EivI88vKEc/TiZWUaaH5j2Hi4vAOnVYmcahbzUELr3LHw sha512-BlZeGCIONWMdv9uCBB3I3hpY94r8I2e4DdNxyl4OOHYg0Y/LwwWDC4ioJr9vRaLNHwQG0oHiFdmqt7UaTCAZ0A==" crossorigin="anonymous"', +'require_js_attr' : 'integrity="sha256-1fEPhSsRKlFKGfK3eO710tEweHh1fwokU5wFGDHO+vg= sha384-38qS6ZDmuc4fn68ICZ1CTMDv4+Yrqtpijvp5fwMNdbumNGNJ7JVJHgWr2X+nJfqM sha512-c3Nl8+7g4LMSTdrm621y7kf9v3SDPnhxLNhcjFJbKECVnmZHTdo+IRO05sNLTH/D3vA6u1X32ehoLC7WFVdheg==" crossorigin="anonymous"', +'jquery_attr' : 'integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8= sha384-tsQFqpEReu7ZLhBV2VZlAu7zcOV+rXbYlF2cqB8txI/8aZajjp4Bqd+V6D5IgvKT sha512-+NqPlbbtM1QqiK8ZAo4Yrj2c4lNQoGv8P79DPtKzj++l5jnN39rHA/xsqn8zE9l0uSoxaCdrOgFs6yjyfbBxSg==" crossorigin="anonymous"', +'reveal_js_attr' : 'integrity="sha256-Xr6ZH+/kc7hDVReZLO5khBknteLqu5oen/xnSraXrVk= sha384-YSZJq04Xw1k1QeTgkujYtdAjgN/sspQx01Qx4JPksOst7V7juBOa/XBwsIK+mJ7c sha512-47qp+bUV262nwngjB+lBR1txpTKevoQKlz3d1+0uvu6Zly3Q+Y+tR19xDDk4NnutJ9vu6uojPXQS4S3sOB06qw==" crossorigin="anonymous"', +'font_awesome_attr' : 'integrity="sha256-NuCn4IvuZXdBaFKJOAcsU2Q3ZpwbdFisd5dux4jkQ5w= sha384-FckWOBo7yuyMS7In0aXZ0aoVvnInlnFMwCv77x9sZpFgOonQgnBj1uLwenWVtsEj sha512-5A8nwdMOWrSz20fDsjczgUidUBR8liPYU+WymTZP1lmY9G6Oc7HlZv156XqnsgNUzTyMefFTcsFH/tnJE/+xBg==" crossorigin="anonymous"', + } %} +{% set all_attr = { + 'empty_attr' : empty_attr, + 'sri_attr' : sri_attr, + } %} \ No newline at end of file From c538beb3b5816babb98794a444495d99c221f6fd Mon Sep 17 00:00:00 2001 From: Mark Schmitz Date: Fri, 1 Mar 2019 16:57:25 +0000 Subject: [PATCH 11/11] fix attr for require_js to actually use require_js_attr --- nbconvert/templates/html/full.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nbconvert/templates/html/full.tpl b/nbconvert/templates/html/full.tpl index ed2033b19..b20eed2a1 100644 --- a/nbconvert/templates/html/full.tpl +++ b/nbconvert/templates/html/full.tpl @@ -23,7 +23,7 @@ {% set nb_title = nb.metadata.get('title', '') or resources['metadata']['name'] %} {{nb_title}} - + {% block ipywidgets %}