Skip to content

Instantly share code, notes, and snippets.

Last active Aug 25, 2017
What would you like to do?
Sphinx column directive extension コラムディレクティブ拡張 for sphinx-1.5 or earlier. LICENSE: CC BY
# -- 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
css_class = 'note'
#required_arguments = 1
required_arguments = 0
optional_arguments = 1
def run(self):
title = u''
if self.arguments:
title += self.arguments[0]
if 'class' in self.options:
self.options['class'] = [self.css_class]
ret = make_admonition(
nodes.admonition,, [title], self.options,
self.content, self.lineno, self.content_offset, self.block_text,
self.state, self.state_machine)
ret[0].attributes['name'] =
return ret
class ColumnDirective(NamedNoteDirective):
css_class = 'column'
def setup(app):
app.add_directive('column', ColumnDirective)
div.column {
background-color: #eee;
border: 1px solid #ccc;
.. reStructuredText sample
Sphinx column directive extension: usage
.. column:: this is column title
tihs is column body.
New version for sphinx-1.6 or later is here:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment