Discussion: <p> can break AMP with some ease
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.
At the very least maybe we can stress it in the FAQ or spec or any document we have.
@jmadler Do you think this is resolvable with an FAQ? validating this may be a bit overly specific.
How difficult would it be to identify is a
? Would it appear as a child to the DOM? If it's straight-forward, we should invalidate this particular use case.
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.
btw discussing things about tags in github is pretty comical (it tries to interpret them as raw html, yay, markdown + html mixed in)
@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.
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.
I think we should just not allow
in favor of
@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.
True, but AMP HTML could complicate this somewhat if an extension uses
So, to the original problem: Can't we catch that in the validator?
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?
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 .
Agree.