Sometimes, we want to make TinyMCE paste in plain text by default with JavaScript.
In this article, we’ll look at how to make TinyMCE paste in plain text by default with JavaScript.
Make TinyMCE Paste in Plain Text by Default with JavaScript
To make TinyMCE paste in plain text by default, we can set the paste_as_text
option to true
.
For example, we can write the following HTML:
<script src="https://cdn.tiny.cloud/1/no-api-key/tinymce/5/tinymce.min.js" referrerpolicy="origin"></script>
<textarea id="mytextarea">Hello, World!</textarea>
to add the TinyMCE script and a text area for the TinyMCE editor.
Then we can convert the text area to a TinyMCE editor with the following JavaScript code:
tinymce.init({
selector: '#mytextarea',
plugins: "paste",
paste_as_text: true
});
We call the tinymce.init
method with an object that has the selector
, plugins
, and paste_as_text
properties.
selector
is the selector of the text area to convert to a TinyMCE editor.
plugins
is set to 'paste'
to add the paste plugin to let us control pasting text.
And we set paste_as_text
to true
to make TinyMCE paste text as plain text.
Conclusion
To make TinyMCE paste in plain text by default, we can set the paste_as_text
option to true
.