From: Mischa POSLAWSKY Date: Mon, 31 Dec 2018 14:40:59 +0000 (+0100) Subject: edit/page: clean up trailing whitespace after save X-Git-Tag: v4.5~12 X-Git-Url: http://git.shiar.nl/minimedit.git/commitdiff_plain/e533b4e9662636f565f6e487b0ab99e768858370 edit/page: clean up trailing whitespace after save Strip invisible trash commonly left by less precise users. First implemented on and copied from poslawsky.nl/bio/. --- diff --git a/edit/page.js b/edit/page.js index ac2288a..4e389db 100644 --- a/edit/page.js +++ b/edit/page.js @@ -4,6 +4,8 @@ CKEDITOR.plugins.add('inlinesave', { exec: function (editor) { var pagename = window.location.pathname; var body = editor.getData(); + // trim trailing whitespace in non-empty paragraphs + body = body.replace(/((?!

).{3})(?:\s|\u200B)+(?=<\/p>)/g, '$1'); // empty line is equivalent to a paragraph break body = body.replace(/
\s*
/g, '

'); // wrap long line after each sentence