mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Add add_node() support for texinfo and add handlers for nodes in our extensions.
This commit is contained in:
parent
bd268c7182
commit
92f6212c98
@ -76,9 +76,9 @@ the following public API:
|
||||
|
||||
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
|
||||
|
||||
|
@ -358,6 +358,9 @@ class Sphinx(object):
|
||||
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
|
||||
|
@ -481,12 +481,14 @@ def setup(app):
|
||||
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)
|
||||
|
@ -357,7 +357,8 @@ def setup(app):
|
||||
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),
|
||||
|
@ -13,6 +13,7 @@ from docutils import nodes, utils
|
||||
from docutils.parsers.rst import directives
|
||||
|
||||
from sphinx.util.compat import Directive
|
||||
from sphinx.writers.texinfo import escape
|
||||
|
||||
|
||||
class math(nodes.Inline, nodes.TextElement):
|
||||
@ -122,6 +123,20 @@ def man_visit_eqref(self, node):
|
||||
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'])
|
||||
|
||||
@ -148,20 +163,23 @@ def number_equations(app, doctree, docname):
|
||||
|
||||
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)
|
||||
|
@ -159,7 +159,8 @@ def setup(app):
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user