This is a migrated thread and some comments may be shown as answers.

Clean HTML

3 Answers 89 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 01 Sep 2011, 03:53 PM
I've read through various articles in this forum but am still struggling to get clean HTML output from the RichTextBox/HtmlDataProvider.  

It seems to try and be very explicit in the markup it creates, whereas actually what we need is clean, uncluttered HTML where CSS classes are only used when a style is specifically set, thus allowing other elements to inherit styles from the page their inserted into.  

For example, a few lines of text and a few bullet points produces this:

<style type="text/css">
.p_CC664AAA { margin: 0px 0px 12px 0px;text-align: left;text-indent: 0pt;padding: 0px 0px 0px 0px; }
.s_1C757C00 { font-family: 'Arial';font-style: Normal;font-weight: normal;font-size: 13.3299999237061px;color: #000000; }
</style>
<p class="p_CC664AAA"><span class="s_1C757C00">This is a line of text.</span></p>
<p class="p_CC664AAA"><span class="s_1C757C00">This is a new para.</span></p>
<ul style="list-style-type:disc">
<li value="1" class="p_CC664AAA"><span class="s_1C757C00">First bullet</span></li>
<li value="2" class="p_CC664AAA"><span class="s_1C757C00">Second bullet</span></li>
</ul>
<p class="p_CC664AAA"><span class="s_1C757C00">The end.</span></p>

What we really need is something like this:

<p>This is a line of text.</p>
<p>This is a new para.</p>
<ul>
<li>First bullet</li>
<li>Second bullet</li>
</ul>
<p>The end.</p>

This is an extreme example as we will want to be using other formatting, but the principle's there - we're looking to pass the HTML through an HTML templating system and the specific styles being applied are causing issues.  We're not looking for anything too complex, but need to know the output is going to be flexible enough to be influenced by higher level CSS and render predictably in a browser/email client.

Is there any way to achieve this kind of clean output without writing our own custom DocumentFormatProvider?

Any help would be very much appreciated as we've been grappling with this for a long time.

Many thanks,

Chris

3 Answers, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 07 Sep 2011, 08:47 AM
Hello Chris,

The content of the document is exported in this way, in order to ensure that it looks as close as possible to the way it does in the rich text box regardless of the consumer of the HTML output. We have "cleaner" HTML output on our to-do list, but this feature has not been scheduled yet.
With the current version of the controls, such HTML output can only be achieved by implementing a custom HTML format provider. You can use the XHTML string that HtmlFormatProvider produces on export and process it to strip all default values using XDocument for example.

Greetings,
Iva
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Chris
Top achievements
Rank 1
answered on 08 Sep 2011, 09:30 AM
Thanks Iva.

Do you guys have any code samples for creating a custom HTML format provider? 
0
Iva Toteva
Telerik team
answered on 14 Sep 2011, 10:27 AM
Hi Chris,

We don't have such a demo. You can create a new format provider by implementing the IDocumentFormatProvider interface and if you encounter any difficulties, we'd be happy to assist you further.

Kind regards,
Iva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
RichTextBox
Asked by
Chris
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Chris
Top achievements
Rank 1
Share this question
or