Try importing markdown utilities from markdown.util

etree and AtomicString will be moved in python-markdown 2.1

See commit https://github.com/waylan/Python-Markdown/commit/89a4f3d0829a7 :
    Cleaned up markdown namespace. This may be a backward incompatible
    change for some extensions. They should be importing from
    markdown.util
This commit is contained in:
Petr Viktorin 2011-08-31 01:55:17 +03:00
parent 719c32de0b
commit ebab8c6e43

View file

@ -15,6 +15,12 @@ import re
import markdown import markdown
from sqlalchemy.orm.session import object_session 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
class MarkdownString(object): class MarkdownString(object):
"""Wraps a Markdown string. """Wraps a Markdown string.
@ -195,8 +201,8 @@ class PokedexLinkPattern(markdown.inlinepatterns.Pattern):
if url: if url:
el = self.factory.make_link(category, obj, url, label or name) el = self.factory.make_link(category, obj, url, label or name)
else: else:
el = markdown.etree.Element('span') el = etree.Element('span')
el.text = markdown.AtomicString(label or name) el.text = AtomicString(label or name)
return el return el
class PokedexLinkExtension(markdown.Extension): class PokedexLinkExtension(markdown.Extension):
@ -218,9 +224,9 @@ class PokedexLinkExtension(markdown.Extension):
Override this to set custom attributes, e.g. title. Override this to set custom attributes, e.g. title.
""" """
el = markdown.etree.Element('a') el = etree.Element('a')
el.set('href', url) el.set('href', url)
el.text = markdown.AtomicString(text) el.text = AtomicString(text)
return el return el
def identifier_url(self, category, identifier): def identifier_url(self, category, identifier):