HTML5 规范是否说要忽略 HTML 评论中的 CSS?

Does the HTML5 spec say to ignore CSS inside HTML comments?

谁能告诉我 HTML5 规范中的以下段落是什么意思?关于<style>元素内容的处理:

https://www.w3.org/TR/html5/document-metadata.html#the-style-element

All descendant elements must be processed, according to their semantics, before the style element itself is evaluated. For styling languages that consist of pure text (as opposed to XML), user agents must evaluate style elements by passing the concatenation of the contents of all the Text nodes that are children of the style element (not any other nodes such as comments or elements), in tree order, to the style system. For XML-based styling languages, user agents must pass all the child nodes of the style element to the style system.

对我来说,这听起来像是 HTML 解析器应该在将生成的文本发送到样式系统之前删除 <style> 元素内的所有 HTML 元素和注释。

HTML 评论中的内容也是一个文本节点,但它不是样式元素的直接子元素,因此不应包含在发送到样式系统的文本中。

现代浏览器似乎不对样式元素内部的注释或元素进行任何处理,而是将样式内容视为与 HTML 一致的 CDATA 4. 但是 HTML5 规范中的这一段说这是不正确的行为不是吗?如果不是,我错过了什么?

将注释节点或元素节点放入 style 元素的唯一方法是通过 DOM 操作——将注释或元素放入 style 元素中64=] 在 HTML 解析器已经解析了文档之后。

所以规范并不是说 HTML 解析器应该删除 <style>…</style> 标记内的所有 HTML 元素和注释。如果规范打算明确说明。

HTML 解析器将 <style>…</style> 标记中的所有内容解析为文本——包括任何看起来像评论或看起来像元素的内容。

因此,HTML 解析器没有要删除的注释或元素,它们只是文本。

Where in the spec does it say that the content is pure text?

html.spec.whatwg.org/multipage/syntax.html#raw-text-elementsstyle 内容是“原始文本”。

The HTML 4 spec states clearly that the content of style elements is CDATA. That is what I am looking for but I can't find it in the HTML5 spec.

当前 HTML 规范称为“原始文本”的内容与 HTML4 规范中的 CDATA 基本相同。

Where does it say that it is terminated by the string "</style"?

查看解析算法的这些步骤:

  1. https://html.spec.whatwg.org/multipage/syntax.html#rawtext-state
  2. https://html.spec.whatwg.org/multipage/syntax.html#rawtext-less-than-sign-state
  3. https://html.spec.whatwg.org/multipage/syntax.html#rawtext-end-tag-open-state
  4. https://html.spec.whatwg.org/multipage/syntax.html#rawtext-end-tag-name-state

最后一步引用 the definition of “appropriate end tag token”:

An appropriate end tag token is an end tag token whose tag name matches the tag name of the last start tag to have been emitted from this tokenizer, if any.

因此在解析 script 内容的原始文本时,发出的最后一个开始标记是 <script> 开始标记,因此“适当的结束标记标记”是 </script>.