Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I strip all html formatting from text when pasting into KendoUI Editor?

I want to use KendoUI editor to basically only allow users to format text into paragraphs. Possibly allow bold and underline.

I'm struggling with 2 things:

  1. I want to strip all html formatting from text when pasting
  2. I want to disable keyboard shortcuts for bold, underline etc - they seem to work even when toolbar element is not there.

Thanks!

like image 795
richardwhatever Avatar asked Mar 24 '13 23:03

richardwhatever


2 Answers

For pasting the only the text you might define a paste handler that remove all but text. This is as simple as:

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

The paste handler receives as argument an event that has in html the text being parsed. We can use jQuery for getting only the text using $(ev.html).text()

For removing the shortcuts, and as far as I could test it with latest Kendo UI version, if you define only the tools that you want, only those shortcut are active. So if you say something like:

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

Only italic shortcut <ctrl>+i is available. If you leave tools array empty then you do not have any.

like image 128
OnaBai Avatar answered Oct 20 '22 01:10

OnaBai


This can be easily achieved now with pasteCleanup option.

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

like image 41
Zubzob Avatar answered Oct 20 '22 00:10

Zubzob