Skip to content
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

Table parts in <template>- <td> and <td> #7922

Closed
alexander-akait opened this issue May 13, 2022 · 10 comments · Fixed by #8271
Closed

Table parts in <template>- <td> and <td> #7922

alexander-akait opened this issue May 13, 2022 · 10 comments · Fixed by #8271
Labels
document conformance needs tests Moving the issue forward requires someone to write tests topic: parser

Comments

@alexander-akait
Copy link

alexander-akait commented May 13, 2022

I have a question about table parts in <template> tag.

I have HTML:

<template id="productrow">
  <tr>
    <td class="record"></td>
    <td></td>
  </tr>
</template>

Ref: https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-intable (it is a basic example in docs and it is confusing )

According spec we have an error here, because \n after </tr> goes in:

Anything else
Parse error. Enable foster parenting, process the token using the rules for the "in body" insertion mode, and then disable foster parenting.

Not in first, because current node is <template>:

A character token, if the current node is table, tbody, tfoot, thead, or tr element

That is, any part of the table in the <template> is a parse error?

@annevk
Copy link
Member

annevk commented May 13, 2022

Thanks for reporting. This looks like an oversight.

cc @whatwg/html-parser

@zcorpan
Copy link
Member

zcorpan commented May 13, 2022

Would the spec do the right thing if we check if the current node is template in

A character token, if the current node is table, tbody, tfoot, thead, or tr element

?

There should still be a parse error for

<template id="productrow">
  <tr>
    <td class="record"></td>
    <td></td>
  </tr>
  text here
</template>

@alexander-akait
Copy link
Author

@zcorpan I am implementing parser here https://github.com/swc-project/swc/tree/main/crates/swc_html_parser using spec and tried to add template in

A character token, if the current node is table, tbody, tfoot, thead, or tr element

And all works fine, we have html5lib_tests and wpt tests and nothing was broken

Therefore, I thought that perhaps this is a mistake/inaccuracy

@zcorpan
Copy link
Member

zcorpan commented May 16, 2022

OK, good to know that it works as intended in your implementation.

It looks like there are no tests currently that exercise this case in html5lib-tests, as far as I can tell. Do you want to contribute new tests?

@zcorpan zcorpan added the needs tests Moving the issue forward requires someone to write tests label May 16, 2022
@alexander-akait
Copy link
Author

Yes, there are no tests in html5lib-tests, yes I can send them, should we have #errors for this. I would like to just understand whether we should go for the first point or maybe we should not create parser error when it is in template in anything else?

@zcorpan
Copy link
Member

zcorpan commented May 16, 2022

Yes the test should use #errors.

IMO, the new tests can be written to assume the fix in #7922 (comment) (so no error for whitespace, error for other text). I can submit a PR for the spec sometime this week, unless someone beats me to it. :)

Thanks!

@alexander-akait
Copy link
Author

alexander-akait commented Sep 7, 2022

@zcorpan Hello, sorry for big delay, I sent tests #7922, also I pushed the fix in our parser (so you can see all tests passed + we use tests from html5lib-tests) swc-project/swc#5779

zcorpan added a commit that referenced this issue Sep 8, 2022
The spec would enable foster parenting for whitespace in template after seeing table-related markup and trigger a parse error. Whitespace in template should not be a parse error. This change should not affect the parsed tree structure, only the number of parse errors. Non-whitespace text will still go through foster parenting and is still a parse error.

Fixes #7922.
@zcorpan
Copy link
Member

zcorpan commented Sep 8, 2022

Thanks! Spec PR: #8271

zcorpan added a commit that referenced this issue Sep 15, 2022
The spec would enable foster parenting for whitespace in template after seeing table-related markup and trigger a parse error. Whitespace in template should not be a parse error. This change should not affect the parsed tree structure, only the number of parse errors. Non-whitespace text will still go through foster parenting and is still a parse error.

Fixes #7922.
@alexander-akait
Copy link
Author

@zcorpan Big thank you

@zcorpan
Copy link
Member

zcorpan commented Sep 15, 2022

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
document conformance needs tests Moving the issue forward requires someone to write tests topic: parser
Development

Successfully merging a pull request may close this issue.

3 participants