summaryrefslogtreecommitdiff
path: root/sphinx/transforms.py
diff options
context:
space:
mode:
Diffstat (limited to 'sphinx/transforms.py')
-rw-r--r--sphinx/transforms.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/sphinx/transforms.py b/sphinx/transforms.py
index 42abea588..e4806092f 100644
--- a/sphinx/transforms.py
+++ b/sphinx/transforms.py
@@ -101,6 +101,29 @@ class HandleCodeBlocks(Transform):
# del node.parent[parindex+1]
+class AutoNumbering(Transform):
+ """
+ Register IDs of tables, figures and literal_blocks to assign numbers.
+ """
+ default_priority = 210
+
+ def apply(self):
+ def has_child(node, cls):
+ for child in node:
+ if isinstance(child, cls):
+ return True
+
+ return False
+
+ for node in self.document.traverse(nodes.Element):
+ if isinstance(node, nodes.figure):
+ if has_child(node, nodes.caption):
+ self.document.note_implicit_target(node)
+ elif isinstance(node, nodes.image):
+ if has_child(node.parent, nodes.caption):
+ self.document.note_implicit_target(node.parent)
+
+
class SortIds(Transform):
"""
Sort secion IDs so that the "id[0-9]+" one comes last.