33 Votes

TinyMCE: Insert Text as Plain Text without any Formatting

Question by Guest | 2014-05-06 at 16:33

When copying some text out of a Word file or an HTML document into my TinyMCE-Editor, the text always contains many formatting such as colors, boxes or tables that should not be taken over.

Of course, it is different when I copy a unformatted text, for example out of a plain text editor.

How can I achieve that even original formatted text will be copied as plain text without any formatting into the TinyMCE-Editor?

ReplyPositiveNegative
4Best Answer4 Votes

TinyMCE is providing a plugin called "paste" that can care about this thing. The property "paste_as_text" should be set to "true".

Here is an example of how to include the plugin:

tinymce.init({
  selector: "textarea",
  plugins: "paste",
  paste_as_text: true
});

In your case, also using "paste_word_valid_elements" instead of "paste_as_text" could be helpful. You can use it like that:

tinymce.init({
  selector: "textarea",
  plugins: "paste",
  paste_word_valid_elements: "h1,h2,h3,b,strong,i,em"
});

With this property, you can define some HTML tags that are allowed to be taken over from Word (or any other source). All other elements not defined here are removed automatically. So, it is possible, for example, to take over headings or bold words but not every formatting.
2014-05-06 at 17:23

ReplyPositive Negative
Reply

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.