From b3c4c38b834b8647f7c93f8326cce55b0ea47d28 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Fri, 15 Sep 2017 19:31:19 +0200 Subject: [PATCH] edit: replace custom paragraph breaks by sentence wrapping Attempt to improve readability of HTML source (and line-based diffs). --- edit.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/edit.js b/edit.js index c32bd5b..b97ed87 100644 --- a/edit.js +++ b/edit.js @@ -3,7 +3,14 @@ CKEDITOR.plugins.add('inlinesave', { editor.addCommand( 'inlinesave', { exec: function (editor) { var pagename = window.location.pathname.replace(/\/$/, '/index'); - var data = 'body='+encodeURIComponent(editor.getData()); + var body = editor.getData().replace(/^(\t*).{73,}/mg, function (line, indent) { + // wrap long line after each sentence + var dot = '(?:[^<]|<[^>]*>)'; // one character + var dots = '(?:'+dot+'{24,72}|'+dot+'{73,}?)'; // chars before punctuation + var wrap = new RegExp('('+dots+'[.;:!?]) (?=[A-Z])', 'g'); // separate lines + return line.replace(wrap, '$1\n'+indent+'\t'); + }); + var data = 'body='+encodeURIComponent(body); ajaxpost = new XMLHttpRequest(); ajaxpost.open('POST', '/edit'+pagename, true); ajaxpost.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); @@ -66,16 +73,6 @@ CKEDITOR.on('instanceCreated', function (event) { }); }); - CKEDITOR.on('instanceReady', function (event) { - var editor = event.editor; - var writer = editor.dataProcessor.writer; - writer.selfClosingEnd = ' />'; - writer.setRules( 'p', { - breakAfterOpen: true, - breakBeforeClose: true, - }); - }); - CKEDITOR.disableAutoInline = true; // add edit link to menu -- 2.30.0