-
Notifications
You must be signed in to change notification settings - Fork 317
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 custom and collapsible admonition functionality #1124
Comments
If we want to do this, I wonder if this would be possible to use with our new HTML translatormixin stuff @12rambau ? It's a slightly different way of doing it than immaterial does, but seems more in-line with our setup here. |
I think we could, but we can also override the Admonition directive entirely (maybe easier). That being said isn't the collapsible admonition already part of sphinx-design ? I'm already using it here: https://docs.sepal.io/en/latest/ .. note::
:class: dropdown
toto Also I would advocate in favor of a small extension, that would be beneficial to any sphinx theme. |
In regards to sphinx-immaterial theme (which is a port of the mkdocs-material theme), the details/summary elements are styled under the assumption that they are indeed admonitions. This restraint is actually born from the mkdocs' plugin that implements admonitions; support for details/summary elements was patched into that implementation later. So, in sphinx-immaterial, we could not use CSS specific to details/summary elements that weren't used for admonitions because it resulted in visual bugs due to conflicting CSS, and altering our theme's CSS would deviate too much from the mkdocs-material theme's CSS (which we inherit). Consequently, this led to monkeypatching sphinxcontrib-details-directive (which doesn't respect the |
@12rambau EDIT: This uses sphinx-togglebutton, not sphinx-design. |
A few quick thoughts: How their implementation works (I think)It looks like they accomplish this by defining their own admonition directive that allows for extra options like and then they override the Sphinx admonition python class that is returned somewhere around here: and that lets them add the extra options + monkeypatch the HTML admonition writers etc without raising errors for "unknown options" in Sphinx. Sphinx-togglebuttonYep - right now the support of I think that Footnotes
|
Yep, you nailed it. I only have 1 note though:
This happens when the module is imported. So, technically it doesn't matter if the users actually utilize the feature or not (we have options to disable the default overridden admonitions); the monkeypatch is still applied. That's why I wrote the the monkeypatch to still behave as originally intended when no custom-added options are used. A few less commented dev tribulations:
PS - Your footnote is the reason I didn't bother suggesting the |
regarding the collapsible admonitions: sphinx-design (which we already depend on) has "dropdowns" with built-in support for the standard semantic color names: https://sphinx-design.readthedocs.io/en/pydata-theme/dropdowns.html#dropdown-options An example from MNE-Python docs (near the bottom of the page): https://mne.tools/stable/install/check_installation.html Done like this: .. dropdown:: If you get an error...
:color: danger
:icon: alert-fill
Content goes here re: defining their own admonitions, I can see the value there, the "legacy" example in the sphinx-immaterial docs is convincing. But I'd consider this low priority (vs, say, sphinx 6 compatibility), since it's already possible in plain sphinx to write
and then write a little custom CSS to style the |
Sometimes, forcing the user to learn CSS may be a bit demanding. |
like I said, the "legacy" example in your docs is convincing as a use case. I'm on board that it would be nice to provide this. What I'm arguing is that this should be back-burner for now; it doesn't seem as urgent as some other things currently on our plate. |
I agree with your priority preference. Thankfully, for us the sphinx v6 support was a mere matter of typing. |
I worked around the requirements set-up by @choldgraf and my conclusion is that we should do nothing but a documentation update if people are really wanting to do it. everything needed is already in the wild: collapsibleadd .. note::
:class: dropdown
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum sit amet augue vitae metus egestas fermentum. Nam hendrerit in purus in scelerisque. Sed auctor neque lacus, at porttitor lectus ornare vitae. Vestibulum pretium vel turpis a placerat. Nullam mattis mi dapibus, malesuada mauris ac, luctus lectus. Morbi ac tincidunt velit. Quisque porta leo egestas ex bibendum, in dignissim dui fringilla. Nulla facilisi. Ut non mollis urna. Mauris felis ante, malesuada et tellus nec, accumsan condimentum eros. Fusce commodo placerat elit, in bibendum massa. Donec quam tellus, lacinia a libero non, viverra luctus risus. change titleto change the title, as explained in Sphinx doc, use the standard admonition: .. admonition:: Aknowledgement
:class: dropdown
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum sit amet augue vitae metus egestas fermentum. Nam hendrerit in purus in scelerisque. Sed auctor neque lacus, at porttitor lectus ornare vitae. Vestibulum pretium vel turpis a placerat. Nullam mattis mi dapibus, malesuada mauris ac, luctus lectus. Morbi ac tincidunt velit. Quisque porta leo egestas ex bibendum, in dignissim dui fringilla. Nulla facilisi. Ut non mollis urna. Mauris felis ante, malesuada et tellus nec, accumsan condimentum eros. Fusce commodo placerat elit, in bibendum massa. Donec quam tellus, lacinia a libero non, viverra luctus risus. to get this: change the color and the titleall th coloring and iconing of the admonitions is piloted from their classes so add the admonition classname you want to mimic: .. admonition:: Aknowledgement
:class: dropdown warning
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum sit amet augue vitae metus egestas fermentum. Nam hendrerit in purus in scelerisque. Sed auctor neque lacus, at porttitor lectus ornare vitae. Vestibulum pretium vel turpis a placerat. Nullam mattis mi dapibus, malesuada mauris ac, luctus lectus. Morbi ac tincidunt velit. Quisque porta leo egestas ex bibendum, in dignissim dui fringilla. Nulla facilisi. Ut non mollis urna. Mauris felis ante, malesuada et tellus nec, accumsan condimentum eros. Fusce commodo placerat elit, in bibendum massa. Donec quam tellus, lacinia a libero non, viverra luctus risus. to get this: change title, color and iconIn short you want to customize everything. You are a very advanced user, don't take me for a fool you know where the div.admonition.toto {border-color: olive;}
div.admonition.toto > .admonition-title:before {background-color: olive;}
div.admonition.toto > .admonition-title:after {color: olive; content: "\f24e"} this create a new .. admonition:: Aknowledgement
:class: dropdown toto
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum sit amet augue vitae metus egestas fermentum. Nam hendrerit in purus in scelerisque. Sed auctor neque lacus, at porttitor lectus ornare vitae. Vestibulum pretium vel turpis a placerat. Nullam mattis mi dapibus, malesuada mauris ac, luctus lectus. Morbi ac tincidunt velit. Quisque porta leo egestas ex bibendum, in dignissim dui fringilla. Nulla facilisi. Ut non mollis urna. Mauris felis ante, malesuada et tellus nec, accumsan condimentum eros. Fusce commodo placerat elit, in bibendum massa. Donec quam tellus, lacinia a libero non, viverra luctus risus. tadaaam: themingIf you want to change the color of the icon, and its value and makes it different for the light and dark theme, set up some css variables. be aware that you go in poor design territory but you can do something like: html[data-theme=dark]{
--color-crazy: pink;
--icon-color-crazy: blue;
--icon-crazy: "\f6be"; /* fa-cat */
}
html[data-theme=light]{
--color-crazy: blue;
--icon-color-crazy: pink;
--icon-crazy: "\f6d3"; /* fa-dog */
}
div.admonition.crazy {border-color: var(--color-crazy);}
div.admonition.crazy > .admonition-title:before {background-color:var(--color-crazy);}
div.admonition.crazy > .admonition-title:after {
color: var(--icon-color-crazy);
content: var(--icon-crazy);
} and light will look different from dark: conclusionto fix or not fix ? |
👍🏻 for a docs-only solution to this. Maybe we need a new docs page/section called "extending the theme" and this would have a part called "adding custom admonitions". Providing people a copy-pastable CSS example will go a long way I think |
I'm +1 on a docs solution as well. I do wish that the UX around admonitions would improve in sphinx, but I guess that is not our problem to solve :-\ I still think it's nuts that I can't do
😭 |
agreed but we'll need to wait for sphinx 7 or that ;-) |
There are two ways that people often request changing admonitions:
.. example::
and have it re-use thetip
style")There are a few examples of each in the wild, but I recently discovered that the Sphinx Immaterial theme has nice support for both "custom admonitions" and for "collapsible admonitions".
I think it would be great if this theme supported the same functionality, ideally by following the exact same patterns they do so that we do not introduce too many new ways for people to do things. (note that these patterns are also both based on mkdocs-material so this particular API / syntax / etc is already supported in many places.
I opened an issue asking if they'd be interested in turning this into a standalone extension, but I also think it would be easy to just copy their admonitions module, give them credit, and implement it in this theme.
The text was updated successfully, but these errors were encountered: