Debian Codegraph @

doc/_extensions/gh_link.py

raw
1 from docutils import nodes
2
3
4 def setup(app):
5 app.add_role(
6 "pr", autolink("https://github.com/python/typing_extensions/pull/{}", "PR #")
7 )
8 app.add_role(
9 "pr-cpy", autolink("https://github.com/python/cpython/pull/{}", "CPython PR #")
10 )
11 app.add_role(
12 "issue",
13 autolink("https://github.com/python/typing_extensions/issues/{}", "issue #"),
14 )
15 app.add_role(
16 "issue-cpy",
17 autolink("https://github.com/python/cpython/issues/{}", "CPython issue #"),
18 )
19
20
21 def autolink(pattern: str, prefix: str):
22 def role(name, rawtext, text: str, lineno, inliner, options=None, content=None):
23 if options is None:
24 options = {}
25 url = pattern.format(text)
26 node = nodes.reference(rawtext, f"{prefix}{text}", refuri=url, **options)
27 return [node], []
28
29 return role