Skip to content

Instantly share code, notes, and snippets.

@revolunet
Created March 31, 2011 12:36
Show Gist options
  • Select an option

  • Save revolunet/896282 to your computer and use it in GitHub Desktop.

Select an option

Save revolunet/896282 to your computer and use it in GitHub Desktop.
get innerText with linebreaks in Firefox. compatible syntaxhighlighter
//
// 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