How can I remove all html formatting from text when pasted into the KendoUI editor?

I want to use the KendoUI editor to basically allow users to format text in paragraphs. It is possible to allow bold and underline.

I am struggling with 2 things:

  • I want to remove all html formatting from text when pasting
  • I want to disable shortcut keys for bold, underline, etc. - they seem to work even if the toolbar item does not exist.

Thanks!

+6
source share
3 answers

To paste only text, you can define an insert handler that removes everything except text. It is as simple as:

$("#editor").kendoEditor({ paste: function (ev) { ev.html = $(ev.html).text(); } }); 

The paste handler receives as an argument an event that has processed text in html . We can use jQuery to get only text using $(ev.html).text()

To remove shortcuts, and as far as I can check it with the latest version of Kendo UI, if you define only those tools that you want, only those shortcuts are active. Therefore, if you say something like:

 $("#editor").kendoEditor({ tools: [ "italic" ], paste: function (ev) { ev.html = $(ev.html).text(); } }); 

Only the italic shortcut <ctrl>+i . If you leave the tools array empty, you don't have one.

+8
source

This can easily be done now with the pasteCleanup option.

See here: http://docs.telerik.com/kendo-ui/controls/editors/editor/pasting

+1
source

Kendo MVC also has an extension for this purpose. Usage example:

 .PasteCleanup(x => x.KeepNewLines(false)) 

false in this case means that you want to clear everything except newlines.

0
source

All Articles