Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tinymce editor strip all styles but retain bullets and tables while pasting text

I am using tinymce editor and my requirement is to strip all styles applied on a content while pasting without losing the bullets and tables. Is this possible? I tried initialising my tinymce editor as follows:

 tinymce.init({
    plugins: "paste,textcolor",
    paste_as_text: true,
    encoding: "xml",
    mode: "exact",
    selector: "textarea.className",
    menubar: false,
    statusbar: false,
    height: 257,
    browser_spellcheck: true,
    toolbar: "forecolor backcolor,bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright, justifyfull,bullist,numlist,undo,redo,link,unlink"
});

I am using the paste plugin and setting the paste_as_text as true. This will strip off all the styles so that I can apply the desired styles on my own. However, even the bullets and tables are also stripped which is not good. Any idea people? Thanks in advance!!

like image 546
antony.ouseph.k Avatar asked Nov 16 '16 07:11

antony.ouseph.k


1 Answers

The paste as text option (https://www.tinymce.com/docs/plugins/paste/#paste_as_text) is going to cause your pasted content to come in as plain text - so there are no things like bullets, tables, headings, etc. The content will basically look like you pasted it through Notepad before pasting it into TinyMCE. If you set this to true as in your configuration above you won't get any HTML formatting at all - this is working as designed based on that configuration option.

If you don't set paste_as_text to true you will get HTML content (which you know based on your post) - if you want to further manipulate the HTML you have options:

paste_postprocess - https://www.tinymce.com/docs/plugins/paste/#paste_postprocess

This allows you to run your own custom JavaScript after the paste plugin processes the content but before its injected into the editor. You can do whatever you like to the HTML at this point so there is really no limit to what you can add to or remove from the content.

paste_word_valid_elements - https://www.tinymce.com/docs/plugins/paste/#paste_word_valid_elements

This allows you to list what HTML elements are valid for insertion into the editor when the paste plugin processes the pasted content.

There are other options for the paste plugin that may offer further assistance: https://www.tinymce.com/docs/plugins/paste

like image 141
Michael Fromin Avatar answered Oct 12 '22 03:10

Michael Fromin