Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #3205 from houyhea/dev-1.5.0
Browse files Browse the repository at this point in the history
修改htmlParser的正则表达式,增强html解析的容错能力
  • Loading branch information
Phinome authored Feb 10, 2017
2 parents caa6c01 + 52d1fa7 commit fe3fc76
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions _src/core/htmlparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
var htmlparser = UE.htmlparser = function (htmlstr,ignoreBlank) {
//todo 原来的方式 [^"'<>\/] 有\/就不能配对上 <TD vAlign=top background=../AAA.JPG> 这样的标签了
//先去掉了,加上的原因忘了,这里先记录
var re_tag = /<(?:(?:\/([^>]+)>)|(?:!--([\S|\s]*?)-->)|(?:([^\s\/<>]+)\s*((?:(?:"[^"]*")|(?:'[^']*')|[^"'<>])*)\/?>))/g,
//var re_tag = /<(?:(?:\/([^>]+)>)|(?:!--([\S|\s]*?)-->)|(?:([^\s\/<>]+)\s*((?:(?:"[^"]*")|(?:'[^']*')|[^"'<>])*)\/?>))/g,
//以上的正则表达式无法匹配:<div style="text-align:center;font-family:" font-size:14px;"=""><img src="http://hs-album.oss.aliyuncs.com/static/27/78/35/image/20161206/20161206174331_41105.gif" alt="" /><br /></div>
//修改为如下正则表达式:
var re_tag = /<(?:(?:\/([^>]+)>)|(?:!--([\S|\s]*?)-->)|(?:([^\/\s>]+)((?:\s+[\w\-:.]+(?:\s*=\s*?(?:(?:"[^"]*")|(?:'[^']*')|[^\s"'\/>]+))?)*)[\S\s]*?(\/?)>))/g,
re_attr = /([\w\-:.]+)(?:(?:\s*=\s*(?:(?:"([^"]*)")|(?:'([^']*)')|([^\s>]+)))|(?=\s|$))/g;

//ie下取得的html可能会有\n存在,要去掉,在处理replace(/[\t\r\n]*/g,'');代码高量的\n不能去除
Expand Down Expand Up @@ -194,4 +197,4 @@ var htmlparser = UE.htmlparser = function (htmlstr,ignoreBlank) {
text(currentParent, htmlstr.slice(nextIndex));
}
return root;
};
};

0 comments on commit fe3fc76

Please sign in to comment.