-
Notifications
You must be signed in to change notification settings - Fork 22.5k
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 a template for CSS functional notation #28953
Conversation
Preview URLs
External URLs (2)URL:
URL:
(comment last updated: 2023-09-19 14:54:11) |
The overall structure presented in this template looks good, but I have one explicit usage doubt: For In the template, the "Syntax" section first lists example uses of the functions, then lists paramaters in the "Parameters" subsection, but parameters are usually order-dependent, and there is no easy way to indicate if any literal tokens like commas and slashes are needed in between. Comparing to A smaller issue is that, I think, example uses in the "Syntax" section should not have a comma at the line end as they are not complete value declarations. JavaScript pages don't have such commas, either. Maybe the "Syntax" section can show the pattern in comments: /* var( <custom-property-name> , <declaration-value>? ) */
/* Without a fallback */
var(--custom-prop)
/* With fallback */
var(--custom-prop,) /* empty value as fallback */
var(--custom-prop, initial) /* initial value of the property as fallback */
var(--custom-prop, #FF0000)
var(--my-background, linear-gradient(transparent, aqua), pink)
var(--custom-prop, var(--default-value))
var(--custom-prop, var(--default-value, red)) Then A few notes:
An alternative format is to list several patterns to reduce the use of quantifiers: /* Without a fallback */
/* var( <custom-property-name> ) */
var(--custom-prop)
/* With fallback */
/* var( <custom-property-name> , ) */
var(--custom-prop,) /* empty value as fallback */
/* var( <custom-property-name> , <declaration-value> ) */
var(--custom-prop, initial) /* initial value of the property as fallback */
var(--custom-prop, #FF0000)
var(--my-background, linear-gradient(transparent, aqua), pink)
var(--custom-prop, var(--default-value))
var(--custom-prop, var(--default-value, red)) But this format has the risk that some productions may contain a lot of quantifiers to expand. PS: CSS type pages seem to a deeper hole to fall into 😬 |
Thanks for your thoughtful response, @yarusome !
Yeah, this is a good point, and before I'd read the second part of your post I'd also thought we could use comments in the "syntax example" block to express this.
The general point is also right though, and it is a bit worrying that it might be misleading to call these things "Parameters" when they are rather different to JS parameters. We could call if "Values" instead, but still have "Return value"? Not sure. I think I still like "Parameters" better.
Do you mean semicolon?
I'm not sure the extra syntax is a good idea. They seem to be signalling that this is formal syntax, but this is pseudo-formal syntax. And I'm worried it might confuse people that say In general, formal syntax is hard enough for people without adding something else that is kind of like formal syntax, but isn't. If we can I would prefer a more literal/duplicated approach: /* oklch( L C H) */
oklch(40.1% 0.123 21.57)
/* oklch( L C H / A) */
oklch(59.69% 0.156 49.77 / .5) ...and the things in the brackets are either literals or things we explain in "Parameters".
Oh, this is what I said up there I think :).
Yes, this is a worry, but I think it is better in most cases.
Ha, well feel free to start something there if you want :). |
Yes, my head must be contorted at that time.
This looks much better than the angled notations! (But why |
No reason, just a typo. |
:) Calling it "Syntax" is confusing. It makes readers start looking for syntax patterns in these usage examples. This is somewhat frustrating cos real syntax comes much later on the page. We could have order like syntax, formal syntax, parameters, and return values.
We are already doing this so we could put this in the template. |
All our research says that (unfortunately) most people don't understand formal syntax or even look at it. And I do think the intention of this section is to show the syntax, it just does it "by example" rather than using a formal notation.
This seems like a very vague name. How is "usage examples" different from "examples"? How is someone expected to understand that distinction? An example is different to this block, because an example would show complete code and explain what the specific values chosen do. There's a long discussion about all this here: https://github.com/orgs/mdn/discussions/218 FWIW I do think (as I said in that discussion) that we ought to reunite "formal syntax" and "values", but there didn't seem to be consensus for it. Anyway: please, let's keep this to functions in this discussion. I don't think we should only rename "Syntax" for CSS functions, and I would like to get towards some consistency for those pages. |
I pushed a new commit including the changes requested by @yarusome , more or less. I removed from the syntax block the inline comments like |
.../en-us/mdn/writing_guidelines/page_structures/page_types/css_function_page_template/index.md
Outdated
Show resolved
Hide resolved
|
…css_function_page_template/index.md Co-authored-by: Onkar Ruikar <[email protected]>
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 couple suggestions and a couple edits.
.../en-us/mdn/writing_guidelines/page_structures/page_types/css_function_page_template/index.md
Outdated
Show resolved
Hide resolved
.../en-us/mdn/writing_guidelines/page_structures/page_types/css_function_page_template/index.md
Outdated
Show resolved
Hide resolved
|
||
## Description | ||
|
||
This is an optional section to include a description of the function and explain how it works. Use this section to explain related terms and add use cases for the function. |
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 an optional section to include a description of the function and explain how it works. Use this section to explain related terms and add use cases for the function. | |
Include a description of the function and explain how it works. Use this section to explain related terms and add use cases for the function. |
Prefer to have this semi-required.
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 happy to recommend it but this edit makes it required, not semi-required. At the moment many of our pages don't have description sections, and if we make it mandatory we are likely to get low-value edits just to tick boxes in the template.
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.
We could say "While this section is optional, we highly recommend you to add a description..."
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 just "We highly recommend you include a description..."
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 think if it is optional, we should say it is optional. It's just clearer that way. I've pushed an update along the lines of Dipika's suggestion.
.../en-us/mdn/writing_guidelines/page_structures/page_types/css_property_page_template/index.md
Outdated
Show resolved
Hide resolved
Co-authored-by: Estelle Weyl <[email protected]>
I think following the formal syntax order would be better.
Ideally we would have synchronization between the "syntax example code block", the "values" list, and the formal syntax. That way people can cross-reference from one to the other. As I said in the other PR, that would mean things like:
...which is not that far from @dipikabh 's suggestion of:
...only it maps more explicitly to the
I'm not sure what "only explanations" means here. From @yarusome 's comment at #28953 (comment), I'm not too keen on:
...because (1) I think the value and meaning of
I think the function of the "syntax example code block" is to describe the syntax of the thing, and the semantics ought to be explained in prose. Anyway, this is just my opinion, and maybe there are cases where it wouldn't work. But even if we can't agree on all these details, I would love to have something we can use to get at least a minimal amount of consistency between pages here. |
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.
Thanks for taking this up, Will! I've added a few suggestions and questions.
.../en-us/mdn/writing_guidelines/page_structures/page_types/css_function_page_template/index.md
Outdated
Show resolved
Hide resolved
.../en-us/mdn/writing_guidelines/page_structures/page_types/css_function_page_template/index.md
Outdated
Show resolved
Hide resolved
|
||
```css | ||
/* Without a fallback */ | ||
|
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.
As pointed in previous comment, I think we should not have an empty line here
/* var( <custom-property-name> , ) */ | ||
var(--custom-prop,) | ||
|
||
/* var( <custom-property-name> , <declaration-value> ) */ |
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.
For consistency, we would need to add a descriptive comment here as well?
Which makes me wonder - is it optional or mandatory to add two comments for each syntax use case. We would need to be more specific in the instructions. At the least, a syntax use case should be preceded by a descriptive comment.
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 don't really know how prescriptive we need to be in general.
I have 2 main concerns:
- people should be able to cross-reference between this code block, the "Values" list, and the formal syntax. So we should if at all possible use the same names for things in all three places.
- we should use the code block as a place to show the syntax, not to describe the syntax.
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.
Agree, it can be a guideline instead of a requirement and authors and reviewers can take a call based on the context.
.../en-us/mdn/writing_guidelines/page_structures/page_types/css_function_page_template/index.md
Outdated
Show resolved
Hide resolved
.../en-us/mdn/writing_guidelines/page_structures/page_types/css_function_page_template/index.md
Outdated
Show resolved
Hide resolved
.../en-us/mdn/writing_guidelines/page_structures/page_types/css_function_page_template/index.md
Outdated
Show resolved
Hide resolved
|
||
## Description | ||
|
||
This is an optional section to include a description of the function and explain how it works. Use this section to explain related terms and add use cases for the function. |
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.
We could say "While this section is optional, we highly recommend you to add a description..."
|
||
### Add a descriptive heading | ||
|
||
Each example must have an H3 heading (`###`) naming the example. The heading should be descriptive of what the example is doing. For example, "A simple example" does not say anything about the example and therefore, not a good heading. The heading should be concise. For a longer description, use the paragraph after the heading. |
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 always thought that in addition to making an H3 heading mandatory in "Examples", we also had some guidance to include a few words about the example. It might make more sense now if we get rid of the language H4 headers as well as "Result". We need to convey that the H3 should be followed by a description of the example scenario/setup or what we're trying to demo. And ideally, after the result frame, explain the output as a result of what we did in the example codes.
-
I realize that this would need to be updated across all the template files that have the "Examples" section and I can take that up we agree on the general idea to include that instruction.
-
CSS property page template, just as an example, also has a "Note" block (I remember you added that across templates :) ). Are we going to add that here?
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.
- CSS property page template, just as an example, also has a "Note" block (I remember you added that across templates :) ). Are we going to add that here?
I've added this.
I always thought that in addition to making an H3 heading mandatory in "Examples", we also had some guidance to include a few words about the example. It might make more sense now if we get rid of the language H4 headers as well as "Result". We need to convey that the H3 should be followed by a description of the example scenario/setup or what we're trying to demo. And ideally, after the result frame, explain the output as a result of what we did in the example codes.
I realize that this would need to be updated across all the template files that have the "Examples" section and I can take that up we agree on the general idea to include that instruction.
Can we split proposals for how to change the way we examples across all pages off from this request to add a template for a specific page type? This seems really out of scope for my PR here.
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.
Can we split proposals for how to change the way we examples across all pages off from this request to add a template for a specific page type? This seems really out of scope for my PR here.
Fair enough, better to discuss this separately
Co-authored-by: Dipika Bhattacharya <[email protected]>
OK, I've made most of the updates and argued with a couple. |
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.
Thanks a lot for the updates, @wbamberg! Leaving my +1.
We don't have a template for CSS functions (or CSS types, see #26881), and the way we document them is quite inconsistent:
https://developer.mozilla.org/en-US/docs/Web/CSS/basic-shape/polygon
https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix
https://developer.mozilla.org/en-US/docs/Web/CSS/sign
https://developer.mozilla.org/en-US/docs/Web/CSS/min
https://developer.mozilla.org/en-US/docs/Web/CSS/pow
https://developer.mozilla.org/en-US/docs/Web/CSS/var
Some choices I've made here:
The reasoning for 1 is that including declarations leads us into conversations like #28873 (review), and I wonder if this will be confusing when we inevitably omit some of the properties that the function can provide a value for.
Happy to discuss though. @yarusome , what do you think?