Created
May 20, 2014 14:11
-
-
Save lucaspiller/c544024738bca2be598f to your computer and use it in GitHub Desktop.
wysihtml5: Tidy HTML pasted from Word
This file contains 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
var tidyHtml = function() { | |
var html = this.getValue(); | |
// remove empty paragraphs | |
html = html.replace(/<p>( |\s+)?<\/p>/g, ""); | |
html = html.replace(/<p><b>( |\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