edit/page: clean up trailing whitespace after save
authorMischa POSLAWSKY <perl@shiar.org>
Mon, 31 Dec 2018 14:40:59 +0000 (15:40 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 5 Dec 2020 00:41:21 +0000 (01:41 +0100)
Strip invisible trash commonly left by less precise users.
First implemented on and copied from poslawsky.nl/bio/.

edit/page.js

index ac2288a07fceb1ef132958ef22e44fad7f57f409..4e389dbe624f0765ad66a31115016527085bdf2c 100644 (file)
@@ -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(/((?!<p>).{3})(?:\s|\u200B)+(?=<\/p>)/g, '$1');
                                // empty line is equivalent to a paragraph break
                                body = body.replace(/<br \/>\s*<br \/>/g, '<p>');
                                // wrap long line after each sentence