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

feat: remove <style></style> 标签信息 #342

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pages/index/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ Page({
<video src="http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400"></video>
</div>
</div>


<style type="text/css">
body{
padding: 4px;
}
</style>

<div style="margin-top:10px;">
<h3 style="color: #000;">支持的标签</h3>
Expand Down
23 changes: 21 additions & 2 deletions wxParse/html2json.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ function removeDOCTYPE(html) {
.replace(/<.*!DOCTYPE.*\>\n/, '');
}

/**
* 去除富文本字符串中的 style 标签
* @param {String} html 富文本字符串
*/
function removeStyleCss(html) {
return html
.replace(/\<style(.|\n)*\<\/style\>/gm, '');
}

function trimHtml(html) {
return html
.replace(/\r?\n+/g, '')
Expand All @@ -61,11 +70,21 @@ function trimHtml(html) {
.replace(/[ ]+</ig, '<')
}

/**
* 对富文本的某些特殊信息进行过滤
* @param {String} html 富文本字符串
*/
function filterHtml(html){
html = removeDOCTYPE(html);
html = removeStyleCss(html);
html = trimHtml(html);
return html
}


function html2json(html, bindName) {
//处理字符串
html = removeDOCTYPE(html);
html = trimHtml(html);
html = filterHtml(html);
html = wxDiscode.strDiscode(html);
//生成node节点
var bufArray = [];
Expand Down