-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Support type-dependent search result highlighting via CSS #12474
Conversation
background-image: url(file.png); | ||
background-repeat: no-repeat; | ||
background-position: 0 7px; | ||
list-style: "\25A1"; /* Unicode: White Square */ |
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.
I wonder whether it might make sense to be slightly more explicit and define these using the CSS list-style-type
property?
Also, to check: is the white-square default here intended to highlight cases where sites have upgraded their Sphinx CSS but not rebuilt their searchindex.js
?
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.
I'm not a CSS expert. I was anticipating that list-style
is easier to override for downstream themes, e.g. list-style: url(image.svg)
, but just a guess. If you say list-style-type
is better, I'm happy to change.
I've added the empty square as a catch-all fallback; e.g. could be that somebody rewrites search and includes a new type, but forgets the corresponding CSS. Likely other things can happen and the empty square as as placeholder is better than nothing.
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.
I'm not a CSS expert. I was anticipating that
list-style
is easier to override for downstream themes, e.g.list-style: url(image.svg)
, but just a guess. If you saylist-style-type
is better, I'm happy to change.
Me neither, and your intuition may be correct. I based my suggestion on a sense that list-style-type
is slightly less ambiguous (list-style
does accept the same values, but can also be set to an image URL), and also a small note on the Mozilla MDN page:
The
list-style
property is specified as one, two, or three values in any order. Iflist-style-type
andlist-style-image
are both set, thelist-style-type
is used as a fallback if the image is unavailable.
I've added the empty square as a catch-all fallback; e.g. could be that somebody rewrites search and includes a new type, but forgets the corresponding CSS. Likely other things can happen and the empty square as as placeholder is better than nothing.
That makes sense. A concern I have with it is that the same (or a similar) symbol is used on some systems when a unicode codepage/symbol is not found in the relevant font, and that could make problems slightly trickier to track down. Perhaps we could set the value to initial
(initial browser default)?
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.
A concern I have with it is that the same (or a similar) symbol is used on some systems when a unicode codepage/symbol is not found in the relevant font
Our assumptions in the HTML search is that the user has a modern browser, and hence we should be confident in using Unicode -- every modern browser is able to display emoji, etc.
ul.search li.title { | ||
list-style: "\1F4C1"; /* Unicode: File Folder */ | ||
} |
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 is the only annotation symbol that I find slightly confusing / out of context, personally.
It does sorta logically fit that it's for use to represent that titles are 'containers' in some sense for text content.
I'm browsing unicode character references to try to find something else that could represent text/documents, headings/titles, and/or the potential for containership/nesting.
Edit: remove repetitive phrasing
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 it's a controversial misuse, but perhaps the paragraph symbol (called Pilcrow, as I learned today)?
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.
(or we could try to bring the capitulum back into style)
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.
Another alternative could simply be to style title
and text
matches identically to begin with.
I'll try to spend a bit more time thinking about this before adding any further thoughts/comments.
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.
The idea behind folder was "structuring element" but I'm not too convinced of it either.
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.
On reflection: I'd recommend keeping this simple, and using the same styling for both title
and text
search results - that is, 1F4C4
(unicode: page facing).
We could still emit the CSS classes title
and text
in the result list, allowing downstream sites to customize their display to suit their projects if they choose.
Some reasoning for this suggestion: with a default Sphinx configuration and HTML build, it is possible to infer from each listed search result whether the input search query term(s) matched in the corresponding document's title and/or content body. In my personal opinion it is a nice addition to be able to distinguish between glossary items and programming objects, but seems lower priority to distinguish page title matches from other page content matches.
This comment was marked as resolved.
This comment was marked as resolved.
Maybe nitpicky: the horizontal margin/padding between the icons and the search result titles has increased; is there a way to reduce that back to near the original spacing? |
Might be interesting to see how this works with some popular themes e.g. furo, readthedocs, and sphinx-book-theme. I suspect it'll look fine but can't hurt to double check. |
Good point. They all set That may be ok, but still we're pushing unexpected styling, and e.g. the spacing is too narrow for furo. The alternative would be only to implement the class now, and change the CSS later, which gives downstream more time to react. |
Alternative idea:
What do you think? |
If we roll the theming out 'centrally' (in the If we roll out only the HTML class names, my guess is that many themes will not notice or react to the possibility to style these elements -- that's fine, but I do think that there is a genuine user-facing improvement possible here. I also think that there's some risk -- but also some opportunity -- if fragmentation of result icon theming occurs. In either scenario I'd be hopeful for some future requests for additional class names / tweaks to improve the categories further. I don't have a strong preference either way yet; just trying to consider the likely outcomes at the moment. One other thought: the |
From the themes listed at https://sphinx-themes.org/, I pulled the GitHub stars as a proxy measure of usage. ~10 themes cover most of the user space. So the amount of impact is managable either way: If we supply icons by default, we can check them. If we only provide classes, we can notify them that they could do styling. From the top 7 themes only Alabaster and Bootstrap keep the original search result styling. The others have chosen to explicitly style the result themselves (often just using Conceptually, I find it attractive to include as little styling as possible in the basic theme. It should give the structure, appearance should be handled by the derived themes. Us putting icons into basic makes it potentially harder for them. I believe my proposal above minimizes negative impact. |
@timhoffm Thanks for providing that contextual data. I'm mostly in agreement with your suggestion about leaving the basic theme as-is - providing a gradual opt-in approach seems sensible. An aspect I'm puzzling over is whether we should be even more cautious about affecting downstream, and not remove the Yet one more thought: the choice of tag names does seem important, as you highlighted originally. In particular |
I think that was too cautious and hesistant/change-resistant of me. I'm not an accessibility expert but I would expect that the |
b4affb1
to
0ac6880
Compare
I've changed the basic theme to not have any styling. The effect can be seen as follows at the example of alabaster, which uses the default settings for search: old / new: The sphinx13 theme still got the icon styling. I plan to provide a PR for that on alabaster as well, once this PR is merged.
IMHO we anyway need |
+1 to this approach (applying the change to the project's own documentation theme first / milling our own grain) |
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.
Looks good to me - thanks @timhoffm!
Ah, one more thing @timhoffm - I always forget this - please could you add an entry to the |
Co-authored-by: James Addison <55152140+jayaddison@users.noreply.github.com>
I'm taking a pause here @timhoffm - I'll try to continue this review (and to actually test the suggestions I'm making before adding them, when doing that) later today or tomorrow. |
I personally find PRs with "merge master into feature" more difficult to review, because you mix irrelevant changes from main into the feature code. Therefore, I typically rebase. But if you prefer merges, I can do that as well. Would be good to mention this in the Contributing docs if you have preferences for a specific workflow. |
@jayaddison Thanks for the review! Feel free to directly push any changes. I feel, I've done all that I can for this PR, and in particular if it's JavaScript, I won't be any help. |
@jayaddison at some point, let me know when you're happy with this PR and/or what your outstanding concerns are. This will go into 8.1. A |
You're welcome @timhoffm - please note that I don't have committer rights here, so I can't push to the branch, but I may add a few more suggestions when ready, or open a pull request on your fork of the repo.
Ok, thank you @AA-Turner. The three remaining items I have in mind are:
|
Thanks. I'm minded to merge this as-is and potentially we can tackle those points in follow-ups, given none seem blockers to the feature itself? If you'd prefer that this PR stay open though, no worries. A |
I don't think they're worth considering as blockers either, merging is fine with me 👍 |
# Conflicts: # CHANGES.rst
🎉 thanks @timhoffm @AA-Turner! |
Something seems to be off: https://www.sphinx-doc.org/en/master/search.html?q=directive Note every result is "White Square"... A |
Has there been a change to the search results meanwhile? They seem to be grouped now: All glossary entries (directive, master document, object) are together, all entries on a page are together, ... I will check in more detail, but that will take a week. |
Perhaps @wlach or @jayaddison might know? A |
@AA-Turner @timhoffm it's worth noting that the That probably explains why the results don't have any |
One more note: inspecting the HTML, I noticed that we already use the term
My apologies for not noticing that during the discussion about what to name the type/kind/context classname. I now feel that we should disambiguate the two (and we do still have time to do that, since this change is not-yet-released). I think |
Edit: Summary (Update: 25.07.2024)
This adds result type-dependent HTML classes to the
<li>
elements of the search result list. Implemented types / classes are:context-index
: If the search term is found in an index such as the glossarycontext-object
: If the search term a code object such as a python functioncontext-text
: If the search term is found in plain documentation textcontext-title
: If the search term is found in a headingThe basic style intentionally does not apply styling to these classes to not interfere with derived themes. We encourage theme authors to apply suitable styling to the results list via CSS as they see fit. Check
sphinx13.css
in this PR as an example.It's helpful to visually distinguish different content types.
This PR adds
context
to the javascript result entries (one of "title", "index", "object", "text" - please check that these names make sense, I've inferred them from the JS context) and adds them as a class to the<li>
item in the result list. This allows styling via CSS.For simplicity, I've styled with unicode symbols, which should give a decent look without the need to ship our own symbols. Derived themes have the ability to adapt this via CSS and use their own icons if they want to.
Before / after: