Skip to content

Commit

Permalink
+ impl-detail sphinx directive
Browse files Browse the repository at this point in the history
  • Loading branch information
skirpichev committed Dec 13, 2024
1 parent dcf81a5 commit 6dc0239
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pep_sphinx_extensions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,29 @@ def set_description(
context["description"] = "Python Enhancement Proposals (PEPs)"


class ImplementationDetail(SphinxDirective):

has_content = True
final_argument_whitespace = True

# This text is copied to templates/dummy.html
label_text = sphinx_gettext('CPython implementation detail:')

def run(self):
self.assert_has_content()
pnode = nodes.compound(classes=['impl-detail'])
content = self.content
add_text = nodes.strong(self.label_text, self.label_text)
self.state.nested_parse(content, self.content_offset, pnode)
content = nodes.inline(pnode[0].rawsource, translatable=True)
content.source = pnode[0].source
content.line = pnode[0].line
content += pnode[0].children
pnode[0].replace_self(nodes.paragraph(
'', '', add_text, nodes.Text(' '), content, translatable=False))
return [pnode]


def setup(app: Sphinx) -> dict[str, bool]:
"""Initialize Sphinx extension."""

Expand Down Expand Up @@ -101,6 +124,8 @@ def setup(app: Sphinx) -> dict[str, bool]:
app.add_directive("superseded", pep_banner_directive.SupersededBanner)
app.add_directive("withdrawn", pep_banner_directive.WithdrawnBanner)

app.add_directive('impl-detail', ImplementationDetail)

# Register event callbacks
app.connect("builder-inited", _update_config_for_builder) # Update configuration values for builder used
app.connect("env-before-read-docs", create_pep_zero) # PEP 0 hook
Expand Down

0 comments on commit 6dc0239

Please sign in to comment.