0
votes

Hi I am trying to create a TinyMCE editor, and in this I want user to be able to paste from wherever he wants.

The only restriction i want to put , when a user paste from his source my TinyMCE box should remove all the rich-text properties ( e.g. color, font-style, heading, table ) except superscript and subscript.

I want only superscript and subscript to be retained.

here is my TinyMCE code. Currently I am using paste_as_text:true , so it is removing every rich text style including superscript and subscript.

http://fiddle.tinymce.com/KAfaab/4

<script type="text/javascript">
 tinyMCE.init({
         selector: 'textArea',  // change this value according to your HTML
         menubar: false,
         width: "840",
         toolbar: 'undo redo | superscript subscript | link image',
         height: "225",
         resize: 'both',      
         encoding: "xml",
         elementpath: true,
         paste_word_valid_elements: "superscript,subscript,sub,sup",
         plugins: "paste",
         paste_retain_style_properties: "superscript,subscript,sub,sup",
         paste_as_text:true


     });

 <form method="post" action="dump.php">
     <textarea name="content"></textarea>
 </form>
1

1 Answers

0
votes

Paste as text will remove all formatting - not what you want.

You can try to use valid_elements / extended_valid_elements to get what you want but it may be easier to use paste_postprocess to remove those elements that you don't want in the editor after a paste:

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

This option provides you a copy of the content after the paste plugin is done doing its work and you can perform your own modifications before the content is inserted into the editor.

Note: paste_word_valid_elements only impacts content pasted from Word - it won't impact (as an example) content pasted from another web page so while that may address your issue for some types of pasted content it won't work for all types of pasted content. A similar issue exists for paste_retain_style_properties - that only impacts CSS styles - it will have no impact on any tag so the way you have it configured it won't do anything.