(
html, //字符串模板
options //参数
)
| 12573 | } |
| 12574 | |
| 12575 | function parseHTML( |
| 12576 | html, //字符串模板 |
| 12577 | options //参数 |
| 12578 | ) { |
| 12579 | var stack = []; // parseHTML 节点标签堆栈 |
| 12580 | var expectHTML = options.expectHTML; //true |
| 12581 | var isUnaryTag$$1 = options.isUnaryTag || no; //函数匹配标签是否是 'area,base,br,col,embed,frame,hr,img,input,isindex,keygen, link,meta,param,source,track,wbr' |
| 12582 | var canBeLeftOpenTag$$1 = options.canBeLeftOpenTag || no; //函数 //判断标签是否是 'colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr,source' |
| 12583 | var index = 0; |
| 12584 | var last, // |
| 12585 | lastTag; // |
| 12586 | console.log(html) |
| 12587 | |
| 12588 | |
| 12589 | |
| 12590 | while (html) { //循环html |
| 12591 | last = html; // |
| 12592 | // Make sure we're not in a plaintext content element like script/style 确保我们不在像脚本/样式这样的纯文本内容元素中 |
| 12593 | if ( |
| 12594 | !lastTag || //lastTag 不存在 |
| 12595 | !isPlainTextElement(lastTag) // 如果标签不是script,style,textarea |
| 12596 | ) { |
| 12597 | |
| 12598 | var textEnd = html.indexOf('<'); //匹配开始标签或者结束标签的位置 |
| 12599 | if (textEnd === 0) { //标识是开始标签 |
| 12600 | // Comment: |
| 12601 | if (comment.test(html)) { //匹配 开始字符串为<!--任何字符串,注释标签 如果匹配上 |
| 12602 | var commentEnd = html.indexOf('-->'); //获取注释标签的结束位置 |
| 12603 | |
| 12604 | if (commentEnd >= 0) { //如果注释标签结束标签位置大于0,则有注释内容 |
| 12605 | console.log(html.substring(4, commentEnd)) |
| 12606 | if (options.shouldKeepComment) { //shouldKeepComment为真时候。获取注释标签内容 |
| 12607 | |
| 12608 | //截取注释标签的内容 |
| 12609 | options.comment(html.substring(4, commentEnd)); |
| 12610 | } |
| 12611 | //截取字符串重新循环 while 跳出循环就是靠该函数,每次匹配到之后就截取掉字符串,知道最后一个标签被截取完没有匹配到则跳出循环 |
| 12612 | advance(commentEnd + 3); |
| 12613 | continue |
| 12614 | } |
| 12615 | } |
| 12616 | |
| 12617 | //这里思路是先匹配到注释节点,在匹配到这里的ie浏览器加载样式节点 |
| 12618 | // http://en.wikipedia.org/wiki/Conditional_comment#Downlevel-revealed_conditional_comment |
| 12619 | if (conditionalComment.test(html)) { //匹配开始为 <![ 字符串 <![endif]--> 匹配这样动态加ie浏览器的 字符串 <!--[if IE 8]><link href="ie8only.css" rel="stylesheet"><![endif]--> |
| 12620 | //匹配ie浏览器动态加样式结束符号 |
| 12621 | var conditionalEnd = html.indexOf(']>'); |
| 12622 | |
| 12623 | if (conditionalEnd >= 0) { |
| 12624 | //截取字符串重新循环 while 跳出循环就是靠该函数,每次匹配到之后就截取掉字符串,知道最后一个标签被截取完没有匹配到则跳出循环 |
| 12625 | advance(conditionalEnd + 2); |
| 12626 | continue |
| 12627 | } |
| 12628 | } |
| 12629 | |
| 12630 | // Doctype: |
| 12631 | //匹配html的头文件 <!DOCTYPE html> |
| 12632 | var doctypeMatch = html.match(doctype); |
no test coverage detected