I am using the Kendo UI angular editor and need to save both the markup and the plain text from inside the control. I would like to keep the markup text encoded. This editor is being used within a custom template for a Kendo UI Grid popup edit. From what I have researched, I see two possible options to handle this.
- Write code to programmatically call the cleanFormatting toolbar method, save the original copy of the text, create a range of the body of the editor, select this range, call the cleanFormatting method, and save the new copy of the text.
- Programmatically replace all markup in the original copy of the text using some jQuery approach.
I would think that the first option would be the cleanest since it would be using Kendo throughout. However, the original copy of the text is encoded and calling the cleanFormatting method does not seem to call the exec method listed in the tools array for the editor. Furthermore, all HTML tags are still present. This is what I have so far for my tools and for the create method for my grid:
vm.editorOptions = {
tools: [
{
name:
'cleanFormatting'
,
tooltip:
'Clean formatting'
,
exec:
function
(e) {
console.log(
'ready to clean'
);
var
editor = $(
this
).data(
'kendoEditor'
);
editor.exec(
'cleanformatting'
);
}
},
'insertUnorderedList'
,
'insertOrderedList'
,
'foreColor'
,
'backColor'
],
execute:
function
(e){console.log(
"executing command"
, e.name, e.command);}
};
function
createLogEntry(options) {
var
markup = options.data.markupText;
console.log(markup);
var
editor = $(
'table.k-editor.k-editor-widget'
).kendoEditor().data(
'kendoEditor'
);
var
range = editor.createRange();
range.selectNodeContents(editor.body);
editor.selectRange(range);
editor.exec(
'cleanFormatting'
);
options.data.plainText = options.data.markupText;
console.log(options.data);
//...
}
When I use the button on the editor itself, I get exactly what I want. Is there a way to handle this programmatically, or is that not possible?
Because of the encoding, getting a jQuery method to strip the tags does not seem to work either. I have tried a few approaches, including
var
markup = options.data.markupText;
var
plain = $(
'<div>'
+ markup +
'</div>'
).text();
That seems to keep all the HTML tags that are inside the string, though.
Is there some way to do this with Kendo editor? Thanks for all your help!