Skip to content

tidy validates incorrectly inside of <template> #282

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

Closed
shwoodard opened this issue Oct 5, 2015 · 4 comments
Closed

tidy validates incorrectly inside of <template> #282

shwoodard opened this issue Oct 5, 2015 · 4 comments

Comments

@shwoodard
Copy link

Templates should be validated with different semantics. IOW, if I am templating an <li>, I should not be warned that an <ul> will be implicitly inserted.

Template html src

<template id="tmpl__lane">
  <li class="lane">
    <h2></h2>
    <ol class="stories"></ol>
  </li>
</template>

Error on line one:

missing </template> before <li>

Error on line 2

inserting implicit <ul>

Error on line three

trimming empty <h2>

imho, none of these errors should appear due that we are inside of a <template>.

@geoffmcl
Copy link
Contributor

geoffmcl commented Oct 5, 2015

@shwoodard thanks for opening this issue...

I guess when html5 was added to tidy, the use of the template tag was still in draft form, so in tidy it is parsed as any other block element...

Has the W3C spec moved on since then?

Maybe some with W3C knowledge can comment, and maybe provides some links to read...

To check browser support I scraped a working example from whatwg.org - thanks to them -

<!DOCTYPE html>
<meta charset="utf-8">
<title>Test 2 - template tag #282 - Cat data</title>
<script>
 // Data is hard-coded here, but could come from the server
 var data = [
   { name: 'Pillar', color: 'Ticked Tabby', sex: 'Female (neutered)', legs: 3 },
   { name: 'Hedral', color: 'Tuxedo', sex: 'Male (neutered)', legs: 4 },
 ];
</script>
<table>
 <thead>
  <tr>
   <th>Name <th>Colour <th>Sex <th>Legs
 <tbody>
  <template id="row">
   <tr><td><td><td><td>
  </template>
</table>
<script>
 var template = document.querySelector('#row');
 for (var i = 0; i < data.length; i += 1) {
   var cat = data[i];
   var clone = template.content.cloneNode(true);
   var cells = clone.querySelectorAll('td');
   cells[0].textContent = cat.name;
   cells[1].textContent = cat.color;
   cells[2].textContent = cat.sex;
   cells[3].textContent = cat.legs;
   template.parentNode.appendChild(clone);
 }
</script>

This seems to function fine in chrome and firefox, but not in IE, Opera, or Safari, but I may not have all the latest windows 7 64-bit versions installed... especially since this caniuse.com report suggests better than I found...

Of course I am unable to construct even a simple sample that passes the W3C validator... but there have been some 'complaints' about that like here in stackoverflow... but that was a few years ago...

The following sample got close, but shows the nu validator is parsing the text in the template block as html, so warns of an empty h1 header -

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test 3 - template #282</title>
</head>
<body>
<template id="tmpl__lane">
  <li class="lane">
    <h2></h2>
    <ol class="stories"></ol>
  </li>
</template>
<p>Test 3 - template #282</p>
</body>
</html>

I hope someone can give us some samples using template which do pass W3C validation!

My reading of the spec is that the template block contains metadata content, and should not be parsed as html... should not be too difficult implementation in tidy... treat it all as a text node with no html parsing applied...

But the first step here is to hear from some people with good W3C intel...

So again, thanks for bringing it up. Is it now time to kick tidy template tag support up a notch?

@geoffmcl geoffmcl added this to the 5.1 milestone Oct 5, 2015
@geoffmcl
Copy link
Contributor

geoffmcl commented Oct 5, 2015

And such a service, to treat the meta content as a text node, with no html parsing applied, if implemented in tidy, may also be useful for the script and style tags, which are running into trouble - see #65, #280, #281, and maybe others...

For them we need a service that collects a text token from the stream, until the first container close tag is found, and the template tag could be added as a user of the service...

@geoffmcl
Copy link
Contributor

This feature did not make it to 5.1... maybe good for the next 5.2? Or later... meantime marking it indefinite...

As always, ideas, patches, PR very welcome...

@geoffmcl geoffmcl modified the milestones: Indefinite future, 5.1 Dec 12, 2015
@geoffmcl
Copy link
Contributor

No further comment for many weeks, so closing this for now...

Please feel free to re-open, or raise another issue... thanks...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants