-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Markup: Wrap algorithms in <div> tags #11392
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
base: main
Are you sure you want to change the base?
Conversation
Out of curiosity, why use a different attribute marker to indicate an algorithm than what Bikeshed uses? There's certainly no, like, interop between the documents, but using identical patterns when possible reduces mental load for spec authors that touch multiple specs. It looks like a major reason might be that about half the "algorithms" don't scope their variables, per your numbers. Can you expand on that? |
Using the same marker might have suggested it has the same semantics, which I don't think it does (though there's a lot of overlap). One difference is that the (optional) value of Bikeshed's But certainly, if the HTML editors would like the spec to be more like Bikeshed in this regard, that can be done.
It's not that they don't scope their variables, it's that they don't have variables to scope. E.g.
Although "a parallel queue" and "the parallel queue" are basically the declaration and use of a parameter, it doesn't use any Other examples are where an algorithm's only use of (what you might think of as) a parameter is to say And then there are cases like in 2.6.1 Reflecting content attributes in IDL attributes, where "For a reflected target that is an element element, these are defined as follows:" introduces a One caveat is that I mostly ignore |
My reaction is the same as @tabatkins. This is more than I anticipated in #10483 (comment). And I worry that trying to guarantee this level of fine-grained metadata going forward will be a burden on contributors. Can we just use Additional note: dff98e6 does not match our style guide. https://github.com/whatwg/html/blob/main/CONTRIBUTING.md#element-hierarchy |
It's certainly more than you described, and I knew that when I created the PR, but like I said, it's more of a discussion-starter than a solid proposal.
Yup.
Certainly. I'll explain more about why this draft has (1) Similarly, the Web IDL spec gives particular wording for defining behavior, but looking for just that wording will miss lots. So one thing I did was read the spec's Web IDL fragments, to figure out what behavior-algorithms would need to appear elsewhere in the spec. So if the algorithms I had tagged so far didn't cover that, I would need to look further (i.e., look for other phrasings). The granular (2) (3)
To be clear, I didn't introduce So sure, we can say that every algorithm is implictly a variable scope, and so drop
Sure, but like I said, that commit's only there to make the main commit cleaner. (That is, in the main commit, every new Or are you saying that the later commit doesn't fix it? Currently, the PR says
According to the style sheet, I guess this should be
because both the Or maybe you'd prefer
but then I have to ask if you'd like a similar treatment for other cases where the new Of course, rather than introducing a |
Thanks for your detailed reply! I think I'm aligned on most points. To summarize:
Regarding the eventual end state, do you think Anyway, I'll try to do a more detailed review pass now! |
So, the diff is huge, and not reviewable on GitHub. But reviewing it locally, the following things stood out to me from, like, the first 10%, plus some skipping around.
|
You looked at cases of (Looking at the 3rd
I'm pretty sure that just |
This makes sense, and is something I wouldn't mind introducing to Bikeshed as well. (And that name, But in Bikeshed, at least, it would be in addition to the var scoping that happens automatically for algorithms. For ease of comparison, I think it would be a good idea to assume that algorithms automatically scope their variables. (We can worry about to what extent we need to care about marking up a shared variable "inheriting into" nested scopes later, if at all. This is mostly for human convenience, and lightly for linting and styling, so it doesn't necessarily need to be too precise.) |
(Responding to just a couple points for now...)
Indeed, the variety of syntax is discouraging. I imagine I'll suggest some consistification to make analysis easier, but it probably won't make much of a dent in the non-uniformity.
Yeah, that's what I thought too. More generally, they are rich in statically checkable phrases, so it would be a shame not to check them.
It may be difficult to draw the line between algorithm-y and non-algorithm-y definitions.
I think the specific reason was just that I didn't look for dfn-paragraphs with that form. E.g., I probably would have included CORS-same-origin if it had been phrased as: "A response is CORS-same-origin if ..." or "To determine whether a response is CORS-same-origin, ..." Background: I didn't want to step through the whole HTML spec, asking for each paragraph in turn whether it should be marked as an algorithm. So instead [among other things] I 'scraped' paragraphs from the spec and tried to identify patterns of phrasing that looked like algorithms, and then (check and) mark-up the paragraphs using those patterns. Which has the failure mode of leaving things out. Anyway, I'll take another look.
The "has 53 weeks" paragraph got my attention because of the
Yes, I'm currently counting 84, ignoring examples, notes, and domintros. I think I only bothered creating a
Right there with you, and I'd happily work on it, like I did for EcmaScript. That could conceivably be an alternative to this PR, since if you have a distinct enough syntax for algorithm headers, you might not need |
(responding to the rest of Domenic's comment...)
Okay, cool.
I did have it marked as an algorithm for a while, but it was just too weird.
There's definitely a tooling-related reason to have struct info handy. E.g., if you want to validate (type-check) However, I'm not sure that
Standardizing either the markup or the introductory wording would be good.
It occurs to me that
There might be other cases where
I understand what you mean, but I don't think I have much to add to your points. |
(I'm creating this in draft mode, because at this stage it's more of a discussion-starter than a solid proposal.)
In issue #10483, @domenic raises the possibility of wrapping the HTML spec's algorithms in
<div algorithm>
(as in Bikeshed specs). This PR does something approximating that.The first commit is a minor markup change that was originally in PR #11379, but fell out when I withdrew the
<hN>
-related commits.The second commit just adds some linebreaks, so that the main commit has a cleaner diff.
In the main commit, I add 2269
<div>...</div>
pairs.Each
<div>
start tag has one or both attributes:var-scope
algo="..."
(11 have only
var-scope
, 1081 have onlyalgo
, 1177 have both.)var-scope
means: thisdiv
is a scope for<var>
elements. (The main commit also inserts thevar-scope
attribute into 4<p>
tags and 1<dd>
tag, rather than introduce a<div>
to hold thevar-scope
.)algo
means: thisdiv
contains some kind of algorithm, where the value of the attribute suggests the kind. (Occasionally, the value will show 2 kinds.)Behavior for attributes and operations declared in Web IDL fragments:
The classic: an algorithm is defined with a unique name + ID:
A named state of affairs exists if a given condition holds:
Integration with JavaScript:
Some other spec declares the algorithm, this spec gives steps for it:
(You could say that "js:host-defined-op" belongs here too.)
There's one 'abstract' declaration of the algorithm, but different kinds of object can have different definitions for the algorithm:
(You could say that "js:internal-method" belongs here too.)
When something occurs in the data model, the UA must perform some steps:
Parsing-related algorithms:
See below:
Algorithms that appear in examples, which might or might not be 'serious':
Abstract declarations of algorithms:
Things that are not actually algorithms, but I felt like identifying:
I don't know how to categorize it:
"main+subs" isn't a particular kind of algorithm, but rather a collection of algorithms, where there's one main algorithm that invokes others, but those others use variables defined in the main algorithm without taking them as parameters. (These need to be treated specially when it comes to checking for
<var>
s being defined.) One way to think of these is as as macros that get inlined at the invocation-points. However, I prefer to think of them as algorithms that are conceptually nested at some point within the main algorithm, and so can 'see' the variables defined at that point. (Presumably they appear after the main algorithm to make the main algorithm easier to read.)/browsers.html ( diff )
/browsing-the-web.html ( diff )
/canvas.html ( diff )
/common-dom-interfaces.html ( diff )
/common-microsyntaxes.html ( diff )
/comms.html ( diff )
/custom-elements.html ( diff )
/dnd.html ( diff )
/document-lifecycle.html ( diff )
/document-sequences.html ( diff )
/dom.html ( diff )
/dynamic-markup-insertion.html ( diff )
/edits.html ( diff )
/embedded-content-other.html ( diff )
/embedded-content.html ( diff )
/form-control-infrastructure.html ( diff )
/form-elements.html ( diff )
/forms.html ( diff )
/grouping-content.html ( diff )
/iframe-embed-object.html ( diff )
/image-maps.html ( diff )
/imagebitmap-and-animations.html ( diff )
/images.html ( diff )
/index.html ( diff )
/infrastructure.html ( diff )
/input.html ( diff )
/interaction.html ( diff )
/interactive-elements.html ( diff )
/links.html ( diff )
/media.html ( diff )
/microdata.html ( diff )
/nav-history-apis.html ( diff )
/obsolete.html ( diff )
/parsing.html ( diff )
/popover.html ( diff )
/rendering.html ( diff )
/scripting.html ( diff )
/sections.html ( diff )
/semantics-other.html ( diff )
/semantics.html ( diff )
/server-sent-events.html ( diff )
/structured-data.html ( diff )
/syntax.html ( diff )
/system-state.html ( diff )
/tables.html ( diff )
/text-level-semantics.html ( diff )
/timers-and-user-prompts.html ( diff )
/urls-and-fetching.html ( diff )
/web-messaging.html ( diff )
/webappapis.html ( diff )
/webstorage.html ( diff )
/workers.html ( diff )
/worklets.html ( diff )
/xhtml.html ( diff )