diff --git a/pokedex/db/markdown.py b/pokedex/db/markdown.py index 115faa4..f030ba7 100644 --- a/pokedex/db/markdown.py +++ b/pokedex/db/markdown.py @@ -16,12 +16,8 @@ import re import markdown import six from sqlalchemy.orm.session import object_session -try: - # Markdown 2.1+ - from markdown.util import etree, AtomicString -except ImportError: - # Old Markdown - from markdown import etree, AtomicString +from markdown.util import etree, AtomicString + @six.python_2_unicode_compatible class MarkdownString(object): @@ -66,8 +62,7 @@ class MarkdownString(object): extension = self.session.markdown_extension md = markdown.Markdown( - extensions=['extra', extension], - safe_mode='escape', + extensions=['markdown.extensions.extra', EscapeHtml(), extension], output_format='xhtml1', ) @@ -228,6 +223,17 @@ class PokedexLinkPattern(markdown.inlinepatterns.Pattern): el.text = AtomicString(label or name) return el +class EscapeHtml(markdown.Extension): + u"""Markdown extension which escapes raw html elements. + + This is the recommended replacement for safe_mode='escape', + which was deprecated in Markdown 2.5. + See https://python-markdown.github.io/change_log/release-2.5/ + """ + def extendMarkdown(self, md, md_globals): + del md.preprocessors['html_block'] + del md.inlinePatterns['html'] + class PokedexLinkExtension(markdown.Extension): u"""Markdown extension that translates the syntax used in effect text: