diff --git a/markdown/treeprocessors.py b/markdown/treeprocessors.py index 109358beb703..152daab15b87 100644 --- a/markdown/treeprocessors.py +++ b/markdown/treeprocessors.py @@ -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 @@ -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) @@ -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: @@ -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 @@ -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: @@ -379,14 +379,14 @@ def run(self, root): self._prettifyETree(root) # Do
'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'