Created
May 15, 2013 00:24
-
-
Save shimizukawa/5580802 to your computer and use it in GitHub Desktop.
Sphinxで書籍作成向け、コラムディレクティブ。ついでにnoteディレクティブがタイトルを受け取れるように変更。columnディレクティブ自体はnoteと同じ実装だけど、columnノードが出来るのでbuilderで出力を変えたり、専用のcss名が付くのでcss追加したりで調整する。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -- directive/role definition ------------------------------------------------> | |
from docutils.parsers.rst.directives.admonitions import BaseAdmonition | |
from docutils import nodes | |
from sphinx.util.compat import make_admonition | |
class NamedNoteDirective(BaseAdmonition): | |
node_class = nodes.admonition | |
#required_arguments = 1 | |
required_arguments = 0 | |
optional_arguments = 1 | |
def run(self): | |
title = u'' | |
if self.arguments: | |
title += self.arguments[0] | |
ret = make_admonition( | |
nodes.admonition, self.name, [title], self.options, | |
self.content, self.lineno, self.content_offset, self.block_text, | |
self.state, self.state_machine) | |
ret[0].attributes['name'] = self.name | |
return ret | |
def setup(app): | |
app.add_object_type('idx', 'idx', | |
objname='index role', | |
indextemplate='single: %s') | |
app.add_directive('column', NamedNoteDirective) | |
app.add_directive('note', NamedNoteDirective) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment