-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
rustdoc options to set default theme (and other settings) #77213
Conversation
Some changes occurred in HTML/CSS/JS. |
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @GuillaumeGomez (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
ping @GuillaumeGomez |
You added the |
c50bb7b
to
ab195aa
Compare
Hi. Thanks for the review. I have made those changes. I rebased onto current master, and then made the requested changes as new commits, for ease of your review (and as requested by the highfive bot). I did them as git autosquash, and when you're happy with the series, will squash it down. |
☔ The latest upstream changes (presumably #77809) made this pull request unmergeable. Please resolve the merge conflicts. Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels:
|
As requested, I did this. Unfortunately it didn't get a review before some other changes went in which conflicted. By its nature, the change to use (FTR obviously I approve of #77809 and it should work well in combination with my work in this MR.) |
Joshua Nelson writes ("Re: [rust-lang/rust] rustdoc options to set default theme (and other settings) (#77213)"):
@ijackson is this PR still needed after #77809 ? It seems like #77024 should be
fixed by setting your system theme to the default that you want.
No, I'm think this is still wanted. Honouring prefers-color-scheme is
good but:
* It is not available except on fairly recent browsers
(caniuse.com says eary-to-mid 2019).
* It is suppressed by "privacy.resistFingerprinting" [1]
* It does not address the use case of a shared site-wide default, for
the person running rustdoc to generate docs for their community.
* My series allows setting other preferences too which might well be
useful.
So I intend to rebase this, assuming that it is likely to be accepted.
Thanks,
Ian.
[1] https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme
…--
Ian Jackson <[email protected]> These opinions are my own.
Pronouns: they/he. If I emailed you from @fyvzl.net or @evade.org.uk,
that is a private address which bypasses my fierce spamfilter.
|
Please rebase to fix merge conflicts then ping me and I'll review again (but it seems mostly good already). |
Currently, storage.js and main.js have many open-coded calls to getCurrentValue for "rustdoc-" values, but these are settings and should be handled by getSettingValue. So make getSettingValue part of storage.js (where everyone can call it) and use it everywhere. No functional change yet. We are going to make getSettingValue do something more sophisticated in a moment. Signed-off-by: Ian Jackson <[email protected]>
rustdoc has various user-configurable preferences. These are recorded in web Local Storage (where available). But we want to provide a way to configure the default default, including for when web storage is not available. getSettingValue is the function responsible for looking up these settings. Here we make it fall back some in-DOM data, which ultimately comes from RenderOptions.default_settings. Using HTML data atrtributes is fairly convenient here, dsspite the need to transform between snake and kebab case to avoid the DOM converting kebab case to camel case (!) We cache the element and dataset lookup in a global variable, to ensure that getSettingValue remains fast. The DOM representation has to be in an element which precedes the inclusion of storage.js. That means it has to be in the <head> and we should not use an empty <div> as the container (although most browsers will accept that). An empty <script> element provides a convenient and harmless container object. <meta> would be another possibility but runs a greater risk of having unwanted behaviours on weird browsers. We trust the RenderOptions not to contain unhelpful setting names, which don't fit nicely into an HTML attribute. It's awkward to quote dataset keys. Signed-off-by: Ian Jackson <[email protected]>
We just plumb through what the user tells us. This is flagged as unstable, mostly because I don't understand the compatibility rules that rustdoc obeys for local storage data, and how error handling of invalid data works. We collect() the needed HashMap from Vec of Vecs of (key, value) pairs, so that there is a nice place to add new more-specific options. It would have been possible to use Extend::extend but doing it this way ensures that all the used inputs are (and will stay) right next to each other. Signed-off-by: Ian Jackson <[email protected]>
This is a fairly simple special case of --default-eetting. We must set both "theme" and "use-system-theme". Providing it separately enables us to document a way to set the theme without expoosing the individual settings keywords, which are quite complex. Signed-off-by: Ian Jackson <[email protected]>
ab195aa
to
709efd9
Compare
Now done, thanks. I made some slight improvements to the Rust parts so you may want to re-review them. |
Just nits on my end. Maybe you want to take a last look @jyn514 too? |
Hi, thanks for the prompt review.
+ .map(|(k, v)| format!(r#" data-{}="{}""#, k.replace('-', "_"), Escape(v),))
Small nit: I think that the extra comma at the end is unnecessary. ;)
I think that used to be before a newline but rustfmt deleted the
newline. I'll get rid of the comma...
+ "Set the default theme. THEME should be the theme name, generally lowercase. \
The usage of the double whitespace is bugging me a lot. Is there a reason
behind it?
That's what I was taught in school on a manual typewriter :-). I am
happy to change it.
Would you like a new commit on top to address these nits, or amendment
and force push ?
Ian.
…--
Ian Jackson <[email protected]> These opinions are my own.
Pronouns: they/he. If I emailed you from @fyvzl.net or @evade.org.uk,
that is a private address which bypasses my fierce spamfilter.
|
In this case it's fine, you're still under the "rebase bar". :p Just push another commit to fix the nits. |
* Remove a needless comma in the Rust code * Replace double spaces after full stops with single spaces Requested-by: @GuillaumeGomez Signed-off-by: Ian Jackson <[email protected]>
@GuillaumeGomez Done, thanks. |
All good for me. Just a last check from @jyn514 and then it's good to go! |
unstable("default-theme", |o| { | ||
o.optopt( | ||
"", | ||
"default-theme", | ||
"Set the default theme. THEME should be the theme name, generally lowercase. \ | ||
If an unknown default theme is specified, the builtin default is used. \ | ||
The set of themes, and the rustdoc built-in default is not stable.", | ||
"THEME", | ||
) | ||
}), |
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.
Why is default-theme special cased? If you want default-settings
to work for arbitrary settings, I think it makes sense to use it for themes too. If you want this to be documented, I would rather document settings in the unstable section of the rustdoc book (src/doc/rustdoc/src/unstable-features.md
).
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 would also be ok with getting rid of default-settings
and only keeping default-themes
.)
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 storage names are rather internal, and --default-setting
sets them directly. That's good for flexibility but it is rather too raw.
Indeed, as you can see from the implementation, --default-theme
doesn't just set the theme
setting. Because of the way the "use system theme" option and the light/dark themes operate, since #77809, it is necessary to change the default for "use system theme" to "false" for the --default-theme
option to work.
Indeed, I think this fact about #77809 shows that my pre-#77809 approach of having a raw --default-setting
option, and a cooked --default-theme
option, was correct. Before #77809, --default-theme
just set the theme
setting. Now it does more.
Notice that the stability caveats for the two options are rather different. Another aspect of this is that it might easily make sense to stabilise the --default-theme
option soon, after we've had some experience with it. Stabilising the raw --default-setting
option would involve thinking about what additional promises that would imply (maybe none that we care about? but I'm not sure and it's certainly harder to think about)
.flatten() | ||
.collect(), | ||
matches | ||
.opt_strs("default-setting") |
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.
One more thing that --default-theme
breaks is you now have different behavior for --default-theme x
and --default-setting theme=x
- the first will set use-system-theme=false
, the second will not.
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.
Yes. That is inevitable and deliberate. As you can see from the usage message we do not make any promises about the particular behaviour of --default-setting
. The available settings and their semantics and not documented and not stable.
Whereas the semantics of --default-theme
are well-defined, and are implemented by setting the two internal settings.
I do think it is worth keeping --default-setting
even despite these caveats because in practice the storage settings are visible to users via their browser and of course if they look at the JS.
The difference between --default-setting
and --default-theme
is like the difference between firefox's about:config
and about:preferences
.
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 guess my question is why you would ever want to modify default-setting
. All those settings are also configurable on a per-user basis on settings.html
- do we really need so much flexibility as to make the 'default defaults' configurable too?
Co-authored-by: Joshua Nelson <[email protected]>
This allows removing a `mut` which is nicer. Suggested-by: @jyn514 Signed-off-by: Ian Jackson <[email protected]>
I guess my question is why you would ever want to modify default-setting. All
those settings are also configurable on a per-user basis on settings.html - do
we really need so much flexibility as to make the 'default defaults'
configurable too?
The reasons I gave for the default theme here:
#77024 (comment)
apply to all of these default options too. The same reasons motivate
many of rustdoc's options, such as `--theme`, `--extend-css`,
`--index-page`, etc. etc. etc.
…--
Ian Jackson <[email protected]> These opinions are my own.
Pronouns: they/he. If I emailed you from @fyvzl.net or @evade.org.uk,
that is a private address which bypasses my fierce spamfilter.
|
@bors r=jyn514,GuillaumeGomez In practice I don't expect |
📌 Commit 776e204 has been approved by |
In practice I don't expect --default-settings to be used often, but
since it's perma-unstable I'm ok with adding it. --default-theme
definitely seems like a good improvement.
Thanks. I will probably propose stabilising --default-theme after
it's had a chance to bed in. Many of the other options which interact
with details of the CSS are already stable.
Ian.
…--
Ian Jackson <[email protected]> These opinions are my own.
Pronouns: they/he. If I emailed you from @fyvzl.net or @evade.org.uk,
that is a private address which bypasses my fierce spamfilter.
|
Rollup of 11 pull requests Successful merges: - rust-lang#77213 (rustdoc options to set default theme (and other settings)) - rust-lang#78224 (min_const_generics: allow ty param in repeat expr) - rust-lang#78428 (MinConstGenerics UI test for invalid values for bool & char) - rust-lang#78460 (Adjust turbofish help message for const generics) - rust-lang#78470 (Clean up intra-doc links in `std::path`) - rust-lang#78475 (fix a comment in validity check) - rust-lang#78478 (Add const generics tests for supertraits + dyn traits.) - rust-lang#78487 (Fix typo "compiltest") - rust-lang#78491 (Inline NonZeroN::from(n)) - rust-lang#78492 (Update books) - rust-lang#78494 (Fix typos) Failed merges: r? `@ghost`
As discussed in rust-lang#77213, this seems like it has bedded in and can be safely and usefully made stable. (rustdoc already has other stable options that interact quite intimately with the rustdoc-supplied CSS, and also an option for supplying entirely different CSS, so exposing the theme names this way seems a very minor step.) Signed-off-by: Ian Jackson <[email protected]>
rustdoc: stabilise --default-theme command line option As discussed in rust-lang#77213, this seems like it has bedded in and can be safely and usefully made stable. (rustdoc already has other stable options that interact quite intimately with the rustdoc-supplied CSS, and also an option for supplying entirely different CSS, so exposing the theme names this way seems a very minor step.) There is also a commit to do some minor grammar fixes to the help message.
Hi. This is the MR I promised in #77024
It is a little more general than I envisaged there. Once I had found the settings-handling machinery it seemed foolish to add this feature just for the theme.
Closes #77024