为什么React只允许一部分HTML实体? [英] Why does React only allow a subset of HTML entities?

查看:104
本文介绍了为什么React只允许一部分HTML实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这个问题上找到的唯一相关的文档只是说我可以在React中使用HTML实体。

The only relevant documentation I found on this issue simply says that I can use HTML entities in React.

然而,这并不完全如此。例如,& amp; & sum; work,而& vert ; & num; 不要。那是一个有意识的设计决定吗?如果是,原因是什么?

However, this doesn't entirely seem to be the case. For example, & and ∑ work, while | and # don't. Was that a conscious design decision? If yes, what is the reason?

示例:

Example:

const App = () => (
  <div>
    <h2>&amp;, &sum; - this works. &vert;, &num; - this doesn't.</h2>
  </div>
);

CodeSandbox示例

推荐答案

ReactJS仅支持 HTML4特殊实体

ReactJS only supports HTML4 special entities.

这可能是有意为之的,尽管文档对此并不清楚。我的猜测是,HTML实体通常用于屏蔽代码中使用的字符,但由于ReactJS具有Unicode支持,因此不需要使用可以用Unicode表示的新实体。

This might be intentional, although the documentation is unclear about it. My guess would be that HTML entities are commonly used to mask characters that are used in code as well, but since ReactJS has Unicode support, it's not as needed to make use of the new entities that can be represented in Unicode.

您可以在这里找到一份HTML4实体列表 a>。

这篇关于为什么React只允许一部分HTML实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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