From 1aa14e34ce5b7aa13ef7480216daa3f9a824766f Mon Sep 17 00:00:00 2001 From: Min RK Date: Wed, 6 Mar 2019 15:13:59 +0100 Subject: [PATCH] address deprecation warning in cgi.escape use html.escape when available --- nbconvert/filters/markdown_mistune.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/nbconvert/filters/markdown_mistune.py b/nbconvert/filters/markdown_mistune.py index 8435e0ed9..cfe4cd4f0 100644 --- a/nbconvert/filters/markdown_mistune.py +++ b/nbconvert/filters/markdown_mistune.py @@ -9,7 +9,12 @@ from __future__ import print_function import re -import cgi + +try: + from html import escape as html_escape +except ImportError: + # Python 2 + from cgi import escape as html_escape import mistune @@ -126,12 +131,8 @@ def header(self, text, level, raw=None): anchor_link_text = self.options.get('anchor_link_text', u'ΒΆ') return add_anchor(html, anchor_link_text=anchor_link_text) - # We must be careful here for compatibility - # html.escape() is not availale on python 2.7 - # For more details, see: - # https://wiki.python.org/moin/EscapingHtml def escape_html(self, text): - return cgi.escape(text) + return html_escape(text) def block_math(self, text): return '$$%s$$' % self.escape_html(text)