Mam proste rozszerzenie Sphinx następująco:Rozszerzenie procesora dokumentacji Sphinx działa inaczej dla wyjścia HTML i LaTeX?
from docutils import nodes
from docutils.parsers.rst import directives
from sphinx.util.compat import Directive
class testnode(nodes.Element):
def __init__(self, *args, **kwargs):
super(testnode, self).__init__(*args, **kwargs)
self['foo'] = '?'
def visit_testnode_latex(self, node):
self.body.append('Test: %s' % node['foo'])
def depart_testnode_latex(self, node):
pass
def visit_testnode_html(self, node):
self.body.append('<p>Test: %s</p>' % node['foo'])
def depart_testnode_html(self, node):
pass
class TestDirective(Directive):
has_content = False
required_arguments = 0
optional_arguments = 0
final_argument_whitespace = False
option_spec = {
'foo': directives.unchanged,
}
def run(self):
node = testnode()
node['foo'] = self.options.get('foo')
return [node]
def setup(app):
app.add_directive("testdirective", TestDirective)
app.add_node(testnode,
html=(visit_testnode_html,
depart_testnode_html),
latex=(visit_testnode_latex,
depart_testnode_latex))
otrzymać dokument zawierający wyjście
.. testdirective::
:foo: bar
HTML zawiera »Test: bar«ale wyjście LaTeX zawiera»Test:?« (The domyślna wartość). Sprawdziłem, czy node['foo']
ma poprawną wartość po przypisaniu w TestDirective.run()
, ale nie wydaje się, aby się utrzymywał, dopóki nie uruchomi się program piszący LaTeX.
Co robię źle?