Skip to content

Commit

Permalink
python3: Fix python3 issues in markdown/treeprocessors.py
Browse files Browse the repository at this point in the history
Replaces node.getchildren() with list(node) or direct loops over the
node as well as replacing node.getiterator() with node.iter().

Change-Id: Id9a2638c0e4aaa266753ba59880c7edfc6874312
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2853352
Reviewed-by: Ken Rockot <[email protected]>
Commit-Queue: Dan Elphick <[email protected]>
Cr-Commit-Position: refs/heads/master@{#877931}
NOKEYCHECK=True
GitOrigin-RevId: 67d9015f0a8b9c2e2a17e62c0b7ad308f04e91fe
  • Loading branch information
danelphick authored and copybara-github committed Apr 30, 2021
1 parent 2d6415a commit 27d5056
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions markdown/treeprocessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def __processElementText(self, node, subnode, isText=True):
childResult = self.__processPlaceholders(text, subnode)

if not isText and node is not subnode:
pos = node.getchildren().index(subnode)
pos = list(node).index(subnode)
node.remove(subnode)
else:
pos = 0
Expand Down Expand Up @@ -211,7 +211,7 @@ def linkText(text):
linkText(text)

if not isString(node): # it's Element
for child in [node] + node.getchildren():
for child in [node] + list(node):
if child.tail:
if child.tail.strip():
self.__processElementText(node, child,False)
Expand Down Expand Up @@ -269,9 +269,9 @@ def __applyPattern(self, pattern, data, patternIndex, startIndex=0):
if not isString(node):
if not isinstance(node.text, util.AtomicString):
# We need to process current node too
for child in [node] + node.getchildren():
for child in [node] + list(node):
if not isString(node):
if child.text:
if child.text:
child.text = self.__handleInline(child.text,
patternIndex + 1)
if child.tail:
Expand Down Expand Up @@ -308,7 +308,7 @@ def run(self, tree):
while stack:
currElement = stack.pop()
insertQueue = []
for child in currElement.getchildren():
for child in currElement:
if child.text and not isinstance(child.text, util.AtomicString):
text = child.text
child.text = None
Expand All @@ -324,11 +324,11 @@ def run(self, tree):
child.tail = dumby.text
else:
child.tail = None
pos = currElement.getchildren().index(child) + 1
pos = list(currElement).index(child) + 1
tailResult.reverse()
for newChild in tailResult:
currElement.insert(pos, newChild)
if child.getchildren():
if list(child):
stack.append(child)

for element, lst in insertQueue:
Expand Down Expand Up @@ -379,14 +379,14 @@ def run(self, root):
self._prettifyETree(root)
# Do <br />'s seperately as they are often in the middle of
# inline content and missed by _prettifyETree.
brs = root.getiterator('br')
brs = root.iter('br')
for br in brs:
if not br.tail or not br.tail.strip():
br.tail = '\n'
else:
br.tail = '\n%s' % br.tail
# Clean up extra empty lines at end of code blocks.
pres = root.getiterator('pre')
pres = root.iter('pre')
for pre in pres:
if len(pre) and pre[0].tag == 'code':
pre[0].text = pre[0].text.rstrip() + '\n'

0 comments on commit 27d5056

Please sign in to comment.