Skip to content

Commit

Permalink
address deprecation warning in cgi.escape
Browse files Browse the repository at this point in the history
use html.escape when available
  • Loading branch information
minrk committed Mar 6, 2019
1 parent fdeebe2 commit 1aa14e3
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions nbconvert/filters/markdown_mistune.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1aa14e3

Please sign in to comment.