了解解析外国内容中的令牌的规则 [英] Understanding rules for parsing tokens in foreign content

查看:27
本文介绍了了解解析外国内容中的令牌的规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,它与条件中执行指令的阶段有关.我不太明白每条指令的含义以及执行时间.在这种情况下,借助 UA 的示例将非常有帮助.

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.

这里有一段来自 规范:

  • 开始标记是以下之一:b, big, blockquote, body, br, center, code, dd, div "dl", "dt", "em",嵌入"、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"
  • 如果标记具有任何名为颜色"、面"或大小"的属性,则起始标记名称为字体"

解析错误.

如果解析器最初是为 HTML 片段解析而创建的算法,然后按照任何其他开始标签"条目中的描述进行操作以下.(片段案例)

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)

否则:

从打开的元素栈中弹出一个元素,然后一直弹出开放元素堆栈中的更多元素,直到当前节点是 MathML 文本集成点、HTML 集成点或HTML 命名空间中的元素.

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.

然后,重新处理令牌.

为了避免误解,我在引用中以常用字体命名了说明.规范中也有类似的地方,但我很难正确解释它们,因为不清楚在哪些方面存在差异.

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?

下一句:

如果解析器最初是为 HTML 片段解析算法创建的,则按照下面任何其他开始标记"条目中的描述进行操作.(片段案例)

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?

接下来我们看到铭文Othewise"——它告诉我们所有这些指令不能一起执行.但尽管这个问题相同,引用:

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:

从打开的元素栈中弹出一个元素,然后一直弹出开放元素堆栈中的更多元素,直到当前节点是 MathML 文本集成点、HTML 集成点或HTML 命名空间中的元素.

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.

然后,重新处理令牌.

这句话是指解析错误"还是完全不同?

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

总结一下:只有2条执行指令,其中一条是在parser最初是为HTML片段解析算法创建的条件下执行的,另一条指令在前一条指令没有的情况下执行没有通过测试.而这一切都是解析错误".

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.

更新 1

我认为需要补充这个问题,以便您可以充分利用它.

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

您可能已经注意到,我们正坐在解析外国内容的章节中.如您所见,本章旨在分析外国内容中的内容,而外国内容就是节点 svg 或 math 中的全部内容.

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.

所以假设我们坐在节点 svg 中,在这个 svg 中,我们放置了列表中调用解析错误的任何标签.试着这样写:<svg><p>Hello</p></svg> - 结果不会让你等待,你会看到 将弹出 svg 节点并站在它后面:</svg><p>Hello</p>.这种行为描述了哪一点?正确!第二!那么问题来了,如何用第一项重现所有相同的东西?

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:

如果解析器最初是为 HTML 片段解析算法创建的,则按照下面任何其他开始标记"条目中的描述进行操作.(片段案例)

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)

推荐答案

规范中的解析错误链接看起来很奇怪.https://w3c.github.io/html 的规范链接的早期修订版/syntax.html#parse-errors 这对我来说更有意义.

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.

如果解析器最初是为 HTML 片段解析算法创建的,则按照下面任何其他开始标记"条目中的描述进行操作.(片段案例)

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)

当解析器解析 HTML 片段时,这是解析器在引发解析错误后应该对令牌做的下一件事情.它与解析错误的引发无关.

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.

否则……

即当解析器解析整个 HTML 文档时,这是解析器在引发解析错误后应该对令牌做的下一件事情.它与解析错误的引发无关.

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.

要查看文档解析和片段大小写解析之间的区别,请参阅此示例.您需要使用 Firefox 或 Edge,因为 Chrome 似乎不符合此处的规范.您将需要使用开发工具来检查创建的 DOM.

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.

我们有两个div,都要求包含<svg><p>Hello</p></svg>,第一个在解析文档时解析,第二个是由innerHTML添加的.因此,第二个使用片段大小写解析并将

元素放在 元素中.在第一个 div 中,

元素出现在 元素之后.

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>

这篇关于了解解析外国内容中的令牌的规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆