Skip to content

Instantly share code, notes, and snippets.

@vrutberg
Created May 7, 2009 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vrutberg/108087 to your computer and use it in GitHub Desktop.
Save vrutberg/108087 to your computer and use it in GitHub Desktop.
var lines = document.getElementById('textArea').value.split("\n");
var prev = 0, str = "", blankLines = 0, total = "";
for(var n in lines) {
str = b[n];
if(str === "") {
blankLines++;
if(n == (lines.length-1) && blankLines !== 0) {
total += "rtItem.addNewLine("+ blankLines +");\n";
}
} else {
if(prev === "") {
total += "rtItem.addNewLine("+ blankLines +");\n";
blankLines = 0;
} else {
total += "rtItem.appendText(\""+ str +"\");\n";
}
}
prev = str;
}
alert(total);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment