mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
This commit make it clearer, from the filenames and titles, what the extension tutorials are intended to teach.
37 lines
937 B
Python
37 lines
937 B
Python
from __future__ import annotations
|
|
|
|
from docutils import nodes
|
|
|
|
from sphinx.application import Sphinx
|
|
from sphinx.util.docutils import SphinxDirective, SphinxRole
|
|
from sphinx.util.typing import ExtensionMetadata
|
|
|
|
|
|
class HelloRole(SphinxRole):
|
|
"""A role to say hello!"""
|
|
|
|
def run(self) -> tuple[list[nodes.Node], list[nodes.system_message]]:
|
|
node = nodes.inline(text=f'Hello {self.text}!')
|
|
return [node], []
|
|
|
|
|
|
class HelloDirective(SphinxDirective):
|
|
"""A directive to say hello!"""
|
|
|
|
required_arguments = 1
|
|
|
|
def run(self) -> list[nodes.Node]:
|
|
paragraph_node = nodes.paragraph(text=f'hello {self.arguments[0]}!')
|
|
return [paragraph_node]
|
|
|
|
|
|
def setup(app: Sphinx) -> ExtensionMetadata:
|
|
app.add_role('hello', HelloRole())
|
|
app.add_directive('hello', HelloDirective)
|
|
|
|
return {
|
|
'version': '0.1',
|
|
'parallel_read_safe': True,
|
|
'parallel_write_safe': True,
|
|
}
|