Skip to content

Instantly share code, notes, and snippets.

@lucaspiller
Created May 20, 2014 14:11
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 lucaspiller/c544024738bca2be598f to your computer and use it in GitHub Desktop.
Save lucaspiller/c544024738bca2be598f to your computer and use it in GitHub Desktop.
wysihtml5: Tidy HTML pasted from Word
var tidyHtml = function() {
var html = this.getValue();
// remove empty paragraphs
html = html.replace(/<p>(&nbsp;|\s+)?<\/p>/g, "");
html = html.replace(/<p><b>(&nbsp;|\s+)?<\/b><\/p>/g, "");
// remove newlines between words
html = html.replace(/([^>])\n([^<])/g, "$1 $2");
// remove excess whitespace
html = html.replace(/(\n\s*)+/g, "\n");
// add newlines between paragraphs
html = html.replace(/<\/p><p>/g, "</p>\n<p>");
this.setValue(html);
};
wysihtml5_options = {
events: {
"paste:composer": tidyHtml
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment