Allow images when stripping all formatting

1 Answer 61 Views
Editor
Beister Software GmbH
Top achievements
Rank 1
Beister Software GmbH asked on 15 Jun 2021, 09:07 AM

Hi there,

since it is not possible to paste images, if stripping all formatting is configured, i have created a small workaround, which i want to share. Target was, to get pretty clean HTML - without annoying markup - but to allow images to be inserted via clipboard.

First of all, use the options of the editor, to "pre-clean" the HTML:

StripFormattingOptions="Css,Font,Span,MSWordRemoveAll"

Then attach to the OnClientPasteHtml event and perform special cleaning, if HTML is pasted:

function Editor_PasteHtml(sender, args) {
	var sInitialValue = args.get_value();
	if ((args.get_commandName() == 'Paste') && (sInitialValue != null)) {
		// Only allow basic tags
		var sStrippedValue = sInitialValue.replace(new RegExp("<(?!\/?(strong|b|em|img|(i(?!nput))|u|ol|ul|li|p|br)(?=>|\s?.*>))\/?.*?>", "ig"), "");
		args.set_value(sStrippedValue);
	}
}

The solution is not perfect and the RegEx could be extended, but for our case, it works good enought. The RegEx itself was taken from a sample by Rumen and modified, to allow less tags.

 

Kind regards, Carsten

1 Answer, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 15 Jun 2021, 10:56 AM

Hi Carsten,

Thank you for sharing this useful solution with the community!

Let me share the resource with the regular expression you mention in your post - here you go Using Custom ContentFilters with RadEditor and Telerik Reporting.

Keep up the good work!

 

Best Regards,
Rumen
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Editor
Asked by
Beister Software GmbH
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Share this question
or