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

Import Markup and escape directly from MarkupsSafe #1737

Merged
merged 5 commits into from Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 5 additions & 4 deletions nbconvert/exporters/html.py
Expand Up @@ -14,6 +14,7 @@
from traitlets.config import Config
from jupyter_core.paths import jupyter_path
import jinja2
import markupsafe

if tuple(int(x) for x in jinja2.__version__.split(".")[:3]) < (3, 0, 0):
from jinja2 import contextfilter
Expand Down Expand Up @@ -213,7 +214,7 @@ def _init_resources(self, resources):
def resources_include_css(name):
env = self.environment
code = """<style type="text/css">\n%s</style>""" % (env.loader.get_source(env, name)[0])
return jinja2.Markup(code)
return markupsafe.Markup(code)

def resources_include_lab_theme(name):
# Try to find the theme with the given name, looking through the labextensions
Expand All @@ -237,12 +238,12 @@ def resources_include_lab_theme(name):
data = data.replace(local_url, 'url(data:{};base64,{})'.format(mime_type, base64_data))

code = """<style type="text/css">\n%s</style>""" % data
return jinja2.Markup(code)
return markupsafe.Markup(code)

def resources_include_js(name):
env = self.environment
code = """<script>\n%s</script>""" % (env.loader.get_source(env, name)[0])
return jinja2.Markup(code)
return markupsafe.Markup(code)

def resources_include_url(name):
env = self.environment
Expand All @@ -266,7 +267,7 @@ def resources_include_url(name):
data = base64.b64encode(data)
data = data.replace(b'\n', b'').decode('ascii')
src = 'data:{mime_type};base64,{data}'.format(mime_type=mime_type, data=data)
return jinja2.Markup(src)
return markupsafe.Markup(src)

resources = super()._init_resources(resources)
resources['theme'] = self.theme
Expand Down
4 changes: 2 additions & 2 deletions nbconvert/filters/ansi.py
Expand Up @@ -4,7 +4,7 @@
# Distributed under the terms of the Modified BSD License.

import re
import jinja2
import markupsafe

__all__ = [
'strip_ansi',
Expand Down Expand Up @@ -57,7 +57,7 @@ def ansi2html(text):
Text containing ANSI colors to convert to HTML

"""
text = jinja2.utils.escape(text)
text = markupsafe.escape(text)
return _ansi2anything(text, _htmlconverter)


Expand Down
3 changes: 2 additions & 1 deletion setup.py
Expand Up @@ -225,7 +225,8 @@ def get_data_files():
'testpath',
'defusedxml',
'beautifulsoup4',
'nbclient>=0.5.0,<0.6.0'
'nbclient>=0.5.0,<0.6.0',
'MarkupSafe>=2.0'
]

pyppeteer_req = 'pyppeteer>=1,<1.1'
Expand Down