微信小程序处理富文本

在官网(https://developers.weixin.qq.com/miniprogram/dev/component/rich-text.html
)已经说的很清楚用标签rich-text就可以处理大部分html标签,其中有个别标签不能兼容,
小弟只对section的标签做了兼容,废话少说,直接上代码

在项目中的js文件中:

var html = '<p>12321311<span style="text-decoration: underline;">321321321321<span style="text-decoration: line-through;">3213213213213231asdasdasda<img src="http://sgsource.sougewang.com/image/know/30b64859b849008ca2cb83bd3934ea4c.png" /><video controls="controls" width="300" height="150"><source src="http://sgsource.sougewang.com/video/know/4c83a1703c5f8a82efc26519be342748.mp4" type="video/mp4" /></video></span></span></p>'
data: {
    htmlSnip:html.replace(/<section/g, '<div').replace(/\/section>/g, '/div>'),
  },

在wxml页面:

<rich-text nodes="{{htmlSnip}}"></rich-text>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容