Created
August 22, 2013 16:23
-
-
Save examinedliving/6309483 to your computer and use it in GitHub Desktop.
Extract as an html string the doctype tag and html open tag for parsing out doctypes and xmlns when altering html documents.
This file contains 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 getDocTypeStr(htmlStr){ | |
var getByXMLNS,docTypeStr, index=htmlStr.indexOf('<head>'); | |
getByXMLNS=function(){ | |
if(!htmlStr.match(/xmlns/i)){ | |
return false; | |
} else { | |
var index_tmp,docTypeStr,newIndex,index=htmlStr.indexOf('xmlns'), | |
sub_tmp=htmlStr.substr(index); | |
index_tmp=sub_tmp.indexOf('>'); | |
newIndex=index_tmp + index; | |
docTypeStr=htmlStr.substr(0,newIndex) + '>';} | |
return docTypeStr; | |
} | |
if(index===-1){ | |
docTypeStr=getByXMLNS() || '<html>'; | |
} else { | |
docTypeStr=htmlStr.substr(0,index);} | |
return docTypeStr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment