Remove the extra <div> when saving content from CKEditor

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 <div> 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 <div> in the
 same way, thus i can not use fixed indices in call to substring.
This commit is contained in:
jordi fita mas 2024-01-21 21:04:51 +01:00
parent cf527ce070
commit 64dc533949
1 changed files with 4 additions and 1 deletions

View File

@ -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('&nbsp;', '&#xA0;');
let text = serializer.serializeToString(xml);
text = text.replace('&nbsp;', '&#xA0;');
text = text.substring(text.indexOf('>') + 1, text.lastIndexOf('<'));
textarea.value = text;
}
});
})