'Caveat emptor: there isn\'t much guarding against link
patterns being formed inside other standard Markdown links, e.g.
inside a [link def][like this].
Dev Notes: *Could* consider prefixing regexes with a negative
lookbehind assertion to attempt to guard against this.'

def _do_link_patterns(self, text):

    link_from_hash = {}
    for (regex, repl) in self.link_patterns:
        replacements = []
        for match in regex.finditer(text):
            if hasattr(repl, '__call__'):
                href = repl(match)
            else:
                href = match.expand(repl)
            replacements.append((match.span(), href))
        for ((start, end), href) in reversed(replacements):
            escaped_href = href.replace('"', '&quot;').replace('*', self._escape_table['*']).replace('_', self._escape_table['_'])
            link = ('<a    href="%s">%s</a>' % (escaped_href, text[start:end]))
            hash = _hash_text(link)
            link_from_hash[hash] = link
            text = ((text[:start] + hash) + text[end:])
    for (hash, link) in list(link_from_hash.items()):
        text = text.replace(hash, link)
    return text
