-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Style: Reduce size of code font and improve responsiveness at narrow screen widths #2439
Conversation
c8b95cc
to
e50d0d7
Compare
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 OK on macOS and Pixel 3.
I've made some further improvements here based on additional feedback on #2437 . See my comment there for more details. |
I agree, changes here generally look good but let's not make the table text smaller, it makes is harder to read. If anything, we should be increasing the font size and whitespace on mobile. Plus smaller text doesn't help for wider tables. For example, the wide table in PEP 594 still affects the whole zoom on the page (Android/Samsung S10/Chrome):
There is a whole bunch of things that can be done to make tables responsive and accessible, but:
As a quick example, Boostrap does this too:
Can we do the same? |
That requires rewriting HTML that is generated by Sphinx (or doing a transform within Sphinx) to wrap the table tag in a div. There's code for that in various Sphinx themes that can be borrowed for this (for Furo's code which reparses the generated HTML, see https://github.com/pradyunsg/furo/blob/812935eee54aeec3ae964647c37f2f18d930c9ec/src/furo/__init__.py#L42). |
Or, that's the only way that I know of. If you know of a better way, please say so here. I'd be more than happy to eliminate an HTML parse of potentially long documents from Furo's rendering step. :) |
Short term: if you want this PR to be CSS only, shall we remove the table shrinking CSS from this PR and do the Furo trick in another PR? Medium term: is it worth asking Sphinx to wrap tables in a div? That would benefit us, Furo users and other Sphinx users. Longer term: when Adam's back we can discuss further improvements in more depth. |
I think it is. I'm not quite sure how Sphinx handles markup changes under their somewhat-strict backwards compatibility model -- but yes, we should totally ask them! I adapted that from what sphinx-rtd-theme is doing so... this would be fairly widely useful. :) |
Well, if we do that, it won't fix the primary issue reported in #2437 , which motivated this PR in the first place, and which the users who reported the issue and tested this seemed to be happy with. As I mentioned above,
It seems to be at least a modest net improvement for the majority of cases for the time being until a followup PR with a longer-term solution is implemented, particularly if we defer the Furo hack, since it will require an extra round of discussion, implementation in and testing to hack a kludge in, as well as additional dependencies, that will almost certainly get ripped back out again when the earlier of A. Adam gets back in a month and we implement it in the HTML translator, or B. Sphinx wraps the table in a div. |
Or instead, how about as a lighter-weight stopgap, we just wrap body tables in a |
Okay, let's try some JavaScript. In general, I think it's better to fix the HTML itself, for those without JavaScript, but hopefully this a temporary thing! |
Yeah, better to fix the HTML on the Sphinx side, but indeed this JS will only be a temporary solution. In any case, I've implemented it as described above (via JS using
Well, FWIW, considering 98% of websites use JS, only around 0.2% of users in 2016 had it disabled at some level, and this is only a non-essential usability enhancement, I'm not sure how compelling that reason is, particularly considering over 10 times that (1.5-3.6%) have browsers ancient enough that don't support the |
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.
Looking good, thank you!
One comment here.
And I found something else needing a break, but I'll raise that separately so as not to delay this any more.
@@ -177,6 +177,11 @@ sup {top: -0.5em} | |||
sub {bottom: -0.25em} | |||
|
|||
/* Table rules */ | |||
div.table-wrapper { | |||
overflow-x: scroll; | |||
scrollbar-width: thin; /* CSS Standards, not *yet* widely supported */ |
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, only supported by Firefox: https://caniuse.com/?search=scrollbar-width
MDN also notes accessibility concerns, scrollbar-width: thin
"can make content hard or impossible to scroll if the author does not provide an alternative scrolling mechanism": https://developer.mozilla.org/en-US/docs/Web/CSS/scrollbar-width#accessibility_concerns
As we're doing this partly for accessibility shall we skip this one?
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, I wanted to be consistent with the other scroll bars (e.g. for the sidebar), but that also uses the illegal, bespoke pseudo-elements to support WebKit/Blink-based browsers, so you're right—best to just eliminate this, fall back on the device-default scrollbars and use overflow-x: auto
instead to automatically hide it when not needed instead of a transparent overlay. I also fixed several other additional existing responsiveness issues I spotted in further testing for this.
8d2fcab
to
9a0d8f8
Compare
I eliminated the poorly-supported, potentially inaccessible scroll bar tweaks as @hugovk suggested, and switched it to
|
Looking good!
Nice, this was the other thing I was going to bring up :) Breaking by word works nicely for URLs too ( https://pep-previews--2439.org.readthedocs.build/pep-0594/ And some PEPs have a lot of footnote text where https://pep-previews--2439.org.readthedocs.build/pep-0465/ The same PEP also has some long URLs in the body, causing a pesky horizontal scroll. Left is PR, right is with |
Hmm, I see. To note, I couldn't reproduce the issue in your screenshots (at least on FF on Windows), except at much narrower widths, because by default links were breaking on To resolve all this, I used (To note, neither of these cases (long links in the body, nor footnotes in general) would be a real problem for new or updated PEPs that followed the current guidance proscribing bare and footnote links in favor of inline links with proper display text, and this rule would be unnecessary.) |
Thanks for all this, I think we're good now! I should have mentioned my screenshots were Chrome/macOS. Yep, good idea to use Here's https://pep-previews--2439.org.readthedocs.build/pep-0465/ on Chrome with mobile layout. ChromeFirefoxSafari
You'll see from the inspector that all three show:
https://caniuse.com/wordwrap shows widespread support. Anyway, fine to keep both if you wish :) |
I'll merge this now, thanks again! |
Wrapping makes the |
Thanks; that makes more sense (at least for the great majority of literal blocks), and I'm not sure why I didn't think of it before. To note, readability is further impaired by that block not having the correct language tag applied, so syntax highlighting doesn't work; I'll go through and fix that separately in a PR for that purpose. I've opened #2463 which implements the suggested solution, using |
#2463 is merged! 🚀 |
Right now, the code font is much larger than the prose font, which varies by platform (due to the former using a system font stack, while the latter uses a web font). As a stopgap solution, to ensure 79 characters fit on a line under all but the most constrained screen resolutions, and reduce the perceptible size difference between the prose and code fonts while making it more motivated, this PR follows @pradyunsg 's suggestion reduce the code font size to something similar to what Furo uses, 0.875rem/14px as was suggested and discussed there, until we decide on a final resolution to the font stack issue.
Furthermore, as also suggested by @methane on #2347 , it allows code blocks to break by letter than than by word, resolving formatting issues at narrow screen widths and matching the behavior of most editors/IDEs (while ensuring inline code breaks cleanly).
Resolves #2437
Resolves #2449