Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

实体字符未能正确的显示 #418

Closed
zhbhun opened this issue Apr 1, 2022 · 3 comments
Closed

实体字符未能正确的显示 #418

zhbhun opened this issue Apr 1, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@zhbhun
Copy link

zhbhun commented Apr 1, 2022

使用环境

  • 平台:微信小程序
  • 基础库:2.13.0

问题描述

mp-html 只内置了部分的实体字符配置,如果服务端下发的富文本包含其他类型的实体字符会导致这些实体字符无法正确显示。

例如:↑ 需要显示 ↑。

复现方式

<mp-html content="&uarr;" />

我自己 fork 了一份源码,基于 html-entities 修改了实体字符解码的实现来应急修复项目问题,看下这块是否需要内置,还是以插件的形式交给外部定制。

https://github.com/jin-yufeng/mp-html/blob/8b4ff8f7c5/src/miniprogram/parser.js#L110

      // ...
      let entity = config.entities[code]
      if (!entity) {
        const entityCode = '&' + code + ';'
        entity = decodeHTMLEntity(entityCode)
        if (entity === entityCode) {
          entity = undefined
        }
      }
      if (entity || (code === 'amp' && amp)) {
        str = str.substr(0, i) + (entity || '&') + str.substr(j + 1)
      }
      // ...
@jin-yufeng
Copy link
Owner

把需要用到实体编码的添加到 这里 即可,全部实体所占空间比较大,因此只配置了一些常用的

@jin-yufeng
Copy link
Owner

除了箭头还用到哪些?不多且比较常用的话可以内置一下

@zhbhun
Copy link
Author

zhbhun commented Apr 2, 2022

标准里的有点多,我看 htm-entities 里实体字符的映射配置就有 70 多 KB 了,可能还是得交给外部定制吧。

https://html.spec.whatwg.org/multipage/named-characters.html#named-character-references

@jin-yufeng jin-yufeng added the enhancement New feature or request label May 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants