Paste plugin
Looking 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.
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
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
paste_as_text
This option enables you to set the default state of the Paste as text
menu item, which is added by the {plugin}
plugin under the Edit
menu dropdown. It’s disabled by default.
Type: Boolean
Default Value: false
Possible Values: true
, false
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
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
paste_preprocess
This option enables you to modify the pasted content before it gets inserted into the editor.
Type: Function
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
paste_word_valid_elements
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.
To access this feature, you need to set the value of paste_enable_default_filters to "false" in your configuration.
|
Type: String
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
paste_retain_style_properties
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
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
paste_tab_spaces
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
paste_convert_word_fake_lists
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
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
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
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.