-
Notifications
You must be signed in to change notification settings - Fork 338
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
Conversation
Hmmm - does this mean that any other Sphinx extension that alters the |
@choldgraf are you aware of such extensions? Note that this is "just" the |
I checked in the built pandas docs, and there the "docutils container" classes in divs currently only occur in the output from And they also use this as a selector for styling: (and more) So yes, this patch would break nbsphinx ... (so thanks for asking the question! ;)) Personally, I think nbsphinx should rather not use this container css class to style (they already add their own classes, so I don't think they need it). But OK, we will need to find another solution here. We will probably need to add a new docutils node (eg "div"), that does the exact same thing as the container node, except for adding those "docutils container" classes to the div. |
Remove 'docutils' and 'container' classes to overcome interference | ||
between docutils container class and bootstrap container class | ||
""" | ||
self.body.append(self.starttag(node, "div", CLASS="")) |
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.
couldn't this just be something like below? I think the details probably are off, but the general idea?
self.body.append(self.starttag(node, "div", CLASS="")) | |
classes = ' '.join(filter(lambda ii: ii != "container", node.attributes.classes)) | |
self.body.append(self.starttag(node, "div", CLASS=classes)) |
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.
Yes, that's indeed more correct (because the whole purpose was to use eg .. container:: some-bootstrap-class
, so we indeed need to pass that through as class into the html)
But, that still doesn't solve the issue of removing "container" causing issues for projects that rely on it for theming (like nbsphinx)
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.
yeah that makes sense - probably not a good idea to alter fundamental default sphinx behavior
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.
Actually, I was a bit fast with commenting, as there should be some other way that the user-defined classes are pass through, as the base docutils implementation is:
def visit_container(self, node):
self.body.append(self.starttag(node, 'div', CLASS='docutils container'))
so we have exactly the same just without the two classes. I suppose the CLASS option above is only additive to the classes that are already defined in the node itself (coming from parsing the .. container::
directive)
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.
Indeed, as far as I understood, the other classes are passed as well, this removes only these two. Still, there is probably a better way to do this, but I do not have any other idea for the moment.
So to conclude here: let's make a new directive that is kind of a copy-paste of the container directive, but with another name ("div" ?) and that doesn't use the "docutils container" classes? |
Yeah - though will this mean extensions that generate containers will have unforeseen behavior? I guess there's a reason that this is a problem in the first place that we should probably document it... |
…x-theme into remove-docutils-container-class
Still work in progress, but the addition of a It won't work for all use cases, e.g. using sphinx-aware links inside bootstrap buttons as on https://pandas.io/docs/ won't work out of the box with this approach. @jorisvandenbossche would you rather abstract the entire concept of a |
Thanks for adding the div directive!
I would say that the div directive in itself is useful anyway? But in addition also having a more opinionated card directive could remove quite some boilerplate for the user of it? |
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.
We should probably also start adding tests for such things .. (in which case we should look into how sphinx is doing this, might not be the easiest thing to do ..)
# custom div directive | ||
# see https://github.com/dnnsoftware/Docs/tree/master/common/ext | ||
|
||
class DivNode(nodes.General, nodes.Element): |
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?
A quick note on testing - over in some of the executable book project repos, we've starded using pytest-regressions on the |
@choldgraf interesting. Could you point to an example repo that is using this? |
Yep, as an example see the MyST-NB repo. Here is the tests file, you'll see it uses pytest-regressions throughout: https://github.com/ExecutableBookProject/MyST-NB/blob/master/tests/test_parser.py#L5 Here are the XML files that are checked for regressions: https://github.com/ExecutableBookProject/MyST-NB/tree/master/tests/test_parser Basically, you generate them once and double-check that they look correct to you, and then pytest-regressions will throw an error any time the output of running the tests causes a change to those files. perhaps @chrisjsewell can provide advice as well? |
FYI I have essentially implemented this in: https://github.com/executablebooks/sphinx-panels I accounted for this container issue by overriding the container visitor class: |
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Should "null" visitors also be set for other output formats
Sphinx-panels now added such a I am only wondering if we shouldn't just make sphinx-panels a dependency of this theme, so those directives are automatically available (or we should maybe at least document / showcase them in our theme docs) |
+1 from me, then we can upstream bootstrappy syntax there instead of only having it in this theme |
can we close this one? There's a |
thanks @stijnvanhoey ! |
When using the docutils
container
directive to add custom css classes to a node, docutils automatically adds thedocutiles
andcontainer
class to the element. As bootstrap itself uses acontainer
class as well, this creates interference.To avoid this, the PR adjusts the docutils container directive and only uses the css classes provided by the user.