-
I have a very simple Sphinx extension that implement a custom directive that returns a new section: from docutils.parsers.rst import Directive
from docutils import nodes
class TestDirective(Directive):
def run(self):
new_section = nodes.section()
new_section += nodes.title(text="Title")
return [new_section]
def setup(app):
app.add_directive("test", TestDirective) But whenever I try to include the directive in a Sphinx project: test
====
.. test::
I get the following error:
I am still very new to Ps: I am using |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
I'd first suggest using A |
Beta Was this translation helpful? Give feedback.
-
Thanks for your answer @AA-Turner I tried with # conf.py
from sphinx.util.docutils import SphinxDirective
from docutils import nodes
class TestDirective(SphinxDirective):
def run(self):
new_section = nodes.section()
new_section += nodes.title(
text="Title",
)
return [new_section]
def setup(app):
app.add_directive("test", TestDirective) .. index.rst
Hello
=====
.. test:: I had these two files in the same folder and ran the following command inside the folder:
|
Beta Was this translation helpful? Give feedback.
I would suggest the following:
Note
note_implicit_target
, which both creates an internal reference target to your section, and sets the node ID.You may find the relevant Docutils code useful here, as this is what happens for the Docutils parser to create a section:
https://github.com/docutils/docutils/…