-
Notifications
You must be signed in to change notification settings - Fork 32
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
Resolve roles in navigation #56
Comments
@2bndy5 can probably address the content tabs better than I can. As far as the toc, I'm not sure if the :caption: is normally supposed to contain rST or if it is intended to be plain text. If the latter we might not want to change the meaning, at least by default, to avoid an incompatibility with other sphinx themes. We might instead want a way to explicitly opt in. Separately, though, page/section titles can contain rST and normally in sphinx that does result in styling of the sidebar toc. I intentionally converted all titles to plain text when generating the navigation because I think in many cases it is preferable not to have special styling in the toc. For example if you have a literal block in a title, I think it can look strange to have the literal styling in the toc. It is also tricky to define css rules so that things like literal styles display in a reasonable way inside the yoc. But I can see how icons could be desired and wouldn't have as many difficulties. I'm certainly open to suggestions for how to improve things. |
I agree that literals in a TOC (eg, classes/functions in an API reference) could be ugly. I'm not so worried about the inline literal case. When discovering I couldn't inline However, the octicons would be nice to add IMHO. I would be happy with adding an exception (or special processing) to only enable |
I can try to fix the content tabs so that inline RST roles should work. There may be some roles that you shouldn't need to use in the labels for a content tab (like a If they ever get around to publishing the next release, sphinx-design will have 10000+ inline icons from the Google material icon fonts repo. I submitted this feature hoping we could use it abusively, like using an inline icon in a page's header title (that would hopefully show in the main nav menu also). |
I was able to get the roles parsed properly when treating the raw text as a separate paragraph. This results in a automatic current working patchfrom sphinx-immaterial/sphinx_immaterial/content_tabs.py Lines 92 to 98 in f925a44
into from docutils.statemachine import StringList
# add tab label
tab_label = nodes.rubric(self.arguments[0], classes=["tabbed-label"])
label_text = StringList(initlist=[self.arguments[0]])
self.state.nested_parse(label_text, self.content_offset, tab_label)
self.add_name(tab_label)
tab_item += tab_label This new CSS rule fixed the label.tabbed-label > p {
margin: 0;
} |
Instead of using
|
That's what it is using now; it doesn't seem to handle parsing roles. unless I appended the children improperly somehow. |
I'm also looking into a way to strip the |
I do believe |
Actually I'm rather confused --- roles already seem to work fine with content tabs: .. md-tab-set::
.. md-tab-item:: Customized content ``n = 4``
:class: custom-tab-item-style
This content could be styled differently from other page content.
.. md-tab-item:: Custom CSS :math:`n = 3`
.. literalinclude:: _static/extra_css.css
:language: css
:start-at: /* *********************** custom-tab-item-style
:end-before: /* ************************* inline icon stuff
|
That's what I thought as well, but I was able to reproduce the issue (not using main branch right now though). |
Maybe it depends on the sphinx or docutils version? |
I was using Sphinx 4.4.0 and docutils 0.17.1 |
I didn't know sphinx allowed anything newer than docutils v16 |
I'm using docutils 0.17.1 with sphinx v4.4.0. I'm switching to main to see if it reproduces there. |
If you add There does indeed appear to be a bug though in the case that the label starts out with a special role. |
yep. just realized that as well. I wonder if we pad the text with whitespace, then we might get the proper structure. |
We shouldn't have to pad with whitespace --- I think the first docutils node is getting converted to a string, which is why we are seeing the docutils markup |
The bug is actually in these two lines:
For docutils nodes that inherit from TextElement, the first argument to Therefore, the first child is getting interpreted as text in both places. Adding an extra |
I took a peek at nav_adapt.py (the code that assembles the ToCs), and it looks like most of the code was designed around using plain text for section titles. I don't think it will be an easy 1-2 line fix. [EDIT] BTW, inline literals don't look that weird. I'm rather used to seeing a mix of monospace fonts with regular fonts in the side nav of other themes, namely the rtd-theme. |
Yeah, In normal use Sphinx ends up calling I worked around that issue by monkey patching In fact I didn't even notice the The solution I implemented was to ask Sphinx for the TOC just once, convert it to an internal format, and then for each page quickly extract just the portion we need. One tricky thing is that normally Sphinx converts the page references to relative URLs as part of the TOC generation, but that is problematic since we will be re-using the same TOC docutils representation for all pages. That requires manually fixing up the relative URLs in We would have to see how we can make rendering the title as HTML fit with this optimization --- in most cases the HTML would be identical, but it is possible that the title itself could contain a link to another page, which would get rendered as a relative URL. Though maybe we can ignore that issue since it is kind of weird to have a separate link within a TOC title. I will try to bring over these fixes as PRs today so that they aren't just piling up on my end. |
If a ref link is present in a toc title, then I would be surprised if clicking the link within the displayed toc will actually have an effect. |
I don't think there is anything that prevents those referenced being turned into There is a better example than a |
* patch literal blocks captions; add result directive * update docs for results directive * add task-list directive and keys role * add experimental button idea * add in new demo CSS * pleasing pylint * ran black on button.py * partial solution to content tabs in #56 * improve api doc signatures and code block captions * pleasing stylelint * pleasing pylint * polish & remove experimental button.py - CSS additions consolidated and revised - result directive (and corresponding CSS) - various improvements to the docs * pleasing stylelint * still pleasing stylelint * hopefully the last stylelint fix * [stylelint] WTH is with property ordering in scss * adjust custon keys' CSS for chrome * remove button testing CSS * use descrptive directive name * use snake casing for docutils node * move a margin reset to typeset.scss * review changes to kbd_keys.py * use plain text for keys role in latex * simplfy example CSS for custom task-list * move rst-result CSS to _highlight.scss * wrap each param in span & style said span * [no ci] move comment to proper location * condensed selectors = less deviation from upstream * set autocrlf to input * try overriding git global config for this repo * override config for all files (not by core config)
I took a swing at letting @jbms Can you think of an objection to using This feels hacky because it is focused solely on letting SVG glyphs be part of the title in the nav menu. example.. in admonitions.rst
:material-regular:`warning` Admonitions
======================================= I had to use python's |
One question is whether it is always desirable to allow rST styling to apply to the navigation as well --- for example, if some portions use a literal or code role, do we want those styles (e..g font and possibly color) to also apply to the navigation, and if so, how do we ensure that the CSS rules properly interoperate with the CSS rules for navigation items. The other question is for the specific case of icons, is it actually desired to have the icon present in the header (e.g. Regarding the implementation of using We should just test to see how expensive this is --- when generating API documentation, the total number of navigation items can be quite large, and we don't want to spend an excessive time rendering the navigation. Sphinx 5 significantly optimized I think rather than parsing the HTML to add back in wbr, it would be better to modify the HTMLTranslator to just add wbr when translating text nodes in the first place. Another alternative would be to use a custom HTML translator that only supports a limited set of docutils nodes, and just converts everything else to text. |
I just realized the metadata tag approach won't work with |
Another option would be to introduce a custom role for specifying the nav icons that generates a docutils node type that we will ignore when rendering the section headings but is handled when generating the nav labels. Could also be a custom directive to specify an icon for the current section. |
I kinda like that idea because then users could put it in other places like paragraphs. Compared to sphinx-design, maybe we could support a CSS class (optional and separated by a semi-colon), so they could further adjust the color or animated it. I'm picturing something like: :md-icon:`material/document`
:md-icon:`material/document;custom-class` Where the role arguments would be a path to the icon (required) [and custom CSS class]. |
We may have to regex the icon in |
Seems to me that this is the only way to support icons in the toctree caption because Sphinx' visitor for |
Hey guys. Just wanted to check in on this issue. Any chance we can make this possible? I think it would add a lot of flair to the websites! ✨ As always, very appreciative of your work here! |
I've become focused on only allowing an icon (like our new |
That is a good point --- I did not think about that. For page titles, Sphinx by default preserves markup and this theme specifically strips it and renders them as text only, unlike other themes. However, toctree captions are indeed text only in Sphinx. I think there are a few possible solutions:
Also of note, mkdocs-material-insiders has some new features related to this, including the "typeset plugin" (https://squidfunk.github.io/mkdocs-material/reference/#built-in-typeset-plugin) which is exactly the feature requested here. While this plugin would not be relevant to Sphinx and we can't make use of the mkdocs-material-insiders code, I think it could make sense to take it into account in coming up with a more comprehensive plan for what options we want to provide in sphinx immaterial. |
I was aiming for option 2 a while ago, but the millennial in me would settle for option 1 (for a more instant gratification). |
Seems fine since it is a subset of the work for option 2. Option 2 should also be pretty easy to implement. |
I was able to do this by supporting roles in the section headings while maintaining the needed
I tried doing this without monkey patching the
I also tried implementing the In a side note, I think the support for roles in section headers is a more stable approach due to the way the ToCs are extracted (seems deep-copied) from a cache when nav_adapt.py handles the html-page-context event. Not to mention, roles in section headers is how this is supported for every other Sphinx theme I've ever used. |
Upstream seems to have added page icons in v9.2.0 (no longer an insiders feature). |
I noticed that Sphinx roles are not applied in the navigation tab or content tab headings. Is there anything we can do about that? Is there a way to run a Sphinx role processor on the the titles or captions?
Content tabs
Here I tried to add an inline literal to a content tab heading. I also tried to add an octicon from the
sphinx-design
extension.Potentially the octicon did get converted to a SVG but isn't displaying as such?
renders as
HTML
Navigation tabs
Here I tried to add an octicon to a navigation tab, but it didn't render as expected.
renders as
HTML
The text was updated successfully, but these errors were encountered: