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

Use escape from markupsafe #1738

Closed
wants to merge 2 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from traitlets import default, Unicode, Bool
from traitlets.config import Config
from jupyter_core.paths import jupyter_path
from markupsafe import Markup
import jinja2

if tuple(int(x) for x in jinja2.__version__.split(".")[:3]) < (3, 0, 0):
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 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 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 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 Markup(src)

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

import re
import jinja2
from markupsafe import escape

__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 = escape(text)
return _ansi2anything(text, _htmlconverter)


Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ def get_data_files():
)

setup_args['install_requires'] = [
'markupsafe<3',
'mistune>=0.8.1,<2',
'jinja2>=2.4',
'pygments>=2.4.1',
Expand Down