HTML Support
A major requirement for providing rich text editing capabilities is support for HTML. The RadRichTextBox control is designed to offer import/export functionality for HTML out of the box – through the HtmlFormatProvider. However, as HTML is a diverse and complicated standard, supporting it comes with certain limitations. HtmlFormatProvider is designed to handle slightly malformed HTML (missing closing tags, missing quotes around attributes), however in this case correct parsing cannot be guaranteed. For best results we recommend importing valid XHTML content.
The purpose of this article is to outline which parts of the HTML are supported.
Importing
When the HtmlFormatProvider imports an HTML document, it parses it and converts the HTML element tree to RadDocument. Importing is basically made up of two parts – content and styling.
Content
HTML content is mapped to several types of RadDocument elements – paragraphs, spans and tables.
Tags mapped to paragraphs are:
<p>
<h1> through <h6>
<ul>, <ol>, <li>
<tr>
Tags mapped to spans are:
- formatting tags, <span>, <font>
Additionally, line breaks are inserted between consequent block elements ( <div> ).
Styling
Styling is supported through CSS styles (classes or inline) and a number of formatting tags (including ). Although the <font> tag has been deprecated, legacy software and markup requires support for it.
Supported formatting tags are:
<b>, <strong> – turn on bold
<i>, <em> – turn on italic
<u> – turn on underline
<h1> through <h6> – apply heading
<sub> - turn on subscript
<sup> - turn on superscript
Supported CSS properties are:
text-align
margin-left
margin-right
color
background-color
font-family
font-size
font-style
font-weight
text-decoration (underline, line-through)
vertical-align (sub, super)
Supported tag attributes are:
face – equivalent to CSS property font-family
size – equivalent to CSS property font-size
color – equivalent to CSS property color
Exporting
When exporting to HTML, the HtmlFormatProvider iterates through the RadDocument tree and generates HTML nodes. It is designed to generate valid XHTML document in order to preserve the formatting as much as possible. Styles are exported as CSS classes in the head of the document and used through the body. The structure of the HTML document closely resembles that of RadDocument – paragraphs and spans.