diff options
| author | Dmitry Shachnev <mitya57@users.noreply.github.com> | 2020-02-03 22:38:22 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-03 14:38:22 -0500 |
| commit | a2e4788f8d1850f59699ce0ab500688031ea1571 (patch) | |
| tree | 3d80ddc754d9e4c8887f5a1cd3d666320ce30931 /markdown/extensions | |
| parent | ccf56edd1404c828c8c2f4e5492ae854e3b06dd7 (diff) | |
| download | python-markdown-a2e4788f8d1850f59699ce0ab500688031ea1571.tar.gz | |
Simplify xml.etree.ElementTree loading (#902)
cElementTree is a deprecated alias for ElementTree since Python 3.3.
Also drop the recommendation to import etree from markdown.util,
and deprecate markdown.util.etree.
Diffstat (limited to 'markdown/extensions')
| -rw-r--r-- | markdown/extensions/abbr.py | 3 | ||||
| -rw-r--r-- | markdown/extensions/admonition.py | 2 | ||||
| -rw-r--r-- | markdown/extensions/def_list.py | 2 | ||||
| -rw-r--r-- | markdown/extensions/footnotes.py | 19 | ||||
| -rw-r--r-- | markdown/extensions/md_in_html.py | 3 | ||||
| -rw-r--r-- | markdown/extensions/tables.py | 2 | ||||
| -rw-r--r-- | markdown/extensions/toc.py | 3 | ||||
| -rw-r--r-- | markdown/extensions/wikilinks.py | 2 |
8 files changed, 20 insertions, 16 deletions
diff --git a/markdown/extensions/abbr.py b/markdown/extensions/abbr.py index 6e0529a..b53f2c4 100644 --- a/markdown/extensions/abbr.py +++ b/markdown/extensions/abbr.py @@ -19,8 +19,9 @@ License: [BSD](https://opensource.org/licenses/bsd-license.php) from . import Extension from ..preprocessors import Preprocessor from ..inlinepatterns import InlineProcessor -from ..util import etree, AtomicString +from ..util import AtomicString import re +import xml.etree.ElementTree as etree # Global Vars ABBR_REF_RE = re.compile(r'[*]\[(?P<abbr>[^\]]*)\][ ]?:\s*(?P<title>.*)') diff --git a/markdown/extensions/admonition.py b/markdown/extensions/admonition.py index 5696224..3926628 100644 --- a/markdown/extensions/admonition.py +++ b/markdown/extensions/admonition.py @@ -19,7 +19,7 @@ License: [BSD](https://opensource.org/licenses/bsd-license.php) from . import Extension from ..blockprocessors import BlockProcessor -from ..util import etree +import xml.etree.ElementTree as etree import re diff --git a/markdown/extensions/def_list.py b/markdown/extensions/def_list.py index 34c3c55..3978b4d 100644 --- a/markdown/extensions/def_list.py +++ b/markdown/extensions/def_list.py @@ -17,7 +17,7 @@ License: [BSD](https://opensource.org/licenses/bsd-license.php) from . import Extension from ..blockprocessors import BlockProcessor, ListIndentProcessor -from ..util import etree +import xml.etree.ElementTree as etree import re diff --git a/markdown/extensions/footnotes.py b/markdown/extensions/footnotes.py index 18466ea..7d7ad3f 100644 --- a/markdown/extensions/footnotes.py +++ b/markdown/extensions/footnotes.py @@ -22,6 +22,7 @@ from .. import util from collections import OrderedDict import re import copy +import xml.etree.ElementTree as etree FN_BACKLINK_TEXT = util.STX + "zz1337820767766393qq" + util.ETX NBSP_PLACEHOLDER = util.STX + "qq3936677670287331zz" + util.ETX @@ -165,14 +166,14 @@ class FootnoteExtension(Extension): if not list(self.footnotes.keys()): return None - div = util.etree.Element("div") + div = etree.Element("div") div.set('class', 'footnote') - util.etree.SubElement(div, "hr") - ol = util.etree.SubElement(div, "ol") - surrogate_parent = util.etree.Element("div") + etree.SubElement(div, "hr") + ol = etree.SubElement(div, "ol") + surrogate_parent = etree.Element("div") for index, id in enumerate(self.footnotes.keys(), start=1): - li = util.etree.SubElement(ol, "li") + li = etree.SubElement(ol, "li") li.set("id", self.makeFootnoteId(id)) # Parse footnote with surrogate parent as li cannot be used. # List block handlers have special logic to deal with li. @@ -181,7 +182,7 @@ class FootnoteExtension(Extension): for el in list(surrogate_parent): li.append(el) surrogate_parent.remove(el) - backlink = util.etree.Element("a") + backlink = etree.Element("a") backlink.set("href", "#" + self.makeFootnoteRefId(id)) backlink.set("class", "footnote-backref") backlink.set( @@ -196,7 +197,7 @@ class FootnoteExtension(Extension): node.text = node.text + NBSP_PLACEHOLDER node.append(backlink) else: - p = util.etree.SubElement(li, "p") + p = etree.SubElement(li, "p") p.append(backlink) return div @@ -313,8 +314,8 @@ class FootnoteInlineProcessor(InlineProcessor): def handleMatch(self, m, data): id = m.group(1) if id in self.footnotes.footnotes.keys(): - sup = util.etree.Element("sup") - a = util.etree.SubElement(sup, "a") + sup = etree.Element("sup") + a = etree.SubElement(sup, "a") sup.set('id', self.footnotes.makeFootnoteRefId(id, found=True)) a.set('href', '#' + self.footnotes.makeFootnoteId(id)) a.set('class', 'footnote-ref') diff --git a/markdown/extensions/md_in_html.py b/markdown/extensions/md_in_html.py index 2a0c443..500c166 100644 --- a/markdown/extensions/md_in_html.py +++ b/markdown/extensions/md_in_html.py @@ -18,6 +18,7 @@ from . import Extension from ..blockprocessors import BlockProcessor from .. import util import re +import xml.etree.ElementTree as etree class MarkdownInHtmlProcessor(BlockProcessor): @@ -52,7 +53,7 @@ class MarkdownInHtmlProcessor(BlockProcessor): # Create Element markdown_value = tag['attrs'].pop('markdown') - element = util.etree.SubElement(parent, tag['tag'], tag['attrs']) + element = etree.SubElement(parent, tag['tag'], tag['attrs']) # Slice Off Block if nest: diff --git a/markdown/extensions/tables.py b/markdown/extensions/tables.py index 54942f8..4b027bb 100644 --- a/markdown/extensions/tables.py +++ b/markdown/extensions/tables.py @@ -17,7 +17,7 @@ License: [BSD](https://opensource.org/licenses/bsd-license.php) from . import Extension from ..blockprocessors import BlockProcessor -from ..util import etree +import xml.etree.ElementTree as etree import re PIPE_NONE = 0 PIPE_LEFT = 1 diff --git a/markdown/extensions/toc.py b/markdown/extensions/toc.py index e42836a..dc80c7e 100644 --- a/markdown/extensions/toc.py +++ b/markdown/extensions/toc.py @@ -15,10 +15,11 @@ License: [BSD](https://opensource.org/licenses/bsd-license.php) from . import Extension from ..treeprocessors import Treeprocessor -from ..util import etree, parseBoolValue, AMP_SUBSTITUTE, HTML_PLACEHOLDER_RE +from ..util import parseBoolValue, AMP_SUBSTITUTE, HTML_PLACEHOLDER_RE from ..postprocessors import UnescapePostprocessor import re import unicodedata +import xml.etree.ElementTree as etree def slugify(value, separator): diff --git a/markdown/extensions/wikilinks.py b/markdown/extensions/wikilinks.py index 5f81ee1..cddee7a 100644 --- a/markdown/extensions/wikilinks.py +++ b/markdown/extensions/wikilinks.py @@ -17,7 +17,7 @@ License: [BSD](https://opensource.org/licenses/bsd-license.php) from . import Extension from ..inlinepatterns import InlineProcessor -from ..util import etree +import xml.etree.ElementTree as etree import re |
