'Mark up some plain text, given a context of symbols to look for.
Each context dictionary maps object names to anchor names.'

def markup(self, text, escape=None, funcs={}, classes={}, methods={}):

    escape = (escape or self.escape)
    results = []
    here = 0
    pattern = re.compile('\\b((http|ftp)://\\S+[\\w/]|RFC[-    ]?(\\d+)|PEP[-    ]?(\\d+)|(self\\.)?((?:\\w|\\.)+))\\b')
    while 1:
        match = pattern.search(text, here)
        if (not match):
            break
        (start, end) = match.span()
        results.append(escape(text[here:start]))
        (all, scheme, rfc, pep, selfdot, name) = match.groups()
        if scheme:
            url = escape(all).replace('"', '&quot;')
            results.append(('<a    href="%s">%s</a>' % (url, url)))
        elif rfc:
            url = ('http://www.rfc-editor.org/rfc/rfc%d.txt' % int(rfc))
            results.append(('<a    href="%s">%s</a>' % (url, escape(all))))
        elif pep:
            url = ('http://www.python.org/dev/peps/pep-%04d/' % int(pep))
            results.append(('<a    href="%s">%s</a>' % (url, escape(all))))
        elif (text[end:(end + 1)] == '('):
            results.append(self.namelink(name, methods, funcs, classes))
        elif selfdot:
            results.append(('self.<strong>%s</strong>' % name))
        else:
            results.append(self.namelink(name, classes))
        here = end
    results.append(escape(text[here:]))
    return ''.join(results)
