-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Add collapsible
option to admonition directives
#12507
Add collapsible
option to admonition directives
#12507
Conversation
collabsible
option to admonition directives
I'd be happy to accomodate for this downstream. |
For what it is worth, in Pydata Sphinx Theme we have equivalent "dropdown" we use from sphinx-design: https://pydata-sphinx-theme.readthedocs.io/en/stable/user_guide/web-components.html#dropdowns Not pronouncing for everybody of the core team, but I think we would be happy with having this in core sphinx. I don't know if it's of use but there was an accessibility audit of PST, and I believe one of the findings was that the I guess that's more of a theming question. Would it make sens ":collapsible:" to take a boolean instead of a flag in case you want to make all collapsible by default and override with false ? |
In sphinx-immaterial theme, we conditionally override the admonitions to include this feature (among others). I implemented the .. admonition:: An optional title in sphinx-immaterial
:collapsible:
Closed by default.
.. admonition:: An optional title in sphinx-immaterial
:collapsible: open
Opened by default. Where the optional title becomes required if the It makes sense to have a separate |
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.
This doesn't effect the sphinx.ext.todo
admonitions. I imagine people would make an assumption that this feature is extended to .. todo::
directives as well.
We, at sphinx-immaterial, also satisfied a feature request to style the version directives as admonitions. Ironically, the request came from the author of the sphinx-material theme (sphinx-immaterial's ancestor) in which he assumed the version directives were types of admonitions. He isn't wrong, but the fact that the sphinx docs grouped all admonitions in with the version directives (as "Paragraph-level markup") led to the confusion (and he cited the pydata theme's styling of version directives). In resolving the request, I extended the collapsible behavior to the version directives as well. But I had to mandate the version directives had at least 2 directive arguments specified as well as directive content if the |
This makes sense and I am sure we can accommodate this in PST. A couple of thoughts/suggestions (for usability and accessibility)
Ref in PST: https://pydata-sphinx-theme.readthedocs.io/en/stable/user_guide/web-components.html#dropdowns Note that per the issue linked above by Matthias we are making some interaction design improvements (designed not implemented though). |
Thanks for the feedback @trallard, @Carreau, but would these not be theme specific concerns, i.e. these considerations would not change the actual HTML that is written, only the CSS? TBH I kind of feel the chevron is sufficient; |
Yes. This is using the The one difference is that the example here has got the browser-provided outline that PST's example does not have due to sphinx-design providing an |
Yeah that outline none was just changed in the latest Sphinx Design release which messed up with our visible focus indicator. And we yet have to fix. |
The admonition directive and admonition nodes in general allow for any title |
This is true about specific admonitions ( .. admonition:: Important Implementation Details
:collapsible:
:class: important
End-users probably won't know this unless they dig through our source code... @chrisjsewell You kinda beat me to this answer 🤣 But I added the bit about CSS classes |
Ok, you are right. It works for
It's worth documenting / illustrating the |
Yeah we overhauled the admonitions in sphinx-immaterial to allow for a custom title in our added I also think that docutils' generic admonition shouldn't mandate a title at all (a requirement sphinx-immaterial theme has removed), but that's getting off topic.
This tactic might be theme-specific. It depends on how the CSS for a theme is structured. |
Yeh... obviously a bit out of scope for this PR, but basically, these are in essence equivalent: .. note:: Content
.. admonition:: Note
:class: note
Content It's good to have the "shorthand", but indeed I feel there should be a middle ground:
I also don't really get in docutils, why they need to have separate, specific nodes for each admonition type, rather than a single sphinx/sphinx/writers/html5.py Lines 788 to 789 in e439c6f
|
collabsible
option to admonition directivescollapsible
option to admonition directives
yep, apready do this in myst-parser 😉 https://myst-parser.readthedocs.io/en/latest/syntax/admonitions.html#admonition-titles
it would only be theme specific, if they overrode the HTML writer, which I don't really think they should do |
This comment was marked as off-topic.
This comment was marked as off-topic.
Getting back on topic...
Is I'm also interested with what to do about the |
collapsible
option to admonition directivescollapsible
option to admonition directives
# Conflicts: # .ruff.toml # doc/_themes/sphinx13/static/sphinx13.css # sphinx/directives/other.py # sphinx/writers/html5.py
I've resolved conflicts and updated this to use a single This will obviously need a CHANGES entry and ideally tests but I don't know if @chrisjsewell has time to add any -- if not I will add a minimal CHANGES entry. I might like for the arrow to be to the left of the icon rather than all the way to the right, but this is a CSS setting per-theme and so not critical. I've documented that for output formats without support for collapsible content, all the content is included regardless -- I feel this is the most sensible default. Other than this I think this is suitable for merging. Any comments? A |
heya, yeh cheers all cool! |
Ok @AA-Turner added a test and the changelog, so good to go for me 🚀 ok on your end? |
Thanks @chrisjsewell! A |
Thanks for pushing it along! will see if I can give #13220 a look as well |
Thanks @chrisjsewell for opening this and @AA-Turner for driving this to completion! 🎉 |
Look forward to seeing it in furo |
edit: see https://sphinx--12507.org.readthedocs.build/en/12507/usage/restructuredtext/directives.html#collapsible-admonitions, for an example usage and rendering
This PR adds the
collapsible
and option to the core admonition type directives, which are propagated to the nodes, e.g.For the HTML5 writer, this replaces the outer
div
with adetails
tag, and the titlep
with asummary
tag (with anopen
attribute if set), e.g.For all other writers, these attributes are ignored.
I feel this a better alternative to #10532, since:
This would inherently require additions to theme extensions, to correctly style such admonitions.
But I feel this would be worth the effort (and already necessary anyway for #10532),
(in fact, it has already been added in https://jbms.github.io/sphinx-immaterial/admonitions.html#directive-option-admonition-collapsible,
which in-turn mirrors https://squidfunk.github.io/mkdocs-material/reference/admonitions/#collapsible-blocks)
cc @pradyunsg for comment
TODO: tests, documentation, addition of CSS styling to core/docs theme