【问题标题】:unfamiliar html/react tag row- , col-不熟悉的 html/react 标签 row- , col-
【发布时间】:2018-11-03 16:28:37
【问题描述】:

我正在浏览一个比较流行的 repo 的源代码,不知道下面的标签是什么。

见https://github.com/pusher/react-slack-clone/blob/master/src/index.js#L243

 <row->
              <col->
   ....
              </col->
</row->

为什么在 html 标签后面加上-?以及它如何成为可接受的标签?

【问题讨论】:

    标签: html reactjs


    【解决方案1】:

    他们是custom elements。关于标签的有效性,您可能已经注意到它没有在代码中的任何地方定义。按照spec的第5步,它是有效的,并且具有Element的命名空间。

    有关自定义元素的更高级别概述,请查看MDN tutorial 关于使用自定义元素。

    补充说明:这些标签可以替换为带有类的常规&lt;div&gt;标签,功能也一样。

    【讨论】:

      【解决方案2】:

      这很可能是源代码中未被注意到的错误(可能是通过使用搜索和替换?)。 React 接受以 - 字符结尾的元素名称,并通过 document.createElement() 像任何其他元素一样呈现给 DOM(有关简单示例,请参见此处:https://jsfiddle.net/nso3gjpw/)。由于浏览器对奇怪的 html 非常宽容,它只是将元素呈现为一个未知的自定义元素,其行为大致类似于 span 元素。 row- 和 col- 元素也有样式 (https://github.com/pusher/react-slack-clone/blob/master/src/index.css#L73)。

      在 Blink 渲染引擎源代码中,给出了以下标签名称的定义(https://www.w3.org/TR/REC-xml/#NT-CombiningChar):

      // DOM Level 2 says (letters added):
      //
      // a) Name start characters must have one of the categories Ll, Lu, Lo, Lt, Nl.
      // b) Name characters other than Name-start characters must have one of the categories Mc, Me, Mn, Lm, or Nd.
      // c) Characters in the compatibility area (i.e. with character code greater than #xF900 and less than #xFFFE) are not allowed in XML names.
      // d) Characters which have a font or compatibility decomposition (i.e. those with a "compatibility formatting tag" in field 5 of the database -- marked by field 5 beginning with a "<") are not allowed.
      // e) The following characters are treated as name-start characters rather than name characters, because the property file classifies them as Alphabetic: [#x02BB-#x02C1], #x0559, #x06E5, #x06E6.
      // f) Characters #x20DD-#x20E0 are excluded (in accordance with Unicode, section 5.14).
      // g) Character #x00B7 is classified as an extender, because the property list so identifies it.
      // h) Character #x0387 is added as a name character, because #x00B7 is its canonical equivalent.
      // i) Characters ':' and '_' are allowed as name-start characters.
      // j) Characters '-' and '.' are allowed as name characters.
      //
      // It also contains complete tables. If we decide it's better, we could include those instead of the following code.
      

      这里特别重要的是规则j) Characters '-' and '.' are allowed as name characters.

      【讨论】:

      • This commit 让我很难相信标签是错误添加的。此外,我想这些标签会被注意到并修复,因为元素及其伴随的样式自首次提交以来已经移动了几次。
      • @JosiahNunemaker 你是完全正确的,我认为他们是在this commit 中介绍的。也许作者出于某种原因打算使用col elements,其中React refuses to render 与子元素和col- 元素是最简单的出路。
      • 好发现!我什至没有想到这一点。不过绝对是一个有趣的解决方法。
      猜你喜欢
      • 1970-01-01
      • 2021-01-06
      • 1970-01-01
      • 2017-08-03
      • 1970-01-01
      • 2010-10-08
      • 1970-01-01
      • 2021-09-17
      • 2015-07-15
      相关资源
      最近更新 更多