Skip to content

Instantly share code, notes, and snippets.

@ishajain
Last active December 16, 2015 15:49
function pasteAsPlainTextWithNoFormatting() {
var cursorLocation = RTE.Cursor.get_range();
var copiedData = window.self.clipboardData.getData('Text'); //Copy content from clipboard
var copiedDataSpan = document.createElement('span');
copiedDataSpan.setAttribute('id', 'copiedData');
copiedDataSpan.innerText = copiedData; //add clipboard content to new span element
cursorLocation.deleteContent();
cursorLocation.insertBefore(copiedDataSpan); //add the content with the span element at the cursor location
var rawContent = $ribbon('#copiedData').html(); //find that span
var cleanContent = rawContent.replace(/<[^>]*>/gi, ''); //remove all the formatting
$ribbon('#copiedData').html(cleanContent);//add the content back
RTE.RteUtility.removeNodeAndKeepChildNodes(copiedDataSpan);//remove the span by keeping the data
RTE.Cursor.update(); //update the cursor position
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment