Skip to content

Commit

Permalink
PEP 0: Make PEP titles in table clickable links
Browse files Browse the repository at this point in the history
  • Loading branch information
CAM-Gerlach committed Mar 14, 2022
1 parent 13aa4b1 commit 662aac6
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions pep_sphinx_extensions/pep_processor/transforms/pep_zero.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(self, document: nodes.document):
super().__init__(document)
self.pep_table: int = 0
self.entry: int = 0
self.ref: str | None = None

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

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

def visit_entry(self, node: nodes.entry) -> None:
self.entry += 1
if self.pep_table and self.entry == 2 and len(node) == 1:
if not self.pep_table:
return
if self.entry == 2 and len(node) == 1:
node["classes"].append("num")
# if this is the PEP number column, replace the number with a link to the PEP
para = node[0]
Expand All @@ -70,8 +74,14 @@ def visit_entry(self, node: nodes.entry) -> None:
pep_num = int(pep_str)
except ValueError:
return
ref = self.document.settings.pep_url.format(pep_num)
para[0] = nodes.reference("", pep_str, refuri=ref)
self.ref = self.document.settings.pep_url.format(pep_num)
para[0] = nodes.reference("", pep_str, refuri=self.ref)
elif self.entry == 3 and len(node) == 1 and self.ref:
# If this is the PEP title column, add a link to the PEP
para = node[0]
if isinstance(para, nodes.paragraph) and len(para) == 1:
pep_title = para.astext()
para[0] = nodes.reference("", pep_title, refuri=self.ref)


def _mask_email(ref: nodes.reference) -> nodes.reference:
Expand Down

0 comments on commit 662aac6

Please sign in to comment.