icindy / wxParse

wxParse-微信小程序富文本解析自定义组件,支持HTML及markdown解析
http://weappdev.com/
MIT License
7.75k stars 1.82k forks source link

报错:求解! TypeError: Cannot read property 'style' of undefined #265

Open 58bcbedf47bd91439c opened 6 years ago

58bcbedf47bd91439c commented 6 years ago

页面在解析的时候出现的,内容是后台提供的,有个别内容会出现这个问题,求告知原因

58bcbedf47bd91439c commented 6 years ago

TypeError: Cannot read property 'style' of undefined at Object.start (html2json.js? [sm]:169) at parseStartTag (htmlparser.js? [sm]:154) at RegExp.[Symbol.replace] () at String.replace () at HTMLParser (htmlparser.js? [sm]:77) at Object.html2json (html2json.js? [sm]:79) at Object.wxParse (wxParse.js? [sm]:35) at index.js? [sm]:88 at

lizhiyao commented 6 years ago

我也遇到了这个问题,是由于被解析的 html 字符串中出现了 <font>标签,但是该标签并没有任何属性导致的。

解决方案:

找到 /wxParse/html2json.js,这个文件中有这样一段代码:

// 处理font标签样式属性
if (node.tag === 'font' ) {
  // 省略
}

将上面代码修改为:

// 处理font标签样式属性
if (node.tag === 'font' && node.attr) {
  // 省略
}

问题就解决了。

58bcbedf47bd91439c commented 6 years ago

可以了,非常感谢