RadRichTextBox and HtmlFormatProvider - produce html content with only few tags, without spans, classes, etc.

5 Answers 40 Views
RichTextBox
Jakub
Top achievements
Rank 1
Iron
Jakub asked on 08 Jul 2021, 12:30 PM | edited on 08 Jul 2021, 12:33 PM

Hi, I am trying to create simple HTML editor that will let user create html content limited to few options and the requirement here is to produce html with only <p> <u> <em> <strong> <font color="#XXXXXX"> without any spans, class or any other inline styles. I know how to limit it from UI so user can only use a few button to bold text, underscore, etc but I don't know how to get rig of these spans and other elements in export html.

Attached picture shows exported html when in RadRichTextBox I only added two texts, one is bold, second is italic.

I would like to have exported html like this: <p><strong>test</strong></p><p><i>test</i></p>

Any ideas?

 

5 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 09 Jul 2021, 12:27 PM

Hi Jakub,

You can achieve the desired result with the help of the ExportSettings exposed by the HtmlFormatProvider and especially the ExportBoldAsStrong and ExportItalicAsEm properties:

HtmlFormatProvider provider = new HtmlFormatProvider();
HtmlExportSettings htmlExportSettings = new HtmlExportSettings();
htmlExportSettings.ExportBoldAsStrong = true;
htmlExportSettings.ExportItalicAsEm = true;
provider.ExportSettings = htmlExportSettings;

For additional information check all the exposed ExportSettings Properties.

Regards,
Martin
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Jakub
Top achievements
Rank 1
Iron
answered on 09 Jul 2021, 07:08 PM

Thank you Martin.

I knew about this two properties to export bold as strong and italic as em.

The problem is how to get rid of the spans with style atrribute and from other tags like p.

Do I need to loop through all the tree/items and remove styles?

0
Martin
Telerik team
answered on 14 Jul 2021, 10:29 AM
Hi Jakub,

The RichTextBox doesn't provide APIs for removing spans and paragraphs and if you need to do so, you will need to create a custom parser which to remove the unwanted elements.

Regards,
Martin
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Jakub
Top achievements
Rank 1
Iron
answered on 14 Jul 2021, 02:45 PM
Is there any example of how to implement custom parser/formatprovider?
0
Martin
Telerik team
answered on 16 Jul 2021, 02:53 PM

Hi Jakub,

I am afraid we don't have such an example but when browsing the web I found out there are such discussions that could be helpful (e.g. remove HTML tags).

Regards,
Martin
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
RichTextBox
Asked by
Jakub
Top achievements
Rank 1
Iron
Answers by
Martin
Telerik team
Jakub
Top achievements
Rank 1
Iron
Share this question
or