diff --git a/nbconvert/exporters/templateexporter.py b/nbconvert/exporters/templateexporter.py
index 01bffce5b..a3991b871 100644
--- a/nbconvert/exporters/templateexporter.py
+++ b/nbconvert/exporters/templateexporter.py
@@ -63,6 +63,9 @@
'get_metadata': filters.get_metadata,
'convert_pandoc': filters.convert_pandoc,
'json_dumps': json.dumps,
+ # browsers will parse , closing a script tag early
+ # Since JSON allows escaping forward slash, this will still be parsed by JSON
+ 'escape_html_script': lambda x: x.replace('', '<\\/script>'),
'strip_trailing_newline': filters.strip_trailing_newline,
'text_base64': filters.text_base64,
}
diff --git a/share/jupyter/nbconvert/templates/classic/base.html.j2 b/share/jupyter/nbconvert/templates/classic/base.html.j2
index e7b6b6aa0..ad010f016 100644
--- a/share/jupyter/nbconvert/templates/classic/base.html.j2
+++ b/share/jupyter/nbconvert/templates/classic/base.html.j2
@@ -267,7 +267,7 @@ var element = $('#{{ div_id }}');
{% set mimetype = 'application/vnd.jupyter.widget-state+json'%}
{% if mimetype in nb.metadata.get("widgets",{})%}
{% endif %}
{{ super() }}
diff --git a/share/jupyter/nbconvert/templates/lab/base.html.j2 b/share/jupyter/nbconvert/templates/lab/base.html.j2
index 684874606..45046c599 100644
--- a/share/jupyter/nbconvert/templates/lab/base.html.j2
+++ b/share/jupyter/nbconvert/templates/lab/base.html.j2
@@ -273,7 +273,7 @@ var element = document.getElementById('{{ div_id }}');
{% set mimetype = 'application/vnd.jupyter.widget-state+json'%}
{% if mimetype in nb.metadata.get("widgets",{})%}
{% endif %}
{{ super() }}