summaryrefslogtreecommitdiffstats
path: root/doc/development/tutorials/examples/helloworld.py
diff options
context:
space:
mode:
Diffstat (limited to 'doc/development/tutorials/examples/helloworld.py')
-rw-r--r--doc/development/tutorials/examples/helloworld.py25
1 files changed, 20 insertions, 5 deletions
diff --git a/doc/development/tutorials/examples/helloworld.py b/doc/development/tutorials/examples/helloworld.py
index da29562..3f7e504 100644
--- a/doc/development/tutorials/examples/helloworld.py
+++ b/doc/development/tutorials/examples/helloworld.py
@@ -1,18 +1,33 @@
+from __future__ import annotations
+
from docutils import nodes
-from docutils.parsers.rst import Directive
from sphinx.application import Sphinx
+from sphinx.util.docutils import SphinxDirective, SphinxRole
from sphinx.util.typing import ExtensionMetadata
-class HelloWorld(Directive):
- def run(self):
- paragraph_node = nodes.paragraph(text='Hello World!')
+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_directive('helloworld', HelloWorld)
+ app.add_role('hello', HelloRole())
+ app.add_directive('hello', HelloDirective)
return {
'version': '0.1',