October CMS resources and help articles

Simple and to the point. Optimized by the community.

Clean HTML Pasted into Froala

1
by seanthepottingshed, last modified on July 7th, 2020
/**
 * Froala - Clean HTML Plugin.
 */
+function ($) {
    $.FroalaEditor.PLUGINS.cleanHtml = function (editor) {
        function _init() {
            editor.events.on('paste.beforeCleanup', function (clipboardHtml) {
                return _convertHtmlToPlainText(clipboardHtml);
            });
        }
        function _convertHtmlToPlainText(clipboardHtml) {
            return '<p>' + clipboardHtml.replace(/<br>/gi, "\n").replace(/<(?:.|\s)*?>/g, '') + '</p>';
        }
        return {
            _init: _init
        };
    };
}(jQuery);

Then include via:

/**
 * Extend Rich Editor.
 */
\Backend\FormWidgets\RichEditor::extend(function ($widget) {
    $widget->addJs('/plugins/author/name/assets/js/froala.clean-html.js', 'Author.Name');
});

Discussion

0 comments

We use cookies to measure the performance of this website. Do you want to accept these cookies?