Mark up some plain text, given a context of symbols to look for. Each context dictionary maps object names to anchor names.
(self, text, escape=None, funcs={}, classes={}, methods={})
| 706 | """Class used to generate pydoc HTML document for a server""" |
| 707 | |
| 708 | def markup(self, text, escape=None, funcs={}, classes={}, methods={}): |
| 709 | """Mark up some plain text, given a context of symbols to look for. |
| 710 | Each context dictionary maps object names to anchor names.""" |
| 711 | escape = escape or self.escape |
| 712 | results = [] |
| 713 | here = 0 |
| 714 | |
| 715 | # XXX Note that this regular expression does not allow for the |
| 716 | # hyperlinking of arbitrary strings being used as method |
| 717 | # names. Only methods with names consisting of word characters |
| 718 | # and '.'s are hyperlinked. |
| 719 | pattern = re.compile(r'\b((http|https|ftp)://\S+[\w/]|' |
| 720 | r'RFC[- ]?(\d+)|' |
| 721 | r'PEP[- ]?(\d+)|' |
| 722 | r'(self\.)?((?:\w|\.)+))\b') |
| 723 | while 1: |
| 724 | match = pattern.search(text, here) |
| 725 | if not match: break |
| 726 | start, end = match.span() |
| 727 | results.append(escape(text[here:start])) |
| 728 | |
| 729 | all, scheme, rfc, pep, selfdot, name = match.groups() |
| 730 | if scheme: |
| 731 | url = escape(all).replace('"', '"') |
| 732 | results.append('<a href="%s">%s</a>' % (url, url)) |
| 733 | elif rfc: |
| 734 | url = 'https://www.rfc-editor.org/rfc/rfc%d.txt' % int(rfc) |
| 735 | results.append('<a href="%s">%s</a>' % (url, escape(all))) |
| 736 | elif pep: |
| 737 | url = 'https://peps.python.org/pep-%04d/' % int(pep) |
| 738 | results.append('<a href="%s">%s</a>' % (url, escape(all))) |
| 739 | elif text[end:end+1] == '(': |
| 740 | results.append(self.namelink(name, methods, funcs, classes)) |
| 741 | elif selfdot: |
| 742 | results.append('self.<strong>%s</strong>' % name) |
| 743 | else: |
| 744 | results.append(self.namelink(name, classes)) |
| 745 | here = end |
| 746 | results.append(escape(text[here:])) |
| 747 | return ''.join(results) |
| 748 | |
| 749 | def docroutine(self, object, name, mod=None, |
| 750 | funcs={}, classes={}, methods={}, cl=None): |