Skip to content

Commit 82ad7a9

Browse files
committed
Use newer ElementTree API to avoid future breakage.
1 parent 17123ea commit 82ad7a9

File tree

7 files changed

+9
-10
lines changed

7 files changed

+9
-10
lines changed

markdown/blockprocessors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def test(self, parent, block):
148148
return block.startswith(' '*self.tab_length) and \
149149
not self.parser.state.isstate('detabbed') and \
150150
(parent.tag in self.ITEM_TYPES or
151-
(len(parent) and parent[-1] and
151+
(len(parent) and parent[-1] is not None and
152152
(parent[-1].tag in self.LIST_TYPES)))
153153

154154
def run(self, parent, blocks):

markdown/extensions/admonition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class AdmonitionProcessor(BlockProcessor):
4646
def test(self, parent, block):
4747
sibling = self.lastChild(parent)
4848
return self.RE.search(block) or \
49-
(block.startswith(' ' * self.tab_length) and sibling and
49+
(block.startswith(' ' * self.tab_length) and sibling is not None and
5050
sibling.get('class', '').find(self.CLASSNAME) != -1)
5151

5252
def run(self, parent, blocks):

markdown/extensions/codehilite.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,11 @@ class HiliteTreeprocessor(Treeprocessor):
201201

202202
def run(self, root):
203203
""" Find code blocks and store in htmlStash. """
204-
blocks = root.getiterator('pre')
204+
blocks = root.iter('pre')
205205
for block in blocks:
206-
children = block.getchildren()
207-
if len(children) == 1 and children[0].tag == 'code':
206+
if len(block) == 1 and block[0].tag == 'code':
208207
code = CodeHilite(
209-
children[0].text,
208+
block[0].text,
210209
linenums=self.config['linenums'],
211210
guess_lang=self.config['guess_lang'],
212211
css_class=self.config['css_class'],

markdown/extensions/def_list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def run(self, parent, blocks):
6464
else:
6565
state = 'list'
6666

67-
if sibling and sibling.tag == 'dl':
67+
if sibling is not None and sibling.tag == 'dl':
6868
# This is another item on an existing list
6969
dl = sibling
7070
if not terms and len(dl) and dl[-1].tag == 'dd' and len(dl[-1]):

markdown/extensions/footnotes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ def __init__(self, footnotes):
287287

288288
def run(self, root):
289289
footnotesDiv = self.footnotes.makeFootnotesDiv(root)
290-
if footnotesDiv:
290+
if footnotesDiv is not None:
291291
result = self.footnotes.findFootnotesPlaceholder(root)
292292
if result:
293293
child, parent, isText = result

markdown/extensions/headerid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def run(self, doc):
3333
start_level, force_id = self._get_meta()
3434
slugify = self.config['slugify']
3535
sep = self.config['separator']
36-
for elem in doc.getiterator():
36+
for elem in doc:
3737
if elem.tag in ['h1', 'h2', 'h3', 'h4', 'h5', 'h6']:
3838
if force_id:
3939
if "id" in elem.attrib:

markdown/extensions/toc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def add_anchor(self, c, elem_id): # @ReservedAssignment
178178
anchor.attrib["href"] = "#" + elem_id
179179
anchor.attrib["class"] = "toclink"
180180
c.text = ""
181-
for elem in c.getchildren():
181+
for elem in c:
182182
anchor.append(elem)
183183
c.remove(elem)
184184
c.append(anchor)

0 commit comments

Comments
 (0)