'Apply inline patterns to a parsed Markdown tree.
Iterate over ElementTree, find elements with inline tag, apply inline
patterns and append newly created Elements to tree.  If you don\'t
want to process your data with inline paterns, instead of normal
string, use subclass AtomicString:
node.text = markdown.AtomicString("This will not be processed.")
Arguments:
* tree: ElementTree object, representing Markdown tree.
Returns: ElementTree object with applied inline patterns.'

def run(self, tree):

    self.stashed_nodes = {}
    stack = [tree]
    while stack:
        currElement = stack.pop()
        insertQueue = []
        for child in currElement:
            if (child.text and (not isinstance(child.text, util.AtomicString))):
                text = child.text
                child.text = None
                lst = self.__processPlaceholders(self.__handleInline(text), child)
                stack += lst
                insertQueue.append((child, lst))
            if child.tail:
                tail = self.__handleInline(child.tail)
                dumby = util.etree.Element(u'd')
                child.tail = None
                tailResult = self.__processPlaceholders(tail, dumby, False)
                if dumby.tail:
                    child.tail = dumby.tail
                pos = (list(currElement).index(child) + 1)
                tailResult.reverse()
                for newChild in tailResult:
                    currElement.insert(pos, newChild)
            if len(child):
                stack.append(child)
        for (element, lst) in insertQueue:
            if self.markdown.enable_attributes:
                if (element.text and isString(element.text)):
                    element.text = inlinepatterns.handleAttributes(element.text, element)
            i = 0
            for newChild in lst:
                if self.markdown.enable_attributes:
                    if (newChild.tail and isString(newChild.tail)):
                        newChild.tail = inlinepatterns.handleAttributes(newChild.tail, element)
                    if (newChild.text and isString(newChild.text)):
                        newChild.text = inlinepatterns.handleAttributes(newChild.text, newChild)
                element.insert(i, newChild)
                i += 1
    return tree
