Paste plugin
Standard version of features for copying-and-pasting content from Microsoft Word.
Contribute to this pageLooking for more advanced Microsoft Word importing and pasting? Try the PowerPaste plugin.
This plugin will filter/cleanup content pasted from Microsoft Word. The power of the plugin is in its options, so please take the time to learn more about them below.
The plugin also adds a menu item Paste as text
under the Edit
menu dropdown and a toolbar button.
Note: The toolbar button won’t work in browsers that don’t support direct access to the clipboard. In such cases the user will be presented with a modal/dialog box advising them of this along with a reminder of standard keyboard shortcuts.
Basic setup
tinymce.init({
selector: 'textarea', // change this value according to your HTML
plugins: 'paste',
menubar: 'edit',
toolbar: 'paste pastetext'
});
Options
These settings affect the way content is eliminated or preserved when being pasted. In addition, callbacks are available prior to and after content filtration.
paste_block_drop
Due to browser limitations, it is not possible to filter content that is dragged and dropped into the editor. When paste_block_drop
is set to true the plugin will disable drag and dropping content into the editor. This prevents the unfiltered content from being introduced. Copy and paste is still enabled.
Default value: false
Possible values: true
, false
Example: Using paste_block_drop
tinymce.init({
selector: 'textarea', // change this value according to your HTML
plugins: 'paste',
paste_block_drop: false
});
paste_data_images
This option specifies whether data:url
images (inline images) should be removed or not from the pasted contents.
Setting paste_data_images
to "true"
will allow the pasted images, while setting it to "false"
will disallow pasted images.
For example, Firefox enables you to paste images directly into any contentEditable
field. This is normally not something people want, so this option is "false"
by default. For example, a 600kb embedded image would block page loads and prevents it from being cached on multiple pages.
Type: Boolean
Default Value: false
Possible Values: true
, false
Example: Using paste_data_images
tinymce.init({
selector: 'textarea', // change this value according to your HTML
plugins: 'paste',
menubar: 'edit',
toolbar: 'paste',
paste_data_images: true
});
paste_as_text
This option enables you to set the default state of the Paste as text
menu item, which is added by the paste
plugin under the Edit
menu dropdown. It’s disabled by default.
Type: Boolean
Default Value: false
Possible Values: true
, false
Example: Using paste_as_text
tinymce.init({
selector: 'textarea', // change this value according to your HTML
plugins: 'paste',
menubar: 'edit',
toolbar: 'paste',
paste_as_text: true
});
paste_enable_default_filters
This option allows you to disable TinyMCE’s default paste filters when set to false.
Type: Boolean
Default Value: true
Possible Values: true
, false
Example: Using paste_enable_default_filters
tinymce.init({
selector: 'textarea', // change this value according to your html
plugins: 'paste',
menubar: 'edit',
toolbar: 'paste',
paste_enable_default_filters: false
});
paste_filter_drop
This option allows developers to disable the default drop filters when set to false
.
Type: Boolean
Default Value: true
Possible Values: true
, false
Example: Using paste_filter_drop
tinymce.init({
selector: 'textarea', // change this value according to your HTML
plugins: 'paste',
paste_filter_drop: false
});
paste_preprocess
This option enables you to modify the pasted content before it gets inserted into the editor.
Type: Function
Example: Using paste_preprocess
tinymce.init({
selector: 'textarea', // change this value according to your HTML
plugins: 'paste',
menubar: 'edit',
toolbar: 'paste',
paste_preprocess: function(plugin, args) {
console.log(args.content);
args.content += ' preprocess';
}
});
paste_postprocess
This option enables you to modify the pasted content before it gets inserted into the editor but after it’s been parsed into a DOM structure.
Type: Function
Example: Using paste_postprocess
tinymce.init({
selector: 'textarea', // change this value according to your HTML
plugins: 'paste',
menubar: 'edit',
toolbar: 'paste',
paste_postprocess: function(plugin, args) {
console.log(args.node);
args.node.setAttribute('id', '42');
}
});
paste_word_valid_elements
Important: This option has been deprecated in TinyMCE 5.10 and will be removed in TinyMCE 6.0.
This option enables you to configure the valid_elements
specific to MS Office. Word produces a lot of junk HTML, so when users paste things from Word we do extra restrictive filtering on it to remove as much of this as possible. This option enables you to specify which elements and attributes you want to include when Word contents are intercepted.
Note: To access this feature, you need to set the value of paste_enable_default_filters to
"false"
in your configuration.
Type: String
Example: Using paste_word_valid_elements
tinymce.init({
selector: 'textarea', // change this value according to your HTML
plugins: 'paste',
menubar: 'edit',
toolbar: 'paste',
paste_word_valid_elements: 'b,strong,i,em,h1,h2'
});
paste_webkit_styles
This option allows you to specify styles you want to keep when pasting in WebKit. WebKit has a bug where it will take all the computed CSS properties for an element and add them to spans within the editor. Since most users don’t want random spans added all over their document, we need to manually clean that up until the bug is fixed. This option defaults to "none"
but can be set to "all"
or a specific list of styles to retain.
Type: String
Example: Using paste_webkit_styles
tinymce.init({
selector: 'textarea', // change this value according to your HTML
plugins: 'paste',
menubar: 'edit',
toolbar: 'paste',
paste_webkit_styles: 'color font-size'
});
paste_retain_style_properties
Important: This option has been deprecated in TinyMCE 5.10 and will be removed in TinyMCE 6.0.
This option allows you to specify which styles you want to retain when pasting contents from MS Word and similar Office suite products. This option can be set to a space-separated list of CSS style names, or "all"
if you want all styles to be retained.
Type: String
Example: Using paste_retain_style_properties
tinymce.init({
selector: 'textarea', // change this value according to your html
plugins: 'paste',
menubar: 'edit',
toolbar: 'paste',
paste_retain_style_properties: 'color font-size'
});
paste_merge_formats
This option enables the merge format feature of the Paste plugin. This merges identical text format elements to reduce the number of HTML elements produced. For example: <b>abc <b>bold</b> 123</b>
becomes <b>abc bold 123</b>
since the inner format is redundant. This option is enabled by default but can be disabled if retaining nested or identical format elements is important.
Type: Boolean
Default Value: true
Possible Values: true
, false
Example: Using paste_merge_formats
tinymce.init({
selector: 'textarea', // change this value according to your HTML
plugins: 'paste',
paste_merge_formats: false
});
paste_tab_spaces
Note: This feature is only available for TinyMCE 5.4 and later.
This option controls how many spaces are used to represent a tab character in HTML when pasting plain text content. By default, the Paste plugin will convert each tab character into 4 sequential space characters.
Type: Number
Default Value: 4
Example: Using paste_tab_spaces
tinymce.init({
selector: 'textarea', // change this value according to your HTML
plugins: 'paste',
paste_tab_spaces: 2
});
paste_convert_word_fake_lists
Important: This option has been deprecated in TinyMCE 5.10 and will be removed in TinyMCE 6.0.
This option lets you disable the logic that converts list like paragraph structures into real semantic HTML lists.
Type: Boolean
Default Value: true
Possible Values: true
, false
Example: Using paste_convert_word_fake_lists
tinymce.init({
selector: 'textarea', // change this value according to your HTML
plugins: 'paste',
menubar: 'edit',
toolbar: 'paste',
paste_convert_word_fake_lists: false
});
paste_remove_styles_if_webkit
This option allows you to disable TinyMCE’s default paste filters for webkit styles.
Type: Boolean
Default Value: true
Possible Values: true
, false
Example: Using paste_remove_styles_if_webkit
tinymce.init({
selector: 'textarea', // change this value according to your HTML
plugins: 'paste',
menubar: 'edit',
toolbar: 'paste',
paste_remove_styles_if_webkit: false
});
smart_paste
The smart_paste
function will:
- Detect text that resembles a URL and change the text to a hyperlink.
- Detect text that resembles the URL for an image and will try to replace the text with the image.
To disable the smart_paste
functionality, set smart_paste
to false
. To configure which image file types are recognised, see Image & file options - images_file_types.
Type: Boolean
Default Value: true
Possible Values: true
, false
Example: Using smart_paste
tinymce.init({
selector: 'textarea', // change this value according to your HTML
plugins: 'paste',
menubar: 'edit',
toolbar: 'paste',
smart_paste: false
});
image_file_types
This option configures which image file formats will be recognized and placed in an img
element by the smart_paste
functionality when content is pasted into the editor.
Type: String
Default Value: 'jpeg,jpg,jpe,jfi,jfif,png,gif,bmp,webp'
Possible Values: A list of valid web image file extensions. For a list of possible values see: MDN Web Docs - Image file type and format guide.
Example: Using image_file_types
tinymce.init({
selector: 'textarea', // change this value according to your HTML
plugins: 'paste',
smart_paste: true, // note: default value for smart_paste is true
image_file_types: 'jpg,svg,webp'
});
Toolbar buttons
The Paste plugin provides the following toolbar buttons:
Toolbar button identifier | Description |
---|---|
pastetext | Toggles plain text pasting mode on/off. When in plain text mode, all rich content is converted into plain text. |
These toolbar buttons can be added to the editor using:
- The
toolbar
configuration option. - The
quickbars_insert_toolbar
configuration option. - Custom Context toolbars.
Menu items
The Paste plugin provides the following menu items:
Menu item identifier | Default Menu Location | Description |
---|---|---|
pastetext | Edit | Toggles paste as plain text on/off. When in plain text mode, all rich content is converted into plain text. |
These menu items can be added to the editor using:
- The
menu
configuration option. - The
contextmenu
configuration option. - Custom Menu toolbar buttons.
Commands
The Paste plugin provides the following JavaScript command.
Command | Description |
---|---|
mceInsertClipboardContent | Triggers a paste event at the cursor location or over the current selection. The command requires an object with: content containing the HTML content, or text containing plain text. |
mceTogglePlainTextPaste | Toggles paste as plain text. |
Examples
tinymce.activeEditor.execCommand('mceInsertClipboardContent', false, {
content: '<p>Hello, World!</p>'
});
tinymce.activeEditor.execCommand('mceTogglePlainTextPaste');
Was this article helpful? Yes - No
Well, that's awkward . Would you mind opening an issue or helping us out?
Thanks for the feedback!
Can't find what you're looking for? Let us know.
Except as otherwise noted, the content of this page is licensed under the Creative Commons BY-NC-SA 3.0 License, and code samples are licensed under the Apache 2.0 License.