Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sphinx-doc/sphinx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortk0miya <i.tkomiya@gmail.com>2014-09-26 17:40:24 +0400
committertk0miya <i.tkomiya@gmail.com>2014-09-26 17:40:24 +0400
commitf974aca3565992d6e011452a071be69b1fab74e8 (patch)
tree29b126edfe0116782cb1e60baa60a7fd4255becb /sphinx/transforms.py
parent7984f81a5e8a9e533559ffffd2907c1d82be8292 (diff)
Assign figure numbers automatically
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.