-
Notifications
You must be signed in to change notification settings - Fork 341
Adjust docutils container class addition #92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
500af67
Adjust docutils container class addition
stijnvanhoey 5b41305
Merge branch 'master' of github.com:pandas-dev/pydata-bootstrap-sphin…
stijnvanhoey 03c16e4
Remove docutils container removal hack
stijnvanhoey 5b234b1
Add Div directive
stijnvanhoey 395034c
Add div bootstrap usage example
stijnvanhoey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,11 @@ | |
Adapted for the pandas documentation. | ||
""" | ||
import os | ||
import sys | ||
|
||
from docutils import nodes | ||
from docutils.parsers.rst import Directive | ||
from docutils.parsers.rst import directives | ||
|
||
import sphinx.builders.html | ||
from sphinx.errors import ExtensionError | ||
|
@@ -166,9 +171,56 @@ def get_html_theme_path(): | |
theme_path = os.path.abspath(os.path.dirname(__file__)) | ||
return [theme_path] | ||
|
||
# ----------------------------------------------------------------------------- | ||
|
||
# custom div directive | ||
# see https://github.com/dnnsoftware/Docs/tree/master/common/ext | ||
|
||
class DivNode(nodes.General, nodes.Element): | ||
|
||
def __init__(self, text): | ||
super(DivNode, self).__init__() | ||
|
||
@staticmethod | ||
def visit_div(self, node): | ||
self.body.append(self.starttag(node, 'div')) | ||
|
||
@staticmethod | ||
def depart_div(self, node=None): | ||
self.body.append('</div>\n') | ||
|
||
class DivDirective(Directive): | ||
|
||
optional_arguments = 1 | ||
final_argument_whitespace = True | ||
option_spec = {'name': directives.unchanged} | ||
has_content = True | ||
|
||
def run(self): | ||
self.assert_has_content() | ||
text = '\n'.join(self.content) | ||
try: | ||
if self.arguments: | ||
classes = directives.class_option(self.arguments[0]) | ||
else: | ||
classes = [] | ||
except ValueError: | ||
raise self.error( | ||
'Invalid class attribute value for "%s" directive: "%s".' | ||
% (self.name, self.arguments[0])) | ||
node = DivNode(text) | ||
node['classes'].extend(classes) | ||
self.add_name(node) | ||
self.state.nested_parse(self.content, self.content_offset, node) | ||
return [node] | ||
|
||
|
||
def setup(app): | ||
theme_path = get_html_theme_path()[0] | ||
|
||
app.add_node(DivNode, html=(DivNode.visit_div, DivNode.depart_div)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should "null" visitors also be set for other output formats |
||
app.add_directive('div', DivDirective) | ||
|
||
app.add_html_theme("pandas_sphinx_theme", theme_path) | ||
app.set_translator("html", BootstrapHTML5Translator) | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe can move this to a dedicated
directives.py
file to not have the init file too crowded?