(html, handler)
| 117 | } |
| 118 | |
| 119 | function HTMLParser(html, handler) { |
| 120 | var stack = [], lastTag; |
| 121 | var attribute = attrForHandler(handler); |
| 122 | var last, prevTag, nextTag; |
| 123 | while (html) { |
| 124 | last = html; |
| 125 | // Make sure we're not in a script or style element |
| 126 | if (!lastTag || !special(lastTag)) { |
| 127 | var textEnd = html.indexOf('<'); |
| 128 | if (textEnd === 0) { |
| 129 | // Comment: |
| 130 | if (/^<!--/.test(html)) { |
| 131 | var commentEnd = html.indexOf('-->'); |
| 132 | |
| 133 | if (commentEnd >= 0) { |
| 134 | if (handler.comment) { |
| 135 | handler.comment(html.substring(4, commentEnd)); |
| 136 | } |
| 137 | html = html.substring(commentEnd + 3); |
| 138 | prevTag = ''; |
| 139 | continue; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | // https://en.wikipedia.org/wiki/Conditional_comment#Downlevel-revealed_conditional_comment |
| 144 | if (/^<!\[/.test(html)) { |
| 145 | var conditionalEnd = html.indexOf(']>'); |
| 146 | |
| 147 | if (conditionalEnd >= 0) { |
| 148 | if (handler.comment) { |
| 149 | handler.comment(html.substring(2, conditionalEnd + 1), true /* non-standard */); |
| 150 | } |
| 151 | html = html.substring(conditionalEnd + 2); |
| 152 | prevTag = ''; |
| 153 | continue; |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | // Doctype: |
| 158 | var doctypeMatch = html.match(doctype); |
| 159 | if (doctypeMatch) { |
| 160 | if (handler.doctype) { |
| 161 | handler.doctype(doctypeMatch[0]); |
| 162 | } |
| 163 | html = html.substring(doctypeMatch[0].length); |
| 164 | prevTag = ''; |
| 165 | continue; |
| 166 | } |
| 167 | |
| 168 | // End tag: |
| 169 | var endTagMatch = html.match(endTag); |
| 170 | if (endTagMatch) { |
| 171 | html = html.substring(endTagMatch[0].length); |
| 172 | endTagMatch[0].replace(endTag, parseEndTag); |
| 173 | prevTag = '/' + endTagMatch[1].toLowerCase(); |
| 174 | continue; |
| 175 | } |
| 176 |
nothing calls this directly
no test coverage detected
searching dependent graphs…