MCPcopy Index your code
hub / github.com/RustPython/RustPython / markup

Method markup

Lib/pydoc.py:777–814  ·  view source on GitHub ↗

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={})

Source from the content-addressed store, hash-verified

775 return '<a href="file:%s">%s</a>' % (url, path)
776
777 def markup(self, text, escape=None, funcs={}, classes={}, methods={}):
778 """Mark up some plain text, given a context of symbols to look for.
779 Each context dictionary maps object names to anchor names."""
780 escape = escape or self.escape
781 results = []
782 here = 0
783 pattern = re.compile(r'\b((http|https|ftp)://\S+[\w/]|'
784 r'RFC[- ]?(\d+)|'
785 r'PEP[- ]?(\d+)|'
786 r'(self\.)?(\w+))')
787 while match := pattern.search(text, here):
788 start, end = match.span()
789 results.append(escape(text[here:start]))
790
791 all, scheme, rfc, pep, selfdot, name = match.groups()
792 if scheme:
793 url = escape(all).replace('"', '&quot;')
794 results.append('<a href="%s">%s</a>' % (url, url))
795 elif rfc:
796 url = 'https://www.rfc-editor.org/rfc/rfc%d.txt' % int(rfc)
797 results.append('<a href="%s">%s</a>' % (url, escape(all)))
798 elif pep:
799 url = 'https://peps.python.org/pep-%04d/' % int(pep)
800 results.append('<a href="%s">%s</a>' % (url, escape(all)))
801 elif selfdot:
802 # Create a link for methods like 'self.method(...)'
803 # and use <strong> for attributes like 'self.attr'
804 if text[end:end+1] == '(':
805 results.append('self.' + self.namelink(name, methods))
806 else:
807 results.append('self.<strong>%s</strong>' % name)
808 elif text[end:end+1] == '(':
809 results.append(self.namelink(name, methods, funcs, classes))
810 else:
811 results.append(self.namelink(name, classes))
812 here = end
813 results.append(escape(text[here:]))
814 return ''.join(results)
815
816 # ---------------------------------------------- type-specific routines
817

Callers 6

docmoduleMethod · 0.95
spilldataMethod · 0.95
docclassMethod · 0.95
docroutineMethod · 0.95
docdataMethod · 0.95
html_topicpageFunction · 0.45

Calls 9

namelinkMethod · 0.95
spanMethod · 0.80
escapeFunction · 0.70
compileMethod · 0.45
searchMethod · 0.45
appendMethod · 0.45
groupsMethod · 0.45
replaceMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected