擅长:python、mysql、java
<p>为Sphinx编写扩展的文档位于<a href="http://sphinx-doc.org/extdev/index.html#dev-extensions" rel="nofollow">http://sphinx-doc.org/extdev/index.html#dev-extensions</a></p>
<p>我唯一的提示是使用<code>self.state.nested_parse(..)</code>可以省去很多麻烦。这里是我拥有的最简单的扩展:</p>
<pre><code>class SvnRevisionDirective(Directive):
"""Directive to display subversion revision of the path.
"""
has_content = True
required_arguments = 1
optional_arguments = 1
final_argument_whitespace = False
option_spec = {}
def run(self):
path = self.arguments[0]
rev = svntools.Revision(path) # uses subprocess etc.
paragraph = nodes.paragraph()
self.state.nested_parse(
StringList([
'**Revision:** r%d' % rev # you can use regular rst syntax here(!)
]), 0, paragraph)
return [paragraph]
...
def setup(app):
...
app.add_directive('svnrevision', SvnRevisionDirective)
</code></pre>
<p>它的用法是</p>
^{pr2}$