forked from python/peps
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
35 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 0 additions & 79 deletions
79
pep_sphinx_extensions/pep_processor/transforms/pep_contents.py
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
pep_sphinx_extensions/pep_processor/transforms/pep_section_linker.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from pathlib import Path | ||
|
||
from docutils import nodes | ||
from docutils import transforms | ||
|
||
|
||
class PEPSectionLinker(transforms.Transform): | ||
"""Link section headings to themselves.""" | ||
|
||
default_priority = 720 | ||
|
||
def apply(self) -> None: | ||
if not Path(self.document["source"]).match("pep-*"): | ||
return # not a PEP file, exit early | ||
_link_section_headings(self.document[0][3:]) # skip PEP title, headers, and <hr/> | ||
|
||
|
||
def _link_section_headings(children: list[nodes.Node]): | ||
for section in children: | ||
if not isinstance(section, nodes.section): | ||
continue | ||
|
||
# remove all pre-existing hyperlinks in the title (e.g. PEP references) | ||
title = section[0] | ||
while (link_node := title.next_node(nodes.reference)) is not None: | ||
link_node.replace_self(link_node[0]) | ||
|
||
title["refid"] = section["ids"][0] # Add a link to self | ||
|
||
_link_section_headings(section.children) # recurse to sub-sections |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters