How to copy HTML as plain text

6k views Asked by At

When I copy paste some text from somewhere to a summernote text editor, it copies the style also. What I need is just the plain text. But what I'm getting is the text with a number of html tags.

When I copy

Lorem Ipsum is simply dummy text of the printing and typesetting industry

What I'm getting is

<strong style="font-family: Arial, Helvetica, sans; font-size: 11px; line-height: 14px; text-align: justify;">Lorem Ipsum</strong><span style="font-family: Arial, Helvetica, sans; font-size: 11px; font-weight: normal; line-height: 14px; text-align: justify;">&nbsp;is simply dummy text of the printing and typesetting industry.</span>

The code I'm using is

$('.summernote').summernote({
    focus : true,
    height: 250,
    toolbar: []
});

Is there any option in summernote to disable this kind of behaviour ?

2

There are 2 answers

5
Zack Tanner On

Summernote has an onPaste event, which can be implemented like so:

$('.summernote').summernote({
    focus : true,
    height: 250,
    toolbar: [],
    onPaste: function(e) {

    })
});

You can see an implementation of how someone used this to strip formatting here: https://github.com/summernote/summernote/issues/303#issuecomment-53713694

0
pirimoglu On

For disable onPaste event

$('.summernote').summernote({
  onPaste: function(e) { 
    event.preventDefault();
    event.stopPropagation();
  } 
});