summaryrefslogtreecommitdiffstats
path: root/tests/roots/test-add_enumerable_node
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 17:25:40 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 17:25:40 +0000
commitcf7da1843c45a4c2df7a749f7886a2d2ba0ee92a (patch)
tree18dcde1a8d1f5570a77cd0c361de3b490d02c789 /tests/roots/test-add_enumerable_node
parentInitial commit. (diff)
downloadsphinx-cf7da1843c45a4c2df7a749f7886a2d2ba0ee92a.tar.xz
sphinx-cf7da1843c45a4c2df7a749f7886a2d2ba0ee92a.zip
Adding upstream version 7.2.6.upstream/7.2.6
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/roots/test-add_enumerable_node')
-rw-r--r--tests/roots/test-add_enumerable_node/conf.py7
-rw-r--r--tests/roots/test-add_enumerable_node/enumerable_node.py62
-rw-r--r--tests/roots/test-add_enumerable_node/index.rst48
-rw-r--r--tests/roots/test-add_enumerable_node/rimg.pngbin0 -> 120 bytes
4 files changed, 117 insertions, 0 deletions
diff --git a/tests/roots/test-add_enumerable_node/conf.py b/tests/roots/test-add_enumerable_node/conf.py
new file mode 100644
index 0000000..8c3a568
--- /dev/null
+++ b/tests/roots/test-add_enumerable_node/conf.py
@@ -0,0 +1,7 @@
+import os
+import sys
+
+sys.path.insert(0, os.path.abspath('.'))
+extensions = ['enumerable_node']
+
+numfig = True
diff --git a/tests/roots/test-add_enumerable_node/enumerable_node.py b/tests/roots/test-add_enumerable_node/enumerable_node.py
new file mode 100644
index 0000000..782365e
--- /dev/null
+++ b/tests/roots/test-add_enumerable_node/enumerable_node.py
@@ -0,0 +1,62 @@
+from docutils import nodes
+from docutils.parsers.rst import Directive
+
+
+class my_figure(nodes.figure):
+ pass
+
+
+def visit_my_figure(self, node):
+ self.visit_figure(node)
+
+
+def depart_my_figure(self, node):
+ self.depart_figure(node)
+
+
+class MyFigure(Directive):
+ required_arguments = 1
+ has_content = True
+
+ def run(self):
+ figure_node = my_figure()
+ figure_node += nodes.image(uri=self.arguments[0])
+ figure_node += nodes.caption(text=''.join(self.content))
+ return [figure_node]
+
+
+class numbered_text(nodes.Element):
+ pass
+
+
+def visit_numbered_text(self, node):
+ self.body.append(self.starttag(node, 'div'))
+ self.add_fignumber(node)
+ self.body.append(node['title'])
+ self.body.append('</div>')
+ raise nodes.SkipNode
+
+
+def get_title(node):
+ return node['title']
+
+
+class NumberedText(Directive):
+ required_arguments = 1
+ final_argument_whitespace = True
+
+ def run(self):
+ return [numbered_text(title=self.arguments[0])]
+
+
+def setup(app):
+ # my-figure
+ app.add_enumerable_node(my_figure, 'figure',
+ html=(visit_my_figure, depart_my_figure))
+ app.add_directive('my-figure', MyFigure)
+
+ # numbered_label
+ app.add_enumerable_node(numbered_text, 'original', get_title,
+ html=(visit_numbered_text, None))
+ app.add_directive('numbered-text', NumberedText)
+ app.config.numfig_format.setdefault('original', 'No.%s')
diff --git a/tests/roots/test-add_enumerable_node/index.rst b/tests/roots/test-add_enumerable_node/index.rst
new file mode 100644
index 0000000..98b858e
--- /dev/null
+++ b/tests/roots/test-add_enumerable_node/index.rst
@@ -0,0 +1,48 @@
+========================
+test-add_enumerable_node
+========================
+
+.. toctree::
+ :numbered:
+
+
+First section
+=============
+
+.. _first_figure:
+
+.. figure:: rimg.png
+
+ First figure
+
+.. _first_my_figure:
+
+.. my-figure:: rimg.png
+
+ First my figure
+
+.. _first_numbered_text:
+
+.. numbered-text:: Hello world
+
+.. _second_numbered_text:
+
+.. numbered-text:: Hello Sphinx
+
+Second section
+==============
+
+.. _second_my_figure:
+
+.. my-figure:: rimg.png
+
+ Second my figure
+
+Reference section
+=================
+
+* first_figure is :numref:`first_figure`
+* first_my_figure is :numref:`first_my_figure`
+* second_my_figure is :numref:`second_my_figure`
+* first numbered_text is :numref:`first_numbered_text`
+* second numbered_text is :numref:`second_numbered_text`
diff --git a/tests/roots/test-add_enumerable_node/rimg.png b/tests/roots/test-add_enumerable_node/rimg.png
new file mode 100644
index 0000000..fda6cd2
--- /dev/null
+++ b/tests/roots/test-add_enumerable_node/rimg.png
Binary files differ