X-Git-Url: http://git.shiar.net/minimedit.git/blobdiff_plain/d3ed59c2753c2babd5aa9a1c5e0109c644904ba8..8da4e3db153de18c026cc8dda79bdc0947663c8a:/edit/page.js diff --git a/edit/page.js b/edit/page.js index 3071844..d1f16bf 100644 --- a/edit/page.js +++ b/edit/page.js @@ -4,8 +4,12 @@ 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, '

'); + // keep names and preceding abbreviations together + body = body.replace(/\b((?:dhr|mw|me?vr|mr?s?)\.)\s+(?=[A-Z])/ig, '$1 '); // wrap long line after each sentence body = body.replace(/^(\t*).{73,}/mg, function (line, indent) { var dots = '(?:.{24,72}|.{73,}?)'; // chars before punctuation @@ -162,7 +166,12 @@ if (pagebody) { editlink.onclick = undefined; pagebody.setAttribute('contenteditable', true); pagebody.querySelectorAll('[data-dyn]').forEach(function (el) { - el.outerHTML = '[[' + el.getAttribute('data-dyn') + ']]'; + let blockname = el.getAttribute('data-dyn'); + if (!blockname) { + el.remove(); + return; + } + el.outerHTML = '[[' + blockname + ']]'; }); CKEDITOR.inline(pagebody, { customConfig: '' }); document.body.className = 'edit';