-
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
Add syntax extension to add warning blocks #79710
Comments
Personal Opinions:
Which to me pushes the text too far right. Not having any spacing, but just separating with newlines, seems hard to parse at a glance what is part of the WARNING, and prevents multiple line breaks inside the warning. Also, it's not as extensible. INFO can be added, but if we ever want more extensions, they would increasingly possibly conflict with other things. |
I think I agree with |
That's why we have this debate. 😛 |
I personally actually prefer stabilizing a CSS class, I think we should do more of that, just because parsing can get annoying. But this is not that hard to parse anyway. The problem with |
The problem with this is it ties rustdoc to the HTML backend; like I said on Zulip nothing rustdoc currently does guarentees that it will generate HTML from the markdown. Changing that means that to make the JSON backend have the same info, we'd have to add a full HTML parser to rustdoc just to read the HTML in the markdown, because pulldown does not parse HTML for us. I really think we should avoid making the JSON backend a second-class citizen. |
Also there's not much point to this if it's just a little CSS IMO, you can add that yourself with |
I'm not a giant fan of the |
So, I agree, but I'm not convinced that the warning class is something that needs to be surfaced in the JSON backend as anything special. Also, bear in mind, HTML is a part of markdown: valid HTML (well a subset of HTML) is valid markdown. Users already can Markdown parsers already need to be able to handle HTML. There's nothing new there. Whatever consumes the JSON backend will need to be able to handle that too.
I mean, yes, in theory, in practice people don't do this because of the barrier to entry (you have to get your tools to use that, including docs.rs) |
Also, this is incorrect, pulldown absolutely parses HTML. It has to, like I said valid HTML is valid Markdown. It doesn't parse it thoroughly, I believe you can mess it up with sufficiently complex HTML, but it parses HTML. What this changes is subtler: up till now you did not need any particular stylesheet to acceptably render rustdoc markdown from the JSON backend on your own (just use your favorite markdown renderer's stylesheet), but now you will need other css classes to handle rendering warnings as warnings. |
I do not agree that this is a problem. I've used Phabricator's implementation of this approach happily and it is by design that warning banners are one paragraph. It is not the intention that you would put entire sections of documentation into a warning banner. They are for a brief callout. It's fine to refer to a subsequent section of the documentation from the callout if needed. I suppose this is a matter of taste but it's one where I believe the opinionatedness of the syntax is a positive thing. |
So I discussed this a bit with @jyn514 on the side, we agree that the effect on the JSON backend isn't major since HTML is already a subset of markdown and docs use HTML already (especially for images and tables). My position is as follows:
which makes my position "HTML or nothing", basically. I'm not wholly against unscoped single-line syntax. We Furthermore, Rust has a strong culture of wrapping text, so this means we need |
I don't know about admonitions specifically but there seems to be something of a community habit to use "magic tags" on fenced code blocks for this sort of features (e.g. github has a So a warning would be
or maybe the tag would be Alternatively, take a gander at how other markdown implementations extend the language for this sort of features? e.g. python-markdown seems to be using |
Hmm, but Aside from the design concerns, this would be feasible to implement: we just extract the language string from the code block with pulldown. |
Could you use something that's already built into markdown? For example, rustdoc could take |
That's what #79710 (comment) suggested: to use markdown and make some changes on rustdoc side. I think the codeblock approach is the best personally. |
My bad, I didn't see that. |
I wonder if it makes more sense to add this as a proc-macro. Rustdoc can still provide the CSS classes and things, and you could use them with HTML directly, but you could use |
Might be better to have a |
Is that going to be a special header similar to the "unsafe"/"experimental"/etc ones, or is that going to also be used within docs in an order-sensitive way? If the latter we should probably just use a CSS class; mixing |
Agreed. Among the suggested ideas, my favourite one remains the code block with "warning" as tag:
|
Yeah, but triple backticks is also for preformatted text without further markup, so you won't be able to e.g. use text formatting (or other code) in there |
True... Finding the right syntax is much more complicated than expected... |
That's the issue of using markdown, for all that it has a pretty nice baseline syntax it really was not designed for extensibility. |
We can always use |
I thought I'd already left this comment, but I'd really like to avoid adding more markdown syntax where possible. This feature works fine without special syntax, I don't think we need it. edit: copying over the reasoning from the other thread:
|
@Manishearth Although, I might not agree fully, I can fully appreciate and understand the reasoning you left in the corresponding PR. Still, I do think it might be worth to standardize some kind of syntax for some kind of warning block. This does not actually require customized markdown. Alternatively, I can suggest adding the GitHub flavor with emojis to the Rust API Guidelines documentation section. This may help in standardizing short form warnings and notes within documentation. We could for example propose to standardize: > ⚠️ **Warning**
> This is a warning message. which should look like the following
I do value people's opinion on this. Is this a possible compromise? |
That's a valid alternative, I think the yellow color is pretty important though, and it's useful for themes to be able to make styling decisions about warnings so I do think that having some way of marking it is important. I just don't think the way of marking it should be some magic invocation as opposed to CSS classes. (And I think that the bar for a feature that is adding new semantics to the Rustdoc markdown parser is much, much higher than that of one stabilizing a CSS class) |
100% agree. I will look at the Rust API guidelines issue and possibly an RFC to rust to track the adoption in GitHub and possibly eventually merge. Thank you 😄 |
Beyond all this discussion of third-party tools, I'd really like to make sure that whatever new syntax and presentation we add to rustdoc can also be added to mdBook. That way, when the standard library starts using callouts, we can make sure the same style also gets used in The Book. Mostly, The Book seems to just use blockquotes, often with headings like this one about ownership. mdBook doesn't do anything special with it: it's just a block quote with a header. |
This is a good point. Once we have something merged here, I'll send a PR there to have an equivalent. |
CC @ehuss |
I'd be happy to add some CSS rules to mdbook if that is what you are proposing. |
Yeah, it is. |
FYI, using a
— CommonMark Spec v0.30, https://spec.commonmark.org/0.30/#block-quotes
— W3C HTML spec, https://html.spec.whatwg.org/multipage/grouping-content.html#the-blockquote-element Unless you are quoting a source, this is not the correct element to use. While I disagree with even using CommonMark does have an RFC for generic directives that could be used if the |
I agree that block quotes for callouts are bad, and would like to work with mdBook to roll out a common syntax (probably |
Using |
Add warning block support in rustdoc Fixes rust-lang/rust#79710. You can test it [here](https://rustdoc.crud.net/imperio/warning-block/foo/struct.Foo.html). It currently looks like this: ![image](https://user-images.githubusercontent.com/3050060/211413494-e1cf04e4-c081-4a9d-97db-27329405cfa7.png) So a few things to note: * Since it's a new add and it's changing the UI, we'll need to go through an FCP. * Does the UI looks good? * Is the way picked to add a warning block ok for everyone? The discussion on the issue seemed to be in favour of this solution but it doesn't hurt to double-check. cc `@rust-lang/rustdoc`
Unfortunately |
Ah. Well I suppose the issue wasn't with intra-doc links, but with inline code blocks. What I tried was that but with |
I opened #119245 which adds extra explanation on how to use markdown inside html tags. That should solve your issue. |
That note is exactly what I was just looking in to. I had it inline, given my familiarity with HTML. TIL that matters. |
It doesn't hurt to have it and if it can helps users, well, why not doing it. :) |
Improve documentation for using warning blocks in documentation From [this comment](rust-lang#79710 (comment)), I think markdown can be surprising sometimes so better explain a bit better how to use it correctly. r? `@notriddle`
Rollup merge of rust-lang#119245 - GuillaumeGomez:improve-docs, r=fmease Improve documentation for using warning blocks in documentation From [this comment](rust-lang#79710 (comment)), I think markdown can be surprising sometimes so better explain a bit better how to use it correctly. r? `@notriddle`
Add warning block support in rustdoc Fixes rust-lang/rust#79710. You can test it [here](https://rustdoc.crud.net/imperio/warning-block/foo/struct.Foo.html). It currently looks like this: ![image](https://user-images.githubusercontent.com/3050060/211413494-e1cf04e4-c081-4a9d-97db-27329405cfa7.png) So a few things to note: * Since it's a new add and it's changing the UI, we'll need to go through an FCP. * Does the UI looks good? * Is the way picked to add a warning block ok for everyone? The discussion on the issue seemed to be in favour of this solution but it doesn't hurt to double-check. cc `@rust-lang/rustdoc`
Add warning block support in rustdoc Fixes rust-lang/rust#79710. You can test it [here](https://rustdoc.crud.net/imperio/warning-block/foo/struct.Foo.html). It currently looks like this: ![image](https://user-images.githubusercontent.com/3050060/211413494-e1cf04e4-c081-4a9d-97db-27329405cfa7.png) So a few things to note: * Since it's a new add and it's changing the UI, we'll need to go through an FCP. * Does the UI looks good? * Is the way picked to add a warning block ok for everyone? The discussion on the issue seemed to be in favour of this solution but it doesn't hurt to double-check. cc `@rust-lang/rustdoc`
Following #79677, we realized that rustdoc users would prefer to have a syntax extension rather than using plain HTML to have warning blocks.
@dtolnay suggested the following:
@Darksonn suggested:
What do you think?
cc @rust-lang/rustdoc
The text was updated successfully, but these errors were encountered: