Commits

Georg Brandl  committed 19d9870

Add add_node() support for texinfo and add handlers for nodes in our extensions.

  • Participants
  • Parent commits 0c12286

Comments (0)

Files changed (6)

File doc/ext/appapi.rst

 
    Node visitor functions for the Sphinx HTML, LaTeX, text and manpage writers
    can be given as keyword arguments: the keyword must be one or more of
-   ``'html'``, ``'latex'``, ``'text'``, ``'man'``, the value a 2-tuple of
-   ``(visit, depart)`` methods.  ``depart`` can be ``None`` if the ``visit``
-   function raises :exc:`docutils.nodes.SkipNode`.  Example:
+   ``'html'``, ``'latex'``, ``'text'``, ``'man'``, ``'texinfo'``, the value a
+   2-tuple of ``(visit, depart)`` methods.  ``depart`` can be ``None`` if the
+   ``visit`` function raises :exc:`docutils.nodes.SkipNode`.  Example:
 
    .. code-block:: python
 

File sphinx/application.py

             elif key == 'man':
                 from sphinx.writers.manpage import ManualPageTranslator \
                     as translator
+            elif key == 'texinfo':
+                from sphinx.writers.texinfo import TexinfoTranslator \
+                    as translator
             else:
                 # ignore invalid keys for compatibility
                 continue

File sphinx/ext/autosummary/__init__.py

                  html=(autosummary_toc_visit_html, autosummary_noop),
                  latex=(autosummary_noop, autosummary_noop),
                  text=(autosummary_noop, autosummary_noop),
-                 man=(autosummary_noop, autosummary_noop))
+                 man=(autosummary_noop, autosummary_noop),
+                 texinfo=(autosummary_noop, autosummary_noop))
     app.add_node(autosummary_table,
                  html=(autosummary_table_visit_html, autosummary_noop),
                  latex=(autosummary_noop, autosummary_noop),
                  text=(autosummary_noop, autosummary_noop),
-                 man=(autosummary_noop, autosummary_noop))
+                 man=(autosummary_noop, autosummary_noop),
+                 texinfo=(autosummary_noop, autosummary_noop))
     app.add_directive('autosummary', Autosummary)
     app.add_role('autolink', autolink_role)
     app.connect('doctree-read', process_autosummary_toc)

File sphinx/ext/inheritance_diagram.py

         latex=(latex_visit_inheritance_diagram, None),
         html=(html_visit_inheritance_diagram, None),
         text=(skip, None),
-        man=(skip, None))
+        man=(skip, None),
+        texinfo=(skip, None))
     app.add_directive('inheritance-diagram', InheritanceDiagram)
     app.add_config_value('inheritance_graph_attrs', {}, False),
     app.add_config_value('inheritance_node_attrs', {}, False),

File sphinx/ext/mathbase.py

 from docutils.parsers.rst import directives
 
 from sphinx.util.compat import Directive
+from sphinx.writers.texinfo import escape
 
 
 class math(nodes.Inline, nodes.TextElement):
     raise nodes.SkipNode
 
 
+def texinfo_visit_math(self, node):
+    self.body.append('@math{' + escape(node['latex']) + '}')
+    raise nodes.SkipNode
+
+def texinfo_visit_displaymath(self, node):
+    self.visit_paragraph(self, node)
+def texinfo_depart_displaymath(self, node):
+    self.depart_paragraph(self, node)
+
+def texinfo_visit_eqref(self, node):
+    self.body.append(node['target'])
+    raise nodes.SkipNode
+
+
 def html_visit_eqref(self, node):
     self.body.append('<a href="#equation-%s">' % node['target'])
 
 
 def setup_math(app, htmlinlinevisitors, htmldisplayvisitors):
     app.add_node(math,
-                 latex=(latex_visit_math, None),
-                 text=(text_visit_math, None),
-                 man=(man_visit_math, None),
-                 html=htmlinlinevisitors)
+        latex=(latex_visit_math, None),
+        text=(text_visit_math, None),
+        man=(man_visit_math, None),
+        texinfo=(texinfo_visit_math, None),
+        html=htmlinlinevisitors)
     app.add_node(displaymath,
-                 latex=(latex_visit_displaymath, None),
-                 text=(text_visit_displaymath, None),
-                 man=(man_visit_displaymath, man_depart_displaymath),
-                 html=htmldisplayvisitors)
+        latex=(latex_visit_displaymath, None),
+        text=(text_visit_displaymath, None),
+        man=(man_visit_displaymath, man_depart_displaymath),
+        texinfo=(texinfo_visit_displaymath, texinfo_depart_displaymath),
+        html=htmldisplayvisitors)
     app.add_node(eqref,
-                 latex=(latex_visit_eqref, None),
-                 text=(text_visit_eqref, None),
-                 man=(man_visit_eqref, None),
-                 html=(html_visit_eqref, html_depart_eqref))
+        latex=(latex_visit_eqref, None),
+        text=(text_visit_eqref, None),
+        man=(man_visit_eqref, None),
+        texinfo=(texinfo_visit_eqref, None),
+        html=(html_visit_eqref, html_depart_eqref))
     app.add_role('math', math_role)
     app.add_role('eq', eq_role)
     app.add_directive('math', MathDirective)

File sphinx/ext/todo.py

                  html=(visit_todo_node, depart_todo_node),
                  latex=(visit_todo_node, depart_todo_node),
                  text=(visit_todo_node, depart_todo_node),
-                 man=(visit_todo_node, depart_todo_node))
+                 man=(visit_todo_node, depart_todo_node),
+                 texinfo=(visit_todo_node, depart_todo_node))
 
     app.add_directive('todo', Todo)
     app.add_directive('todolist', TodoList)