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