From d8f039dc5e1fa69c9939d1d405903f74efa5e431 Mon Sep 17 00:00:00 2001 From: Lars Gebhardt-Kusche Date: Fri, 16 Jan 2026 22:54:17 +0100 Subject: [PATCH] RTE --- public/assets/js/bridge/rte-editor.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/public/assets/js/bridge/rte-editor.js b/public/assets/js/bridge/rte-editor.js index a737a24..68553c7 100644 --- a/public/assets/js/bridge/rte-editor.js +++ b/public/assets/js/bridge/rte-editor.js @@ -289,15 +289,33 @@ saveBtn.style.background = '#0ea5e9'; saveBtn.style.color = '#ffffff'; saveBtn.style.cursor = 'pointer'; - saveBtn.addEventListener('click', () => { - let html = String(content.innerHTML || '').trim(); - const isTextLike = component && component.is && (component.is('text') || component.is('button') || component.is('link')); + const normalizeRteHtml = (rawHtml) => { + const wrapper = doc.createElement('div'); + wrapper.innerHTML = String(rawHtml || '').trim(); + // Unwrap single empty div wrapper inserted by contenteditable + if (wrapper.children.length === 1 && wrapper.firstElementChild.tagName === 'DIV' && wrapper.firstElementChild.attributes.length === 0) { + wrapper.innerHTML = wrapper.firstElementChild.innerHTML; + } + // Drop empty div/br artifacts + wrapper.querySelectorAll('div').forEach((el) => { + if (!el.attributes.length && !el.textContent.trim() && !el.querySelector('img,br,span,b,strong,i,em,u,a,ul,ol,li')) { + el.remove(); + } + }); + let html = wrapper.innerHTML.replace(//gi, '').trim(); if (!html) { - const fallbackText = String(content.textContent || '').trim(); + const fallbackText = wrapper.textContent.trim(); if (fallbackText) { html = fallbackText.replace(//g, '>'); } } + return html; + }; + + saveBtn.addEventListener('click', () => { + const rawHtml = content.innerHTML || ''; + let html = normalizeRteHtml(rawHtml); + const isTextLike = component && component.is && (component.is('text') || component.is('button') || component.is('link')); try { if (!isTextLike && component.components) { component.components(html);