-
-
Save os0x/164430 to your computer and use it in GitHub Desktop.
シンプルな HTMLPaser / scriptを削る正規表現はjAutoPagerizeから
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
function HTMLStringToDOM(str){ | |
var html = String(str).replace(/<script(?:[ \t\r\n][^>]*)?>[\S\s]*?<\/script[ \t\r\n]*>|<\/?(?:i?frame|html|script|object)(?:[ \t\r\n][^<>]*)?>/gi, ' '); | |
var htmlDoc = document.implementation.createHTMLDocument ? | |
document.implementation.createHTMLDocument('HTMLParser') : | |
document.implementation.createDocument(null, 'html', null); | |
var range = document.createRange(); | |
range.selectNodeContents(document.documentElement); | |
htmlDoc.documentElement.appendChild(htmlDoc.importNode(range.createContextualFragment(html),true)); | |
return htmlDoc; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment