Created
March 31, 2011 12:36
-
-
Save revolunet/896282 to your computer and use it in GitHub Desktop.
get innerText with linebreaks in Firefox. compatible syntaxhighlighter
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
| // | |
| // useful for executing safely embedded syntaxhighlighter code | |
| // | |
| function getInnerText(el, recurse) { | |
| // innerText emulation for Firefox | |
| // pereserve carriage returns | |
| // remove JS comments | |
| var inner = new Array(); | |
| if (el.childNodes[0] && el.childNodes[0].nodeValue) { | |
| var value = el.childNodes[0].nodeValue; | |
| // remove comments | |
| var re = /\s*\/\/.*\n/gm; | |
| value = value.replace(re,''); | |
| // check non empty | |
| if (value.replace(/\s/g,'')!='') { | |
| inner.push(value); | |
| } | |
| } | |
| for (var i=0;i<el.childNodes.length;i++) { | |
| inner = inner.concat(getInnerText( el.childNodes[i], true ) ); | |
| } | |
| if (recurse) { | |
| return inner; | |
| } | |
| else { | |
| return inner.join('\n'); | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment