-
-
Save Marak/432457 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var intag = false, ret = [], tmpbuf = "", endtag = false; | |
| for (var i=0; i<html.length; i++) | |
| { | |
| var char = html[i]; | |
| if (char === '<') { | |
| intag = true; | |
| if (tmpbuf.length > 0) { | |
| ret.push(tmpbuf.replace("/","")); | |
| tmpbuf = ""; | |
| } | |
| } else if (char === '>') { | |
| intag = false; | |
| if (tmpbuf.length > 0) { | |
| var explode = tmpbuf.split(" "); | |
| var tag = explode.shift(); | |
| if (tag.indexOf("/") === -1) { | |
| ret.push(tag); | |
| var attrs ={}, attr, key, value; | |
| for (var j = 0; j < explode.length; j++) { | |
| attr = explode[j].split("="); | |
| attrs[attr[0]] = attr[1]; | |
| } | |
| ret.push(attrs); | |
| } | |
| tmpbuf=""; | |
| } | |
| } else { | |
| tmpbuf += char; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment