diff --git a/anatomy/static/js/anatomy.js b/anatomy/static/js/anatomy.js index 3f650494..06cf37ee 100644 --- a/anatomy/static/js/anatomy.js +++ b/anatomy/static/js/anatomy.js @@ -16,6 +16,8 @@ $(document).ready(function () { clearableTextAreaSetup(); + + document.body.addEventListener("htmx:responseError", function(e) { let el = document.getElementById("htmx-error"); var error; @@ -738,3 +740,44 @@ function initializeClock(id, endtime) { window.initializeClock = initializeClock + + + // Unwrap single-root

elements from TinyMCE content before any form submit. + // This prevents a single wrapping

from being sent to the server while + // preserving other markup. We use a delegated submit listener so it works + // for dynamically-added forms as well (e.g. admin inlines). + document.addEventListener('submit', function(evt) { + try { + var form = evt.target; + if (!form || !form.querySelector) return; + // Find all tinyMCE textareas inside the form + var areas = form.querySelectorAll('textarea.tinymce'); + areas.forEach(function(area) { + var id = area.id; + if (!id) return; + var ed = (typeof tinyMCE !== 'undefined') ? tinyMCE.get(id) : null; + if (!ed) return; + var html = (ed.getContent && typeof ed.getContent === 'function') ? ed.getContent({format: 'html'}) : area.value; + if (!html) return; + // Use a temporary container to inspect top-level elements safely + var tmp = document.createElement('div'); + tmp.innerHTML = html.trim(); + // If there is exactly one top-level element and it is a

, unwrap it + if (tmp.childElementCount === 1 && tmp.firstElementChild && tmp.firstElementChild.tagName.toLowerCase() === 'p') { + var inner = tmp.firstElementChild.innerHTML; + // Update editor content and the underlying textarea value + try { + ed.setContent(inner); + } catch (e) { + // fallback: set textarea value directly + area.value = inner; + } + // Ensure the textarea value matches (some setups sync on save, some don't) + area.value = inner; + } + }); + } catch (e) { + // be resilient; don't prevent form submission if something goes wrong here + console.error('TinyMCE submit postprocess error', e); + } + }, true); \ No newline at end of file diff --git a/rad/settings.py b/rad/settings.py index 23f27eb9..205f4198 100644 --- a/rad/settings.py +++ b/rad/settings.py @@ -303,6 +303,10 @@ TINYMCE_DEFAULT_CONFIG = { "skin": "oxide-dark", "menubar": "tools", "content_css": "dark", + # Disable the "Powered by Tiny" branding badge in the editor UI + # (TinyMCE option: https://www.tiny.cloud/docs/configure/editor-appearance/#branding) + "branding": False, + "promotion": False, } DEFAULT_AUTO_FIELD = "django.db.models.AutoField"