From 64dc53394978d8af1d19be357e1d1eb0fa187016 Mon Sep 17 00:00:00 2001 From: jordi fita mas Date: Sun, 21 Jan 2024 21:04:51 +0100 Subject: [PATCH] Remove the extra
when saving content from CKEditor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I need to have a single top-level element in order to serialize to XML when returning the editor’s content back to the text area, because, unlike PostgreSQL, XMLSerializer only works with XML documents. I added a
because this is the least “semantic” block element there is, but Oriol seems to have trouble in services when trying to align services using a grid due to this extra div. Now i still use the div to serialize to XML, but then remove that top-level element from the output string by stripping out its label. I can not be sure that all browsers would serialize the
in the same way, thus i can not use fixed indices in call to substring. --- web/static/camper.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/web/static/camper.js b/web/static/camper.js index 206f45c..0695faf 100644 --- a/web/static/camper.js +++ b/web/static/camper.js @@ -118,7 +118,10 @@ ready(function () { editor.ui.focusTracker.on('change:isFocused', (event, name, focused) => { if (!focused) { xml.innerHTML = editor.getData(); - textarea.value = serializer.serializeToString(xml).replace(' ', ' '); + let text = serializer.serializeToString(xml); + text = text.replace(' ', ' '); + text = text.substring(text.indexOf('>') + 1, text.lastIndexOf('<')); + textarea.value = text; } }); })