froala / wysiwyg-editor

The next generation Javascript WYSIWYG HTML Editor.
https://www.froala.com/wysiwyg-editor
Other
5.3k stars 675 forks source link

htmlAllowedTags should replace enter tags p, div and br #3897

Open xmedeko opened 4 years ago

xmedeko commented 4 years ago
Expected behavior.

If htmlAllowedTags does not contain some "enter" tags p, div or br, then these tags should be replaced with the enter tag.

Actual behavior.

All tags not in htmlAllowedTags are removed.

Steps to reproduce the problem.

Following https://github.com/froala/wysiwyg-editor/issues/3276#issuecomment-463690334 point 2) if div is not in htmlAllowedTags, then:

Editor version.

3.1.0

OS.

Windows

Browser.

Chrome

Ugly hacky workaround

Replace all div by p (or depending on your configuration) and hook paste.beforeCleanup event to the pasteBeforeCleanup() function:

function fixHtml(html) {
    return html.replace(/<div\b/gmi, "<p");
}

function pasteBeforeCleanup(html) {
    this.opts.htmlAllowedTags.push("div");
    try {
        html = this.clean.html(html);
    } finally {
        this.opts.htmlAllowedTags.pop();
    }
    html = fixHtml(html);
    return html;
}
ilyaskarim commented 2 weeks ago

We’re closing this issue due to inactivity. If you’re still experiencing this problem on the latest version of our editor, please feel free to reopen the issue and let us know. You can find details on the latest updates here: Froala Editor Changelog.

xmedeko commented 2 weeks ago

@ilyaskarim Problem is still in Froala 4.3.0, try in in JSFiddle, see the link above. Cannot reopen the issue, please, reopen it.

ilyaskarim commented 1 week ago

We are reopening the issue for further investigation.