HTML 5自定义元素名称? [英] HTML 5 Custom element names?

查看:230
本文介绍了HTML 5自定义元素名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HTML 5规范中,解析器和规范声明元素名称可以是一切从一个字母开始,然后是字母数字字符。

现在的问题是如果我引入额外的元素而不是规范的一部分,但在符合指定语法方面是有效的。

当所有浏览器遇到具有自定义名称或未知名称的元素时,它们会做什么?这些元素是否像任何元素一样被处理过,或者被遗漏,剥离或替换?



HTML5编辑器的行为如何?



是否有任何规范中我忽略了关于有效元素标记名称的规定?
$ b

[更新]



由于规定了HTML元素名称的字母数字字符,因此规范在这里有误导性。在阅读HTML 5规范时,我怀疑这是所有元素名称都是如此。



这显然是错误的。在解析器部分,它声明一个元素名称只能以一个ASCII字母开始,并且在该字母后面除外:


tab( U + 0009)

LF(U + 000A)

FF(U + 000C)

U + 0020 SPACE />
/(U + 002F)

>(U + 003E)

U + 0000 NULL

EOF

除了那些需要特殊处理的错误或结束标记名称之外,所有其他可能接合的字符
$ b


其他任何
附件

- >将当前输入字符附加到当前标记标记的标记名称。

在我的现场测试中,还有几个解析器允许第一个字母附加的单码字符(至少它们与那些)。

[/ Update]

解决方案

在HTML 5规范中,p arser和规范说明
的元素名称可以是以字母开头的所有内容,并且可以由字母数字字符跟随

不正确。该规范规定,元素名称必须是该文档中明确列出的名称之一或其他适用规范中的名称之一。这些包括但不限于SVG和MathML。

该规范还包括HTML用户(如浏览器)的处理规范。这并没有描述什么是允许的,它描述了那些消费者应该对文档的每个字符做什么,而不管它包含允许还是不允许的事情。


现在问题是如果我引入额外的元素
不是规范的一部分,但在符合
指定语法方面是有效的。


遵循上述规则。 指定的语法是不相关的。该规范描述了消费者应该如何处理任何输入的字符流。


所有这些浏览器都做了什么当他们遇到自定义
但名字不明的元素时?这些元素是否被处理为任何元素或
被遗漏,剥离或替换?

它们被视为元素位于 http://www.w3.org/1999/xhtml 命名空间中, code> HTMLUnknownElement 接口。


HTML5编辑器的行为如何?


如果它们符合HTML5,那么在阅读HTML时它们的行为方式会相同。


是否有任何规范中我忽略了有关
有效元素标记名称的规范?

请参阅上面的第一段。另外还有自定义元素规范,它使任何元素名称以ASCII字母开头并包含连字符被认为是有效的。目前还不清楚该规范目前是否为HTML5适用规范,但如果不是,它很可能很快就会出现。


In HTML 5 specification the parser and the specification state that the element name can be everything starting with a letter and followed by alpha-numeric characters.

Now the question is what happens if I introduce additional elements not part of the specification but valid in terms of compliance to the specified syntax.

What do all those browsers do when they encounter elements with custom yet unknown name? Does those elements got treaten like any element or are they left out, stripped out or replaced?

How do for instance do HTML5 editor behave?

Is there anything in the specifications I have overlooked regarding valid element tag names?

[Update]

The specification was missleading here since it states the alpha-numerical character of the HTML element names. While reading a HTML 5 Specification, I missconcluded that this is true for all element names.

That is appearently wrong. In the parser section it states that a element name must only start with an ASCII letter and after that letter everthing except:

"tab" (U+0009)
"LF" (U+000A)
"FF" (U+000C)
U+0020 SPACE
"/" (U+002F)
">" (U+003E)
U+0000 NULL
EOF

Beside those mentioned characters which require special treatment involving errors or ending the tag name all other possible characters seam to be allowed.

Anything else
--> Append the current input character to the current tag token's tag name.

From my field test also additional uni-code letters are allowed for the first letter by several parsers (at least they are graceful with those).

[/Update]

解决方案

In HTML 5 specification the parser and the specification state that the element name can be everything starting with a letter and followed by alpha-numeric characters.

Incorrect. The specification states that the element name must be one of the names explicitly listed in that document, or in another applicable specification. These include but are not limited to SVG and MathML.

The specification also includes a processing specification for consumers of HTML, such as browsers. This doesn't describe what's "allowed", it describes what those consumers should do with each character of the document regardless of whether it contains things that are allowed or not allowed.

Now the question is what happens if I introduce additional elements not part of the specification but valid in terms of compliance to the specified syntax.

The above rules are followed. The "specified syntax" is irrelevant. The specification describes what the consumer should do for any input stream of characters.

What do all those browsers do when they encounter elements with custom yet unknown name? Does those elements got treated like any element or are they left out, stripped out or replaced?

They are treated as elements in the http://www.w3.org/1999/xhtml namespace which implement the HTMLUnknownElement interface.

How for instance do HTML5 editor behave?

If they are HTML5 compliant they will behave the same way when reading in the HTML.

Is there anything in the specifications I have overlooked regarding valid element tag names?

See the first paragraph above. Also the Custom Elements spec which makes any element name starting with an ASCII letter and containing a hyphen to be considered valid. It is unclear whether that specification is currently an "HTML5 applicable specification" but if not, it will very probably be one soon.

这篇关于HTML 5自定义元素名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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