os0x (owner)

Fork Of

Revisions

gist: 164430 Download_button fork
public
Description:
シンプルな HTMLPaser 、大抵はこれで十分なはず scriptを削る正規表現はjAutoPagerizeから(Thx! drry) なお、これはライブラリではなく、コードスニペットです 煮るなり焼くなりお好きにどうぞ
Public Clone URL: git://gist.github.com/164430.git
Embed All Files: show embed
HTMLStringToDOM.js #
1
2
3
4
5
6
7
8
9
10
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;
}