Last active
February 11, 2023 07:32
-
-
Save shimizukawa/9cd6721cc922776c2167f92d857ea121 to your computer and use it in GitHub Desktop.
Sphinx column directive extension コラムディレクティブ拡張 for sphinx-1.6 or later LICENSE: CC BY https://creativecommons.org/licenses/by/3.0/deed
This file contains 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 | |
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'].append(self.css_class) | |
else: | |
self.options['class'] = [self.css_class] | |
node = self.node_class('\n'.join(self.content)) | |
node += nodes.title(title, title) | |
node['classes'] += self.options['class'] | |
node['name'] = self.name | |
self.state.nested_parse(self.content, self.content_offset, node) | |
return [node] | |
class ColumnDirective(NamedNoteDirective): | |
css_class = 'column' | |
def setup(app): | |
app.add_stylesheet('custom.css') | |
app.add_directive('column', ColumnDirective) |
This file contains 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
div.column { | |
background-color: #eee; | |
border: 1px solid #ccc; | |
} |
This file contains 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
.. reStructuredText sample | |
Sphinx column directive extension: usage | |
=================================================== | |
.. column:: this is column title | |
tihs is column body. | |
If you want to use this with older sphinx, please refer https://gist.github.com/shimizukawa/2927d6ef049fe39fc3c4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment