sbfkcel / towxml

微信小程序HTML、Markdown渲染库
https://github.com/sbfkcel/towxml/wiki
2.53k stars 320 forks source link

当HTML标签不规范时,会解释失败 #45

Closed liuyong closed 6 years ago

liuyong commented 6 years ago

如题,当HTML标签不规范时,会解释失败(这里标签"< "和" >" 存在空格 ): image

var tab1_dataSource = '

< section style = "max-width: 100%;" >

一年一度的苗族盛会、雷山【苗年】等你来!< /p>< p style = "max-width: 100%; min-height: 1em;" > 西江千户苗寨、镇远古镇、雷山苗年节,精彩不断 & nbsp; 好戏连连,深度体验黔东南原生态的浓浓民族节日风情,和苗族一起欢度苗年!!!< /p>< /section>< /section>< /section>< p style = "max-width: 100%; min-height: 1em; color: rgb(51, 51, 51); font-family: -apple-system-font, system-ui, "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif; letter-spacing: 0.544px; text-align: justify;" ><img data - type="jpeg" class="" data - ratio="0.5351851851851852" data - w="1080" _width = "677px" src = "https://mmbiz.qpic.cn/mmbiz_jpg/neicQU2gdk6AdjwThexH8ucG2Hd4xfRl48ZM0Z3NfG1lpOOHic7gBgibELbKsnuB85ewZUbWfO54N9dD1tiacOEKcg/640?wx_fmt=jpeg&wx_co=1" data - fail="0" style = "width: 100%; visibility: visible !important;" />

< section style = "padding: 20px 8px 15px; max-width: 100%; color: rgb(51, 51, 51); font-family: -apple-system-font, system-ui, "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif; font-size: 1em; letter-spacing: 0.544px; text-align: justify; white-space: normal; text-decoration: inherit; line-height: 25.6px; width: 556px; border: 0px none;" class="_135editor" >
<section data - width="100%" style = "max-width: 100%; font-size: 1em; text-decoration: inherit; color: #fefefe; border-color: #ef7060; display: inline-block; width: 100%;" >

随心出发< /p>< /section>< /section>< /section>< section class="" style = "max-width: 100%;" >

<img data - width="100%" data - type="other" class="" data - ratio="0.8297872340425532" data - w="141" _width = "100%" src = "https://mmbiz.qpic.cn/mmbiz/Ljib4So7yuWhdYlRTur1gpunIhiaDqiaMGicXfviaiauhX1QhcvtEhSlTqc44sewQTaQ8cyhZp5KYo7XkyPfvg1iaePSQ/640?wx_fmt=other&wx_co=1" data - fail="0" style = "display: block; width: 100%; visibility: visible !important;" />
< section style = "padding-top: 1em; padding-bottom: 1em; max-width: 100%;" >
< section style = "max-width: 100%; border-bottom: 4px solid #f3a2a2;" >
活动亮点< /section>< /section>< section style = "max-width: 100%; width: 4px; height: 32px; background: #f3a2a2; border-top-right-radius: 2px; border-bottom-right-radius: 2px;" >
< /section>< /section>< /section>< /section>< section style = "max-width: 100%; width: 1.2em;" ><img data - width="100%" data - type="other" class="" data - ratio="0.8297872340425532" data - w="141" _width = "100%" src = "https://mmbiz.qpic.cn/mmbiz/Ljib4So7yuWhdYlRTur1gpunIhiaDqiaMGicXfviaiauhX1QhcvtEhSlTqc44sewQTaQ8cyhZp5KYo7XkyPfvg1iaePSQ/640?wx_fmt=other&wx_co=1" data - fail="0" style = "display: block; width: 100%; visibility: visible !important;" />
< /section>< /section>< section class="" style = "max-width: 100%;" >

火热过苗年< /p>< /section>< /section>< section style = "margin-top: 4px; margin-bottom: 10px; max-width: 100%; border-top: 1px dashed #86c4ba;" > 苗年,类似汉族的春节,是苗家人的大年,为苗族人民一年一度最隆重的传统节日。苗族全民鼓声擂动、芦笙响彻天穹,大家一起载歌载舞 < /span>< /section>< /section>< section style = "max-width: 100%;" > < /section>< /section>< /section>< p style = "max-width: 100%; min-height: 1em; text-align: left;" ><img data - type="jpeg" class="" data - ratio="0.4703125" data - w="640" _width = "640px" src = "https://mmbiz.qpic.cn/mmbiz_jpg/q1nhBicXtWBJ3hahWVDTR7FNUgiaKQF0N14VLZMReqy1Q1r5q5tPkuAic5tj4c2WOSicicYrV6C7IskkIHpibklTcDibQ/640?wx_fmt=jpeg&wx_co=1" data - fail="0" style = "width: 100%; visibility: visible !important;" />

< p style = "max-width: 100%; min-height: 1em; text-align: left;" > 雷山苗族至今仍保留“以十月为岁首”的纪年法。每年的农历十月,雷山苗寨一派欢腾,开展极富特色的辞旧迎新活动。苗年集苗族祭祀、感恩、庆祝、玩乐为一体, 雷山苗族中最隆重、最能全面体现苗族节日文化的一个节日。< /p>< /section>< /section>< /section>< /section>< /section>< p >

'; //将markdown内容转换为towxml数据 let data = app.towxml.toJson( tab1_dataSource, // markdownhtml文本内容 'html', // markdownhtml that // 当前页面的this(2.1.0或以上的版本该参数不可省略) ); //设置文档显示主题,默认'light' data.theme = 'dark';

//设置数据
this.setData({
  article: data
})
sbfkcel commented 6 years ago

不是BUG,解析库不会去再额外校验HTML的合法性。请自行将html改成合法的格式。