8000 Add github source link transform · python/peps@daf9f64 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit daf9f64

Browse files
committed
Add github source link transform
1 parent 9eb858a commit daf9f64

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

pep_extensions/pep_processor/pep_target_notes.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from docutils.transforms import misc
66
from docutils.transforms import F308 references
77

8+
import pep_extensions.config as pep_config
89

910
class PEPTargetNotes(transforms.Transform):
1011

@@ -17,7 +18,8 @@ class PEPTargetNotes(transforms.Transform):
1718
default_priority = 520
1819

1920
def apply(self):
20-
if not Path(self.document["source"]).match("pep-*"):
21+
pep_source_path = Path(self.document["source"])
22+
if not pep_source_path.match("pep-*"):
2123
# not a PEP file
2224
return
2325

@@ -49,6 +51,8 @@ def apply(self):
4951
reference_section.append(pending)
5052
self.document.note_pending(pending, 1)
5153

54+
self.add_source_link(pep_source_path)
55+
5256
@staticmethod
5357
def cleanup_callback(pending):
5458
"""
@@ -58,3 +62,9 @@ def cleanup_callback(pending):
5862
"""
5963
if len(pending.parent) == 2: # <title> and <pending>
6064
pending.parent.parent.remove(pending.parent)
65+
66+
def add_source_link(self, pep_source_path: Path) -> None:
67+
source_link = pep_config.pep_vcs_url.format(pep_source_path.name)
68+
link_node = nodes.reference("", source_link, refuri=source_link)
69+
span_node = nodes.inline("", "Source: ", link_node)
70+
self.document.append(span_node)

0 commit comments

Comments
 (0)
0