diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2018-05-23 16:50:46 +0300 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2018-05-23 16:50:46 +0300 |
commit | 489d86d47094155c4334851a03abddfb25fc215a (patch) | |
tree | aee62e282292009d8097019b4efcdb0950db13d8 /sphinx/builders/latex/transforms.py | |
parent | 51962c715c3fed63300c08b503cc5ff55c6c89b1 (diff) |
Refactor: Add captioned_literal_block node to simplify LaTeX writer
Diffstat (limited to 'sphinx/builders/latex/transforms.py')
-rw-r--r-- | sphinx/builders/latex/transforms.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/sphinx/builders/latex/transforms.py b/sphinx/builders/latex/transforms.py index 635f2489c..9c8a4192f 100644 --- a/sphinx/builders/latex/transforms.py +++ b/sphinx/builders/latex/transforms.py @@ -13,7 +13,7 @@ from docutils import nodes from sphinx import addnodes from sphinx.builders.latex.nodes import ( - footnotemark, footnotetext, math_reference, thebibliography + captioned_literal_block, footnotemark, footnotetext, math_reference, thebibliography ) from sphinx.transforms import SphinxTransform @@ -566,3 +566,18 @@ class MathReferenceTransform(SphinxTransform): if docname: refnode = math_reference('', docname=docname, target=node['reftarget']) node.replace_self(refnode) + + +class LiteralBlockTransform(SphinxTransform): + """Replace container nodes for literal_block by captioned_literal_block.""" + default_priority = 400 + + def apply(self): + # type: () -> None + if self.app.builder.name != 'latex': + return + + for node in self.document.traverse(nodes.container): + if node['literal_block'] is True: + newnode = captioned_literal_block('', *node.children, **node.attributes) + node.replace_self(newnode) |