Skip to main content

Copy and Paste

These options control how content is handled when pasted or dropped into the editor, including format stripping, style retention, and preprocessing callbacks.

Options

OptionTypeDefaultDescription
paste_as_textbooleanfalsePaste all content as plain text by default, stripping all formatting.
paste_block_dropbooleanfalseBlock content from being dropped into the editor via drag-and-drop.
paste_data_imagesbooleantrueAllow images pasted from the clipboard (as data URIs) to be inserted into the editor.
paste_preprocessfunctionCallback invoked before pasted content is inserted. Receives the plugin instance and an object with a content property that can be modified.
paste_postprocessfunctionCallback invoked after pasted content has been parsed into a DOM node but before insertion. Receives the plugin instance and an object with a node property.
paste_webkit_stylesstring'none'Which WebKit-specific inline styles to retain when pasting. Set to 'all' to keep everything, or a comma-separated list of style names.
paste_remove_styles_if_webkitbooleantrueRemove inline styles from content pasted in WebKit-based browsers (Chrome, Safari).
paste_merge_formatsbooleantrueMerge the format of pasted content with adjacent content that has the same formatting.
smart_pastebooleantrueEnable intelligent paste behavior, such as automatically converting URLs to links or images.
paste_tab_spacesnumber4Number of spaces to use when converting tab characters to spaces in pasted content.

Example

editor42.init({
selector: 'textarea',
paste_as_text: false,
paste_data_images: true,
smart_paste: true,
paste_preprocess: (plugin, args) => {
// Strip all bold tags from pasted content
args.content = args.content.replace(/<\/?strong>/gi, '');
},
paste_postprocess: (plugin, args) => {
// Add a class to all pasted paragraphs
const paragraphs = args.node.querySelectorAll('p');
paragraphs.forEach(p => p.classList.add('pasted'));
}
});