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

百度小程序中真机预览时仅包含br元素的节点会被全部移除 #409

Closed
QIUZAIYOU opened this issue Mar 8, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@QIUZAIYOU
Copy link

问题描述

如果 Html 字符串中出现仅包含 <br/> 的元素,形如:

<p><br/></p>
<p style="text-indent:2em;"><br/></p>
被解析出来的 Dom 节点结构如下:
[{
  ...
  "children": [{
    "name": "br",
    "attrs": {}
  }]
}]

此时在百度开发者工具中的模拟器里可以正常显示解析后的富文本,但是在真机预览时,包含这部分 Dom 节点的节点会整个
被百度自带的 <rich-text> 组件去除,导致文本内容显示不全。

百度开发者工具模拟器中显示完整:
01

真机APP预览中所有此类段落都被删除:
02

解决办法

我暂时通过向 mp-html\index.js 中的 setContent: function (e, n) {} 函数添加 e = e.replace(/<(\w+)([^>]*)><br\/><\/\1>/ig,'') 正则表达式,将仅包含<br/> 的元素全部删除解决了这个问题。
不知道有没有人遇到和我一样的问题,或者有什么更好的解决方法?

@jin-yufeng
Copy link
Owner

找到问题了,br 解析结果里有一个 undefined,可能导致了真机上异常,我修改一下

@QIUZAIYOU
Copy link
Author

感谢大佬。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants