python - 在 Plotly 中,使用 HTML,为什么一些希腊字母可以使用小数,但不能使用实体名称?
问题描述
在我的 Plotly 图形标题中,我需要使用希腊字母,对于某些字母,我可以直接使用实体名称:
μ
它会呈现正确的希腊字母 mu。ω
但是,当我用or对 omega 或 psi 做同样的事情时,ψ
我只会得到用拉丁字符写成的单词,带有 '&' 和 ';' 但不是相应的希腊语。这是结果的图像:
但是,使用十进制代码可以按预期工作:layout = go.Layout(title='ω #968;')
解决方案
我认为这与 javascript 后端有关,尤其是entityToUnicode
在svg_text_utils.js中。
所以我认为这$mu;
是唯一可以使用的希腊字母(因为它是专门entityToUnicode
与满是其他字符的手一起处理的)。
来自 svg_text_utils.js:
/*
* N.B. HTML entities are listed without the leading '&' and trailing ';'
* https://www.freeformatter.com/html-entities.html
*
* FWIW if we wanted to support the full set, it has 2261 entries:
* https://www.w3.org/TR/html5/entities.json
* though I notice that some of these are duplicates and/or are missing ";"
* eg: "&", "&", "&", and "&" all map to "&"
* We no longer need to include numeric entities here, these are now handled
* by String.fromCodePoint/fromCharCode
*
* Anyway the only ones that are really important to allow are the HTML special
* chars <, >, and &, because these ones can trigger special processing if not
* replaced by the corresponding entity.
*/
var entityToUnicode = {
mu: 'μ',
amp: '&',
lt: '<',
gt: '>',
nbsp: ' ',
times: '×',
plusmn: '±',
deg: '°'
};
推荐阅读
- python - Python - 如何反编译 Python 脚本?
- mysql - JPA Hibernate - 多种数据库方言和 nvarchar(length) 数据类型
- actions-on-google - 谷歌操作:使用操作 sdk 退出对话不会调用 actions.intent.CANCEL
- java - 在 JAVA 中,如何以字符串格式计算两个日期之间的时间差,其中两个时间都采用不同的时间格式和时区?
- php - Magento 2 URL重写问题:指定商店的URL密钥已经存在
- angular - 命令 ncu -u 到底是做什么的?
- wordpress - 我不存储任何数据的联系表上的 GDPR
- python - 除了 HoG 特征,还有更好的方法来识别真正的棋子图像吗?
- unit-testing - Kafka 策略是否与测试环境兼容?
- angular - 为什么启用 no-unsafe-any 时 tslint 将强类型参数的属性标记为 any