Understanding rules for parsing tokens in foreign content

。_饼干妹妹 提交于 2019-12-13 18:00:26

问题


I have a question it is related to the stage of executing instructions in the condition. I do not quite understand what each instruction means and when it is executed. Examples with the help of UA would be very helpful in this case.

Here is a piece from specification:

  • A start tag one of the following: b, big, blockquote, body, br, center, code, dd, div "dl", "dt", "em", "embed", "h1", "h2", "h3", "h4", "h5", "h6", "head", "hr", "i", "img", "li", "listing", "menu", "meta", "nobr", "ol", "p", "pre", "ruby", "s", "small", "span", "strong", "strike", "sub", "sup", "table", "tt", "u", "ul", "var"
  • A start tag name is "font", if the token has any attributes named "color", "face", or "size"

    Parse error.

    If the parser was originally created for the HTML fragment parsing algorithm, then act as described in the "any other start tag" entry below. (fragment case)

    Otherwise:

    Pop an element from the stack of open elements, and then keep popping more elements from the stack of open elements until the current node is a MathML text integration point, an HTML integration point, or an element in the HTML namespace.

    Then, reprocess the token.

To avoid misunderstandings, I named instructions what is written in the usual typeface in my quote. In the specification there are similar places, but it is difficult for me to correctly interpret them because it is not clear at what points there are differences.

Look at "Parse Error" - the link leads to the chapter of errors, there is no specific error. How to take this moment?

Next quote:

If the parser was originally created for the HTML fragment parsing algorithm, then act as described in the "any other start tag" entry below. (fragment case)

Does this quote refer to "Parse Error" or is it entirely different?

Next we see the inscription "Othewise" - which tells us that all these instructions can not be executed together. But despite this question the same, quote:

Pop an element from the stack of open elements, and then keep popping more elements from the stack of open elements until the current node is a MathML text integration point, an HTML integration point, or an element in the HTML namespace.

Then, reprocess the token.

Does this quote refer to "Parse Error" or is it entirely different?

Let's sum up: There are only 2 execution instructions, one of which is executed under the condition parser was originally created for the HTML fragment parsing algorithm and the other instruction is executed if the previous instruction does not pass the test. And all this in general is "Parse Error".

But despite this, even if I correctly said everything, please give me examples with this or that fulfillment of the condition, and even understanding of the instructions themselves makes me difficult.


Update 1

I think the question needs to be supplemented so that you can make the most of it.

As you might have noticed, we are sitting in the chapter parsing in foreign content. As you can understand this chapter is intended when we analyze content in foreign content, and foreign content is all that is in the nodes svg or math.

So let's say we are sitting in the node svg and in this svg we put any tag from the list that calls parse error. Just try writing like this: <svg><p>Hello</p></svg> - the result will not keep you waiting, you'll see that <p>Hello</p> will pop out of the svg node and stand after it: <svg></svg><p>Hello</p>. And what point does this behavior describe? Correctly! Second! And then the question arises, and how to reproduce all the same thing with the first item?

How to describe the behavior for an item:

If the parser was originally created for the HTML fragment parsing algorithm, then act as described in the "any other start tag" entry below. (fragment case)


回答1:


The Parse Error link in the spec looks odd. Earlier revisions of the spec link to https://w3c.github.io/html/syntax.html#parse-errors which makes much more sense to me.

If the parser was originally created for the HTML fragment parsing algorithm, then act as described in the "any other start tag" entry below. (fragment case)

When the parser is parsing an HTML fragment, this is the next thing that the parser should do with the token after raising the parse error. It's independent of the raising of the parse error.

Otherwise ...

I.e. when the parser is parsing a whole HTML document, this is the next thing that the parser should do with the token after raising the parse error. It's independent of the raising of the parse error.

To see the difference between document parsing and fragment case parsing see this example. You will need to use Firefox or Edge, as Chrome does not appear to follow the spec here. And you will need to use the development tools to inspect the DOM created.

We have two divs, both of which are requested to contain <svg><p>Hello</p></svg>, the first is parsed as the document is parsed, the second is added by innerHTML. The second therefore uses the fragment case parsing and puts the <p> element inside the <svg> element. In the first div, the <p> element appears after the <svg> element.

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>Test case</title>
</head>
<body>
<div class="parsed normally"><svg><p>Hello</p></svg></div>
<div class="parsed fragment case"></div>
<script>
  document.querySelector(".parsed.fragment.case").innerHTML = "<svg><p>Hello</p></svg>";
</script>
</body>
</html>


来源:https://stackoverflow.com/questions/51807178/understanding-rules-for-parsing-tokens-in-foreign-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!