Skip to content
Merged
Changes from 1 commit
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
Next Next commit
Infra: Elide redundant title and PEP fields in displayed header table
  • Loading branch information
CAM-Gerlach committed Apr 16, 2022
commit 9045b30242de282d6380530f7242a5ff3c89099d
12 changes: 11 additions & 1 deletion pep_sphinx_extensions/pep_processor/transforms/pep_title.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@ def apply(self) -> None:
pep_header_details = {}

# Iterate through the header fields, which are the first section of the document
desired_fields = {"PEP", "Title"}
fields_to_remove = []
for field in self.document[0]:
# Hold details of the attribute's tag against its details
row_attributes = {sub.tagname: sub.rawsource for sub in field}
pep_header_details[row_attributes["field_name"]] = row_attributes["field_body"]

# Store the redundant fields in the table for removal
if row_attributes["field_name"] in desired_fields:
fields_to_remove.append(field)

# We only need the PEP number and title
if pep_header_details.keys() >= {"PEP", "Title"}:
if pep_header_details.keys() >= desired_fields:
break

# Create the title string for the PEP
Expand All @@ -46,6 +52,10 @@ def apply(self) -> None:
pep_title_node.extend(document_children)
self.document.note_implicit_target(pep_title_node, pep_title_node)

# Remove the now-redundant fields
for field in fields_to_remove:
field.parent.remove(field)


def _line_to_nodes(text: str) -> list[nodes.Node]:
"""Parse RST string to nodes."""
Expand Down