Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions pep_sphinx_extensions/pep_processor/transforms/pep_zero.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ def apply(self) -> None:


class PEPZeroSpecial(nodes.SparseNodeVisitor):
"""Perform the special processing needed by PEP 0:
"""Perform the special processing needed by PEP 0.

- Mask email addresses.
- Link PEP numbers in the second column of 4-column tables to the PEPs themselves.
- Link PEP numbers and PEP titles in the table to the PEPs themselves.

"""

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