Redactor: Remove all formatting when pasting text into the Rich Text Editor

AndyB

Well-known member
I would like to see an option that would would remove all formatting when pasting text into the Rich Text Editor. This would remove bold, font size, font color etc.. It would be identical to the way pasting text into the BB Code editor currently functions.

The Remove Formatting on Paste function would be a Admin CP setting.
 
Upvote 16
I am trying to disable bold... This did not help. :cry:

PHP:
if (this.opts.pasteCleanUpCallback)
            {
                // start hack

                html = html.replace(/<h1[^>]*>([\w\W]+?)<\/h1>/ig, '$1');
                html = html.replace(/<h2[^>]*>([\w\W]+?)<\/h2>/ig, '$1');
                html = html.replace(/<h3[^>]*>([\w\W]+?)<\/h3>/ig, '$1');
                html = html.replace(/<b[^>]*>([\w\W]+?)<\/b>/ig, '$1');
                html = html.replace(/<strong[^>]*>([\w\W]+?)<\/strong>/ig, '$1');
             
                // end hack
                html = this.opts.pasteCleanUpCallback(e, this, html);
            }
 
Though my reply is late, it might help someone.
This option enable you to convert evrything pasted by user to plain text.
Users will still able to edit text and convert it into rich.
That was actually my client's requirement.

Goto /js/redactor/redactor.full.js

At about point 2528 add this

Code:
//Make text plain
            html = html.replace(/<style([\s\S]*?)<\/style>/gi, '');
            html = html.replace(/<script([\s\S]*?)<\/script>/gi, '');
            html = html.replace(/<\/div>/ig, '\n');
            html = html.replace(/<\/li>/ig, '\n');
            html = html.replace(/<li>/ig, '  *  ');
            html = html.replace(/<\/ul>/ig, '\n');
            html = html.replace(/<\/p>/ig, '\n');
            html = html.replace(/<br\s*[\/]?>/gi, "\n");
            html = html.replace(/<[^>]+>/ig, '');

set pastePreventCallback to true.
 
One more option is threre,
Just remove allowed tags from /js/redactor/redactor.full.js
Remove unwanted tags from here at about line 184
This does the trick (y) (y) (y).
I changed
PHP:
allowedTags: ["form", "input", "button", "select", "option", "datalist", "output", "textarea", "fieldset", "legend",
                    "section", "header", "hgroup", "aside", "footer", "article", "details", "nav", "progress", "time", "canvas",
                    "code", "span", "div", "label", "a", "br", "p", "b", "i", "del", "strike", "u", "font",
                    "img", "video", "source", "track", "audio", "iframe", "object", "embed", "param", "blockquote",
                    "mark", "cite", "small", "ul", "ol", "li", "hr", "dl", "dt", "dd", "sup", "sub",
                    "big", "pre", "code", "figure", "figcaption", "strong", "em", "table", "tr", "td",
                    "th", "tbody", "thead", "tfoot", "h1", "h2", "h3", "h4", "h5", "h6"]
to:
Code:
allowedTags: [""]
and it now paste in plain text.

There are still few problems though:
1. It doesn't remove the size.
2. When switching from RTE to BB code editor, all the formatting you've done in RTE will lost. But I think normal users wouldn't bother to switch editor ;)

Still I'm hoping there's a an option for each format to turn off on paste. Personally, I'd like "lists" to still have formatting but remove all other else.
 
I would like to see an option that would would remove all formatting when pasting text into the Rich Text Editor. This would remove bold, font size, font color etc.. It would be identical to the way pasting text into the BB Code editor currently functions.

The Remove Formatting on Paste function would be a Admin CP setting.

This add-on provides this function:

https://xenforo.com/community/resources/bb-code-parser.2796/
 
Nice!

I've just learned to paste using Ctrl-Shift-V, which pastes in plaintext; that way I can still paste formatted if I need to. Funny what a few years can do. :D

I can see this helping less technically inclined users, though. You can tell when the post is a formatting trainwreck when they've pasted in formatted text!
 
Back
Top Bottom