From 35d609a50f1ffc0577d5e0f301e040be9a8003d6 Mon Sep 17 00:00:00 2001 From: Grzegorz Leoniec Date: Mon, 28 Jan 2019 11:07:13 +0100 Subject: [PATCH] Updated conten formatting. --- assets/styles/main.scss | 39 ----------------------- components/Editor/plugins/eventHandler.js | 31 +++++++++++++----- 2 files changed, 23 insertions(+), 47 deletions(-) diff --git a/assets/styles/main.scss b/assets/styles/main.scss index d22f3ec08..662b8bb0d 100644 --- a/assets/styles/main.scss +++ b/assets/styles/main.scss @@ -78,45 +78,6 @@ blockquote { } } -.hc-editor-content { - h1, - h2, - h3, - h4, - h5, - h6 { - &:not(:first-child) { - margin-top: 2rem; - } - } - p { - &:not(:last-child) { - margin-top: 0; - margin-bottom: 0; - } - } - dl, - ol, - ul, - blockquote, - pre, - table { - &:not(:first-child) { - margin-top: 15px; - } - } - *:first-child { - margin-top: 0; - } - *:last-child { - margin-bottom: 0; - } - // avoid double breaks - br + p { - margin-top: 0; - } -} - hr { border: 0; width: 100%; diff --git a/components/Editor/plugins/eventHandler.js b/components/Editor/plugins/eventHandler.js index 46137f5c1..b3e41ace5 100644 --- a/components/Editor/plugins/eventHandler.js +++ b/components/Editor/plugins/eventHandler.js @@ -15,18 +15,33 @@ export default class EventHandler extends Extension { }, transformPastedHTML(html) { html = html - .replace(/(\s*){2,}/gim, '
') + // remove all tags with "space only" + .replace(/<[a-z-]+>[\s]+<\/[a-z-]+>/gim, '') + // remove all iframes .replace( - /<\/(p|div|th|tr)>\s*(\s*)+\s*<(p|div|th|tr)>/gim, - '

' - ) - .replace( - /<(p|div|th|tr)>\s*(\s*)+\s*<\/(p|div|th|tr)>/gim, + /(]*)(>)[^>]*\/*>/gim, '' ) - .replace(/<(p|div|th|tr)>\s*/gim, '

') - .replace(/\s*<\/(p|div|th|tr)>/gim, '

') + .replace(/[\n]{3,}/gim, '\n\n') + .replace(/(\r\n|\n\r|\r|\n)/g, '
') + // replace all p tags with line breaks (and spaces) only by single linebreaks + // limit linebreaks to max 2 (equivalent to html "br" linebreak) + .replace(/(
\s*){2,}/gim, '
') + // remove additional linebreaks after p tags + .replace( + /<\/(p|div|th|tr)>\s*(
\s*)+\s*<(p|div|th|tr)>/gim, + '

' + ) + // remove additional linebreaks inside p tags + .replace( + /<[a-z-]+>(<[a-z-]+>)*\s*(
\s*)+\s*(<\/[a-z-]+>)*<\/[a-z-]+>/gim, + '' + ) + // remove additional linebreaks when first child inside p tags + .replace(/

(\s*
\s*)+/gim, '

') + // remove additional linebreaks when last child inside p tags + .replace(/(\s*
\s*)+<\/p>/gim, '

') // console.log('#### transformPastedHTML', html) return html }