Parse XML-style <?target data?> processing instructions#12118
Conversation
f806ae3 to
a26fe99
Compare
|
I've polished some more, this is close to ready now. Needs impl interest and tests, of course. |
Nice! I can have tests ready within a few days. |
Nit: As specified in https://html.spec.whatwg.org/#serialising-html-fragments it would serialize as |
|
@zcorpan you're absolutely right, I was testing in Chrome and didn't realize the spec says otherwise. |
|
Test for serialization: web-platform-tests/wpt#57486 |
|
Ah, I did not know Chromium and WebKit serialize with This opens up for making the Pros to making it required:
Cons:
|
|
Also, maybe we can just support I checked these 6 pages https://docs.google.com/spreadsheets/d/1o04eP_BwH1u7X8CyyLUvxOsntZNmfrDalfhU7ldVqlU/edit?gid=233477192#gid=233477192&range=C12 , only one has a PI pointing to external CSS but that file is empty. |
Yea we could probably also parse that PI for |
Hmm, it would break roundtripping to XML. I'd prefer a comment node or dropping it. |
|
On serializing PIs with just @zcorpan, changing it to Regarding conformance, do you mean that a case like |
|
On the DOM side, does this still create Comment nodes? Otherwise this is certainly not web compatible. |
It creates ProcessingInstruction nodes which already exist in DOM. What specifically makes this web incompatible in your view? HTTP archive shows very little use of PI-like syntax and we can exclude problematic targets if we need to. |
|
In lit-html we use PI syntax to create comments that are parsed inside templates: https://github.com/lit/lit/blob/f243134b226735320b61466cebdaf0c1e574bfa7/packages/lit-html/src/lit-html.ts#L354 These comments are then retrieved with a TreeWalker that shows Comment nodes. The targets aren't fixed, but have the form |
We can easily exclude targets that start with ’lit$’ from this, or any other string that we find to be problematic in terms of compat. |
@foolip suggested that we constrain the syntax instead. ^[a-zA-Z_][\w_\.\-]*$I think treating invalid targets as bogus comments would work better than block-listing |
Or even pithier, |
That includes non-ASCII, right? I think the HTML parser intentionally doesn't branch for non-ASCII anywhere. |
Good point, it can be something like |
jmdyck
left a comment
There was a problem hiding this comment.
A few minor suggestions. (Sorry if they're not in file order.)
Thanks! All addressed. |
jmdyck
left a comment
There was a problem hiding this comment.
Two more nits after previous fixes.
Thanks, fixed both. |
…ruction parsing tests, a=testonly Automatic update from web-platform-tests Untentative and fix HTML processing instruction parsing tests For whatwg/html#12118. -- wpt-commits: cf0642a4d2a851574afd696f566987f84f92849f wpt-pr: 60828
Notably behavior and their rationale:
<?opens a PI, a>always closes it. This to match the boguscomment tokenizer behavior, so that exactly the same characters are
consumed as bogus comments in existing parsers. Any deviation would
make this a much riskier parser change.
goes, matching tag names. This doesn't have to be this way, but
there's no obvious other precedent to follow.
attribute names. This is for consistency, and there's precedent from
the SVG-in-HTML parser behavior.
it's instead treated as a bogus comment.
<?xml?>is not a valid PIin XML, and
<?xml-stylesheet href="style.css"?>would otherwisestart loading stylesheets in HTML documents, which we don't want.
?that's not followed by a>becomes part of the data (neverthe target). This is to match XML for a
<?t ???>where data is "??".<?t?d?>(invalid XML) the target is "t" and data is "?d". Thisbehavior results from handling
?the same way wherever it'sencountered. The example would serialize back as
<?t ?d?>.<?>and<?followed by EOF are treated as bogus comments, becausethis is the most conservative choice, and also avoids empty target.
(See WHATWG Working Mode: Changes for more details.)
/index.html ( diff )
/infrastructure.html ( diff )
/parsing.html ( diff )
/syntax.html ( diff )