8000 PEP 0: Make PEP titles in table clickable links (#2429) · ExplodingCabbage/peps@7523502 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7523502

Browse files
authored
PEP 0: Make PEP titles in table clickable links (python#2429)
1 parent 55bed7d commit 7523502

File tree

1 file changed

+15
-5
lines changed
  • pep_sphinx_extensions/pep_processor/transforms

1 file changed

+15
-5
lines changed

pep_sphinx_extensions/pep_processor/transforms/pep_zero.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,18 @@ def apply(self) -> None:
1818

1919

2020
class PEPZeroSpecial(nodes.SparseNodeVisitor):
21-
"""Perform the special processing needed by PEP 0:
21+
"""Perform the special processing needed by PEP 0.
2222
2323
- Mask email addresses.
24-
- Link PEP numbers in the second column of 4-column tables to the PEPs themselves.
24+
- Link PEP numbers and PEP titles in the table to the PEPs themselves.
2525
2626
"""
2727

2828
def __init__(self, document: nodes.document):
2929
super().__init__(document)
3030
self.pep_table: int = 0
3131
self.entry: int = 0
32+
self.ref: str | None = None
3233

3334
def unknown_visit(self, node: nodes.Node) -> None:
3435
"""No processing for undefined node types."""
@@ -57,10 +58,13 @@ def visit_colspec(self, node: nodes.colspec) -> None:
5758

5859
def visit_row(self, _node: nodes.row) -> None:
5960
self.entry = 0 # reset column number
61+
self.ref = None # Reset PEP URL
6062

6163
def visit_entry(self, node: nodes.entry) -> None:
6264
self.entry += 1
63-
if self.pep_table and self.entry == 2 and len(node) == 1:
65+
if not self.pep_table:
66+
return
67+
if self.entry == 2 and len(node) == 1:
6468
node["classes"].append("num")
6569
# if this is the PEP number column, replace the number with a link to the PEP
6670
para = node[0]
@@ -70,8 +74,14 @@ def visit_entry(self, node: nodes.entry) -> None:
7074
pep_num = int(pep_str)
7175
except ValueError:
7276
return
73-
ref = self.document.settings.pep_url.format(pep_num)
74-
para[0] = nodes.reference("", pep_str, refuri=ref)
77+
self.ref = self.document.settings.pep_url.format(pep_num)
78+
para[0] = nodes.reference("", pep_str, refuri=self.ref)
79+
elif self.entry == 3 and len(node) == 1 and self.ref:
80+
# If this is the PEP title column, add a link to the PEP
81+
para = node[0]
82+
if isinstance(para, nodes.paragraph) and len(para) == 1:
83+
pep_title = para.astext()
84+
para[0] = nodes.reference("", pep_title, refuri=self.ref)
7585

7686

7787
def _mask_email(ref: nodes.reference) -> nodes.reference:

0 commit comments

Comments
 (0)
0