Skip to content

Commit 419fbfe

Browse files
committed
PRS: Update Post-History processing for inline links
1 parent f52151b commit 419fbfe

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

pep_sphinx_extensions/pep_processor/transforms/pep_headers.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ def apply(self) -> None:
9292
elif name in {"last-modified", "content-type", "version"}:
9393
# Mark unneeded fields
9494
fields_to_remove.append(field)
95+
elif name in {"post-history"}:
96+
body[0][:] = _process_post_history(body)
9597

9698
# Remove unneeded fields
9799
for field in fields_to_remove:
@@ -115,3 +117,24 @@ def _pretty_thread(text: nodes.Text) -> nodes.Text:
115117
except ValueError:
116118
# archives and pipermail not in list, e.g. PEP 245
117119
return text
120+
121+
122+
def _process_post_history(body: nodes.field_body) -> list[nodes.Text | nodes.reference]:
123+
new_nodes = []
124+
for pair in body.astext().split(","):
125+
pair = pair.strip()
126+
try:
127+
# if Post-History has no links, ``pair.split(maxsplit=1)``
128+
# will raise ValueError
129+
date, uri = pair.split(maxsplit=1)
130+
node = nodes.reference("",
131+
date.strip(),
132+
refuri=uri.strip(" \f\n\r\t><"),
133+
internal=False
134+
)
135+
except ValueError:
136+
node = nodes.Text(pair)
137+
138+
new_nodes += [node, nodes.Text(", ")]
139+
140+
return new_nodes[:-1] # remove final ', '

0 commit comments

Comments
 (0)