Is it possible to remove all the style attributes when the user paste html content into Summernote texteditor?
For Example : (Input)
<p style="font-weight:500; color:#000;">Hello World </p>
<div style="display:block"> I am a Div content </div>
Expected Output after paste:
<p>Hello World </p>
<div> I am a Div content </div>
I want to Implement something like in Javascript/Jquery
$('tag').removeAttr("style");
Is there any in-built options or feature in SummerNote text editor to do this?
Thanks In advance
I've finally done it adapting an another solution (how to paste as plain text: summernote doesn't allow to format pasted text after writing onpaste event)
After succeed to paste in plain text using the solution above, just had to change text to html and remove style as you suggested:
$('.summernote').summernote({
callbacks: {
onPaste: function (e) {
var bufferText = ((e.originalEvent || e).clipboardData || window.clipboardData).getData('text/html');
e.preventDefault();
var div = $('<div />');
div.append(bufferText);
div.find('*').removeAttr('style');
setTimeout(function () {
document.execCommand('insertHtml', false, div.html());
}, 10);
}
}
}
I don't know browser compatibility of this solution, i only tested on Chrome. But i think it's not so hard to modify.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With