Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@source-data
Created October 1, 2008 15:26
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 source-data/14100 to your computer and use it in GitHub Desktop.
Save source-data/14100 to your computer and use it in GitHub Desktop.
CmdUtils.CreateCommand({
names: ["rewrap"],
arguments: [{role: "object",
nountype: noun_arb_text,
label: "input"}],
help: "removes unnecessary carriage returns and strings of spaces",
execute: function(arguments) {
var selectedText=arguments.text;
selectedText=selectedText.replace(/[\r\n]{2}/g,"§#!");
selectedText=selectedText.replace(/[\r\n]+/g," ");
selectedText=selectedText.replace(/§#!/g,"\r\r");
selectedText=selectedText.replace(/ +/g," ");
CmdUtils.setSelection("",{text: selectedText});
},
preview: function(pblock, arguments) {
var selectedText=arguments.text;
selectedText=selectedText.replace(/[\r\n]{2}/g,"§#!");
selectedText=selectedText.replace(/[\r\n]+/g," ");
selectedText=selectedText.replace(/§#!/g,"\r\r");
selectedText=selectedText.replace(/ +/g," ");
pblock.innerHTML=selectedText;
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment