amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

Discussion: <p> can break AMP with some ease

Open dvoytenko opened this issue 11 years ago • 14 comments

This is a well-known and somewhat documented issue, but we may want to think if we can do anything to make it less of a trap. Consider this:

<p>
  <amp-carousel>
    <div slide1></div>
    <div slide2></div>
  </amp-carousel>
</p>

This code fragment will be completely messed by the browser. It will actually end up being this:

<p>
  <amp-carousel>
  </amp-carousel>
</p>
<div slide1></div>
<div slide2></div>

This is, of course, because HTML spec states that <p> is automatically closed by <div> and a host of other tags. In other words, <p> is really bad for composition.

dvoytenko avatar Sep 28 '15 19:09 dvoytenko

At the very least maybe we can stress it in the FAQ or spec or any document we have.

dvoytenko avatar Sep 28 '15 19:09 dvoytenko

@jmadler Do you think this is resolvable with an FAQ? validating this may be a bit overly specific.

cramforce avatar Sep 28 '15 19:09 cramforce

How difficult would it be to identify is a

is inside of a

? Would it appear as a child to the DOM? If it's straight-forward, we should invalidate this particular use case.

jmadler avatar Oct 01 '15 02:10 jmadler

I think we should detect that nothing is inside the carousel, then emit a warning that links to an explanation.

"Oh hi, this is amp-carousel: It looks like there's no element inside of me. If this is surprising to you, please read [some url explaining]."

Maybe for now the runtime should be doing this, but I think it's also possible to do it in the javascript validator. I'd need to verify that the htmlparser in the Javascript validator correctly auto closes tags and if not, make it so.

powdercloud avatar Oct 01 '15 08:10 powdercloud

btw discussing things about tags in github is pretty comical (it tries to interpret them as raw html, yay, markdown + html mixed in)

powdercloud avatar Oct 01 '15 08:10 powdercloud

@jmadler to answer your question, I think the problem would be that the div isn't actually inside the p. Anything that runs atop a standards conforming html5 parser won't know what's going on. It's possible that our parsers don't close the tags properly but if they don't I'd want to fix that, rather than starting to rely on it. So the way I think we should detect the problem is the absence of stuff inside the carousel. The runtime has the easiest shot at this because it has an accurate DOM thanks to Chrome or whatever browser it's on.

powdercloud avatar Oct 01 '15 08:10 powdercloud

This is correct - if the HTML parser parses according to HTML rules - we have no way of catching this situation. That's the issue here precisely, according to XML the document looks good, but according to HTML it's broken.

We can check inside the carousel, but that wouldn't give us much of a coverage either. The DIV could be in the second, third, etc slide and that would cause carousel to have some slides, just not all of them.

I think the best bet might be to check what HTML parser we use on the backend and see if we can tune it to change

rules and generate warnings this way.

In the meantime, I'll remove [URGENT] from this issue. It's still important to come up with some ideas to help authors, but it is after all HTML5 reality.

dvoytenko avatar Oct 01 '15 17:10 dvoytenko

I think we should just not allow

in favor of

due to its unexpected behavior.

jmadler avatar Dec 17 '15 22:12 jmadler

@jmadler <p> and <div> are not the same thing. I don't see any urgency here at all. HTML has problems. It is not our mission to fix them.

cramforce avatar Dec 17 '15 22:12 cramforce

True, but AMP HTML could complicate this somewhat if an extension uses

internally

jmadler avatar Dec 17 '15 22:12 jmadler

So, to the original problem: Can't we catch that in the validator?

cramforce avatar Dec 17 '15 22:12 cramforce

Probably. It'll be a bit of work if our parser closes the <p> tag the same way as the browser does, but that need not stop us.

What specifically do you propose that we try to disallow in validation? Any <p> tag that is closed implicitly?

Gregable avatar Dec 17 '15 23:12 Gregable

I think we can skip this. We had a concern that this will be a problem. However do far that didn't cause any headaches. On Dec 17, 2015 3:32 PM, "Greg Grothaus" [email protected] wrote:

Probably. It'll be a bit of work if our parser closes the

tag the same way as the browser does, but that need not stop us.

What specifically do you propose that we try to disallow in validation? Any

tag that is closed implicitly?

— Reply to this email directly or view it on GitHub https://github.com/ampproject/amphtml/issues/327#issuecomment-165615128.

You received this message because you are subscribed to the Google Groups "amphtml-eng-github" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/a/google.com/d/msgid/amphtml-eng-github/ampproject/amphtml/issues/327/165615128%40github.com https://groups.google.com/a/google.com/d/msgid/amphtml-eng-github/ampproject/amphtml/issues/327/165615128%40github.com?utm_medium=email&utm_source=footer .

You received this message because you are subscribed to the Google Groups "amphtml-eng" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/a/google.com/d/msgid/amphtml-eng/ampproject/amphtml/issues/327/165615128%40github.com https://groups.google.com/a/google.com/d/msgid/amphtml-eng/ampproject/amphtml/issues/327/165615128%40github.com?utm_medium=email&utm_source=footer .

amphtml-team avatar Dec 18 '15 01:12 amphtml-team

Agree.

jmadler avatar Jan 18 '16 06:01 jmadler