From 8ebb02bde9591fd09bbdbb396e49593a8e83ee4f Mon Sep 17 00:00:00 2001
From: crowjake <jmirzaian@gmail.com>
Date: Wed, 8 Jan 2025 17:14:16 +0000
Subject: [PATCH] Added `<section>`, `<aside>`, `<figure>`, `<article>`,
 `<nav>`, `<header>`, `<footer>` and `<main>` wherever `<div>` was targetted.
 Also added `<mark>` to "allowlist".

---
 js/build/linebreaks.js                                  | 2 +-
 js/ckeditor5_plugins/linebreaks/src/linebreaksfilter.js | 8 ++++----
 js/plugins/linebreaks/linebreaks.js                     | 8 ++++----
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/js/build/linebreaks.js b/js/build/linebreaks.js
index 825b19d..cd226ed 100644
--- a/js/build/linebreaks.js
+++ b/js/build/linebreaks.js
@@ -1 +1 @@
-!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.CKEditor5=r():(e.CKEditor5=e.CKEditor5||{},e.CKEditor5.linebreaks=r())}(self,(()=>(()=>{var e={"ckeditor5/src/core.js":(e,r,n)=>{e.exports=n("dll-reference CKEditor5.dll")("./src/core.js")},"dll-reference CKEditor5.dll":e=>{"use strict";e.exports=CKEditor5.dll}},r={};function n(t){var p=r[t];if(void 0!==p)return p.exports;var c=r[t]={exports:{}};return e[t](c,c.exports,n),c.exports}n.d=(e,r)=>{for(var t in r)n.o(r,t)&&!n.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},n.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r);var t={};return(()=>{"use strict";n.d(t,{default:()=>c});var e=n("ckeditor5/src/core.js");class r{constructor(e){this.editor=e}detach(){var e=this.editor.sourceElement.id,r=this.editor.getData(),n=this.linebreaks_detach(r),t=document.querySelector("#"+e);t&&"value"in t&&(t.value=n)}attach(){var e,r=this.editor.sourceElement.id,n=document.querySelector("#"+r);if(n&&"value"in n){e=n.value;var t=this.linebreaks_attach(e);this.editor.setData(t)}}linebreaks_attach(e){var r="table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|hr|pre|select|form|blockquote|address|math|p|h[1-6]|drupal-entity|drupal-media";return""==e?e:(-1!=e.indexOf("<object")&&(e=e.replace(/<object[\s\S]+?<\/object>/g,(function(e){return e.replace(/[\r\n]+/g,"")}))),-1!=e.indexOf("<embed")&&(e=e.replace(/<embed[\s\S]+?<\/embed>/g,(function(e){return e.replace(/[\r\n]+/g,"")}))),e=e.replace(/<[^<>]+>/g,(function(e){return e.replace(/[\r\n]+/g," ")})),e=(e+="\n\n").replace(new RegExp("&#13;","g"),""),console.log(e),e=e.replace(new RegExp("<br />\\s*<br />","gi"),"\n\n"),console.log(e),e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=e.replace(new RegExp("(<(?:"+r+")[^>]*>)","gi"),"\n$1")).replace(new RegExp("(</(?:"+r+")>)","gi"),"$1\n\n")).replace(new RegExp("\\r\\n|\\r","g"),"\n")).replace(new RegExp("\\n\\s*\\n+","g"),"\n\n")).replace(new RegExp("([\\s\\S]+?)\\n\\n","mg"),"<p>$1</p>\n")).replace(new RegExp("<p>\\s*?</p>","gi"),"")).replace(new RegExp("<p>\\s*(</?(?:"+r+")[^>]*>)\\s*</p>","gi"),"$1")).replace(new RegExp("<p>(<li.+?)</p>","gi"),"$1")).replace(new RegExp("<p>\\s*<blockquote([^>]*)>","gi"),"<blockquote$1><p>")).replace(new RegExp("</blockquote>\\s*</p>","gi"),"</p></blockquote>")).replace(new RegExp("<p>\\s*(</?(?:"+r+")[^>]*>)","gi"),"$1")).replace(new RegExp("(</?(?:"+r+")[^>]*>)\\s*</p>","gi"),"$1")).replace(new RegExp("([^>])\\s*\\n","gi"),"$1<br />\n")).replace(new RegExp("<\\/(strong|em|span|u|a)>\\s*\\n","gi"),"</$1><br />\n")).replace(new RegExp("(</?(?:"+r+")[^>]*>)\\s*<br />","gi"),"$1")).replace(new RegExp("<br />(\\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)","gi"),"$1")).replace(new RegExp("(?:<p>|<br ?/?>)*\\s*\\[caption([^\\[]+)\\[/caption\\]\\s*(?:</p>|<br ?/?>)*","gi"),"[caption$1[/caption]"),console.log(e),e=e.replace(/<(pre|script)[^>]*>[\s\S]+?<\/\1>/g,(function(e){return(e=e.replace(/<br ?\/?>[\r\n]*/g,"\n")).replace(/<\/?p( [^>]*)?>[\r\n]*/g,"\n")})))}linebreaks_detach(e){var r,n,t;return r="blockquote|ul|ol|li|hr|table|thead|tbody|tr|th|td|div|h[1-6]|p",n="blockquote|ul|ol|table|h[1-6]|pre",t="li|thead|tr|th|td",-1!=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=e.replace(/<(pre|script)[^>]*>[\s\S]+?<\/\1>/g,(function(e){return(e=e.replace(/<br ?\/?>[\r\n]*/g,"<lb_temp>")).replace(/<\/?p( [^>]*)?>[\r\n]*/g,"<lb_temp>")}))).replace(new RegExp("\\s*</("+r+")>\\s*","mg"),"</$1>\n")).replace(new RegExp("\\s*<(("+r+")[^>]*)>","mg"),"\n<$1>")).replace(new RegExp("(<p [^>]+>.*?)</p>","mg"),"$1</p#>")).replace(new RegExp("<div([^>]*)>\\s*<p>","mgi"),"<div$1>\n\n")).replace(new RegExp("\\s*<p>","mgi"),"")).replace(new RegExp("\\s*</p>\\s*","mgi"),"\n\n")).replace(new RegExp("\\n\\s*\\n","mgi"),"\n\n")).replace(new RegExp("\\s*<br ?/?>\\s*","gi"),"\n")).replace(new RegExp("\\s*<div","mg"),"\n<div")).replace(new RegExp("</div>\\s*","mg"),"</div>\n")).replace(new RegExp("\\s*\\[caption([^\\[]+)\\[/caption\\]\\s*","gi"),"\n\n[caption$1[/caption]\n\n")).replace(new RegExp("caption\\]\\n\\n+\\[caption","g"),"caption]\n\n[caption")).replace(new RegExp("\\s*<(("+n+") ?[^>]*)\\s*>","mg"),"\n\n<$1>")).replace(new RegExp("\\s*</("+n+")>\\s*","mg"),"</$1>\n\n")).replace(new RegExp("\\s*<(hr ?[^>]*)\\s*>","mg"),"\n\n<$1>\n\n")).replace(new RegExp("\\s*<(("+t+") ?[^>]*)\\s*>","mg"),"\n<$1>")).replace(new RegExp("\\s*</("+t+")>\\s*","mg"),"</$1>\n")).replace(new RegExp("<li([^>]*)>","g"),"\t<li$1>")).indexOf("<object")&&(e=e.replace(/<object[\s\S]+?<\/object>/g,(function(e){return e.replace(/[\r\n]+/g,"")}))),-1!=e.indexOf("<embed")&&(e=e.replace(/<embed[\s\S]+?<\/embed>/g,(function(e){return e.replace(/[\r\n]+/g,"")}))),e=(e=(e=(e=(e=e.replace(new RegExp("</p#>","g"),"</p>\n\n")).replace(new RegExp("\\s*(<p [^>]+>.*</p>)","mg"),"\n\n$1")).replace(new RegExp("^\\s*",""),"")).replace(new RegExp("[\\s\\u00a0]*$",""),"")).replace(/<lb_temp>/g,"\n")}}class p extends e.Plugin{init(){"force"===this.editor.config.get("linebreaks").method&&this.editor.on("destroy",(()=>{new r(this.editor).detach()}),{priority:"lowest"}),this.editor.on("ready",(()=>{new r(this.editor).attach()}),{priority:"lowest"})}static get pluginName(){return"LineBreaks"}}const c={LineBreaks:p}})(),t=t.default})()));
\ No newline at end of file
+!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.CKEditor5=r():(e.CKEditor5=e.CKEditor5||{},e.CKEditor5.linebreaks=r())}(self,(()=>(()=>{var e={"ckeditor5/src/core.js":(e,r,n)=>{e.exports=n("dll-reference CKEditor5.dll")("./src/core.js")},"dll-reference CKEditor5.dll":e=>{"use strict";e.exports=CKEditor5.dll}},r={};function n(t){var p=r[t];if(void 0!==p)return p.exports;var c=r[t]={exports:{}};return e[t](c,c.exports,n),c.exports}n.d=(e,r)=>{for(var t in r)n.o(r,t)&&!n.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},n.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r);var t={};return(()=>{"use strict";n.d(t,{default:()=>c});var e=n("ckeditor5/src/core.js");class r{constructor(e){this.editor=e}detach(){var e=this.editor.sourceElement.id,r=this.editor.getData(),n=this.linebreaks_detach(r),t=document.querySelector("#"+e);t&&"value"in t&&(t.value=n)}attach(){var e,r=this.editor.sourceElement.id,n=document.querySelector("#"+r);if(n&&"value"in n){e=n.value;var t=this.linebreaks_attach(e);this.editor.setData(t)}}linebreaks_attach(e){var r="table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|section|aside|figure|article|nav|header|footer|main|dl|dd|dt|ul|ol|li|hr|pre|select|form|blockquote|address|math|p|h[1-6]|drupal-entity|drupal-media";return""==e?e:(-1!=e.indexOf("<object")&&(e=e.replace(/<object[\s\S]+?<\/object>/g,(function(e){return e.replace(/[\r\n]+/g,"")}))),-1!=e.indexOf("<embed")&&(e=e.replace(/<embed[\s\S]+?<\/embed>/g,(function(e){return e.replace(/[\r\n]+/g,"")}))),e=e.replace(/<[^<>]+>/g,(function(e){return e.replace(/[\r\n]+/g," ")})),e=(e+="\n\n").replace(new RegExp("&#13;","g"),""),console.log(e),e=e.replace(new RegExp("<br />\\s*<br />","gi"),"\n\n"),console.log(e),e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=e.replace(new RegExp("(<(?:"+r+")[^>]*>)","gi"),"\n$1")).replace(new RegExp("(</(?:"+r+")>)","gi"),"$1\n\n")).replace(new RegExp("\\r\\n|\\r","g"),"\n")).replace(new RegExp("\\n\\s*\\n+","g"),"\n\n")).replace(new RegExp("([\\s\\S]+?)\\n\\n","mg"),"<p>$1</p>\n")).replace(new RegExp("<p>\\s*?</p>","gi"),"")).replace(new RegExp("<p>\\s*(</?(?:"+r+")[^>]*>)\\s*</p>","gi"),"$1")).replace(new RegExp("<p>(<li.+?)</p>","gi"),"$1")).replace(new RegExp("<p>\\s*<blockquote([^>]*)>","gi"),"<blockquote$1><p>")).replace(new RegExp("</blockquote>\\s*</p>","gi"),"</p></blockquote>")).replace(new RegExp("<p>\\s*(</?(?:"+r+")[^>]*>)","gi"),"$1")).replace(new RegExp("(</?(?:"+r+")[^>]*>)\\s*</p>","gi"),"$1")).replace(new RegExp("([^>])\\s*\\n","gi"),"$1<br />\n")).replace(new RegExp("<\\/(strong|em|span|mark|u|a)>\\s*\\n","gi"),"</$1><br />\n")).replace(new RegExp("(</?(?:"+r+")[^>]*>)\\s*<br />","gi"),"$1")).replace(new RegExp("<br />(\\s*</?(?:p|li|div|section|aside|figure|article|nav|header|footer|main|dl|dd|dt|th|pre|td|ul|ol)>)","gi"),"$1")).replace(new RegExp("(?:<p>|<br ?/?>)*\\s*\\[caption([^\\[]+)\\[/caption\\]\\s*(?:</p>|<br ?/?>)*","gi"),"[caption$1[/caption]"),console.log(e),e=e.replace(/<(pre|script)[^>]*>[\s\S]+?<\/\1>/g,(function(e){return(e=e.replace(/<br ?\/?>[\r\n]*/g,"\n")).replace(/<\/?p( [^>]*)?>[\r\n]*/g,"\n")})))}linebreaks_detach(e){var r,n,t;return r="blockquote|ul|ol|li|hr|table|thead|tbody|tr|th|td|div|section|aside|figure|article|nav|header|footer|main|h[1-6]|p",n="blockquote|ul|ol|table|h[1-6]|pre",t="li|thead|tr|th|td",-1!=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=e.replace(/<(pre|script)[^>]*>[\s\S]+?<\/\1>/g,(function(e){return(e=e.replace(/<br ?\/?>[\r\n]*/g,"<lb_temp>")).replace(/<\/?p( [^>]*)?>[\r\n]*/g,"<lb_temp>")}))).replace(new RegExp("\\s*</("+r+")>\\s*","mg"),"</$1>\n")).replace(new RegExp("\\s*<(("+r+")[^>]*)>","mg"),"\n<$1>")).replace(new RegExp("(<p [^>]+>.*?)</p>","mg"),"$1</p#>")).replace(new RegExp("<div([^>]*)>\\s*<p>","mgi"),"<div$1>\n\n")).replace(new RegExp("\\s*<p>","mgi"),"")).replace(new RegExp("\\s*</p>\\s*","mgi"),"\n\n")).replace(new RegExp("\\n\\s*\\n","mgi"),"\n\n")).replace(new RegExp("\\s*<br ?/?>\\s*","gi"),"\n")).replace(new RegExp("\\s*<div","mg"),"\n<div")).replace(new RegExp("</div>\\s*","mg"),"</div>\n")).replace(new RegExp("\\s*\\[caption([^\\[]+)\\[/caption\\]\\s*","gi"),"\n\n[caption$1[/caption]\n\n")).replace(new RegExp("caption\\]\\n\\n+\\[caption","g"),"caption]\n\n[caption")).replace(new RegExp("\\s*<(("+n+") ?[^>]*)\\s*>","mg"),"\n\n<$1>")).replace(new RegExp("\\s*</("+n+")>\\s*","mg"),"</$1>\n\n")).replace(new RegExp("\\s*<(hr ?[^>]*)\\s*>","mg"),"\n\n<$1>\n\n")).replace(new RegExp("\\s*<(("+t+") ?[^>]*)\\s*>","mg"),"\n<$1>")).replace(new RegExp("\\s*</("+t+")>\\s*","mg"),"</$1>\n")).replace(new RegExp("<li([^>]*)>","g"),"\t<li$1>")).indexOf("<object")&&(e=e.replace(/<object[\s\S]+?<\/object>/g,(function(e){return e.replace(/[\r\n]+/g,"")}))),-1!=e.indexOf("<embed")&&(e=e.replace(/<embed[\s\S]+?<\/embed>/g,(function(e){return e.replace(/[\r\n]+/g,"")}))),e=(e=(e=(e=(e=e.replace(new RegExp("</p#>","g"),"</p>\n\n")).replace(new RegExp("\\s*(<p [^>]+>.*</p>)","mg"),"\n\n$1")).replace(new RegExp("^\\s*",""),"")).replace(new RegExp("[\\s\\u00a0]*$",""),"")).replace(/<lb_temp>/g,"\n")}}class p extends e.Plugin{init(){"force"===this.editor.config.get("linebreaks").method&&this.editor.on("destroy",(()=>{new r(this.editor).detach()}),{priority:"lowest"}),this.editor.on("ready",(()=>{new r(this.editor).attach()}),{priority:"lowest"})}static get pluginName(){return"LineBreaks"}}const c={LineBreaks:p}})(),t=t.default})()));
\ No newline at end of file
diff --git a/js/ckeditor5_plugins/linebreaks/src/linebreaksfilter.js b/js/ckeditor5_plugins/linebreaks/src/linebreaksfilter.js
index e6069a8..94b52b5 100644
--- a/js/ckeditor5_plugins/linebreaks/src/linebreaksfilter.js
+++ b/js/ckeditor5_plugins/linebreaks/src/linebreaksfilter.js
@@ -51,8 +51,8 @@ export default class LineBreaksFilter {
    * @returns {string} - The content with line breaks converted to HTML tags.
    */
   linebreaks_attach(content) {
-    var blocklist = 'table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|hr|pre|select|form|blockquote|address|math|p|h[1-6]|drupal-entity|drupal-media';
-    var allowedlist = 'strong|em|span|u|a';
+    var blocklist = 'table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|section|aside|article|nav|header|footer|dl|dd|dt|ul|ol|li|hr|pre|select|form|blockquote|address|math|p|h[1-6]|drupal-entity|drupal-media';
+    var allowedlist = 'strong|em|span|mark|u|a';
 
     if (content == "") {
       return content;
@@ -94,7 +94,7 @@ export default class LineBreaksFilter {
     content = content.replace(new RegExp('([^>])\\s*\\n', 'gi'), "$1<br />\n");
     content = content.replace(new RegExp('<\\/('+allowedlist+')>\\s*\\n', 'gi'), "</$1><br />\n");
     content = content.replace(new RegExp('(</?(?:'+blocklist+')[^>]*>)\\s*<br />', 'gi'), "$1");
-    content = content.replace(new RegExp('<br />(\\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)', 'gi'), '$1');
+    content = content.replace(new RegExp('<br />(\\s*</?(?:p|li|div|section|aside|article|nav|header|footer|dl|dd|dt|th|pre|td|ul|ol)>)', 'gi'), '$1');
     content = content.replace(new RegExp('(?:<p>|<br ?/?>)*\\s*\\[caption([^\\[]+)\\[/caption\\]\\s*(?:</p>|<br ?/?>)*', 'gi'), '[caption$1[/caption]');
     console.log(content);
     // Fix <pre> and <script> tags.
@@ -122,7 +122,7 @@ export default class LineBreaksFilter {
     });
 
     // Pretty it up for the source editor.
-    blocklist1 = 'blockquote|ul|ol|li|hr|table|thead|tbody|tr|th|td|div|h[1-6]|p';
+    blocklist1 = 'blockquote|ul|ol|li|hr|table|thead|tbody|tr|th|td|div|section|aside|article|nav|header|footer|main|h[1-6]|p';
     content = content.replace(new RegExp('\\s*</('+blocklist1+')>\\s*', 'mg'), '</$1>\n');
     content = content.replace(new RegExp('\\s*<(('+blocklist1+')[^>]*)>', 'mg'), '\n<$1>');
 
diff --git a/js/plugins/linebreaks/linebreaks.js b/js/plugins/linebreaks/linebreaks.js
index 5a370a4..d2c7f3b 100644
--- a/js/plugins/linebreaks/linebreaks.js
+++ b/js/plugins/linebreaks/linebreaks.js
@@ -33,8 +33,8 @@ CKEDITOR.plugins.add('linebreaks', {
 
 // Prepare the content by converting line breaks to paragraph/br tags.
 function linebreaks_attach(content) {
-  var blocklist = 'table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|hr|pre|select|form|blockquote|address|math|p|h[1-6]|drupal-entity|drupal-media';
-  var allowedlist = 'strong|em|span|u|a';
+  var blocklist = 'table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|section|aside|figure|article|nav|header|footer|main|dl|dd|dt|ul|ol|li|hr|pre|select|form|blockquote|address|math|p|h[1-6]|drupal-entity|drupal-media';
+  var allowedlist = 'strong|em|span|mark|u|a';
 
   if (content == "") {
     return content;
@@ -74,7 +74,7 @@ function linebreaks_attach(content) {
   content = content.replace(new RegExp('([^>])\\s*\\n', 'gi'), "$1<br />\n");
   content = content.replace(new RegExp('<\\/('+allowedlist+')>\\s*\\n', 'gi'), "</$1><br />\n");
   content = content.replace(new RegExp('(</?(?:'+blocklist+')[^>]*>)\\s*<br />', 'gi'), "$1");
-  content = content.replace(new RegExp('<br />(\\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)', 'gi'), '$1');
+  content = content.replace(new RegExp('<br />(\\s*</?(?:p|li|div|section|aside|figure|article|nav|header|footer|main|dl|dd|dt|th|pre|td|ul|ol)>)', 'gi'), '$1');
   content = content.replace(new RegExp('(?:<p>|<br ?/?>)*\\s*\\[caption([^\\[]+)\\[/caption\\]\\s*(?:</p>|<br ?/?>)*', 'gi'), '[caption$1[/caption]');
 
   // Fix <pre> and <script> tags.
@@ -97,7 +97,7 @@ function linebreaks_detach(content) {
   });
 
   // Pretty it up for the source editor.
-  blocklist1 = 'blockquote|ul|ol|li|hr|table|thead|tbody|tr|th|td|div|h[1-6]|p';
+  blocklist1 = 'blockquote|ul|ol|li|hr|table|thead|tbody|tr|th|td|div|section|aside|figure|article|nav|header|footer|main|h[1-6]|p';
   content = content.replace(new RegExp('\\s*</('+blocklist1+')>\\s*', 'mg'), '</$1>\n');
   content = content.replace(new RegExp('\\s*<(('+blocklist1+')[^>]*)>', 'mg'), '\n<$1>');
 
-- 
GitLab

