How to: Customize the SharePoint HTML Editor Field Control (ECM)
Applies to: SharePoint Server 2010
In this article
Constraints
Predefined Table Formats
Spelling Checker
You can use the HTML Editor field control to insert HTML content into a publishing page. Page templates that include a Publishing HTML column type also include the HTML Editor field control. This editor has special capabilities, such as customized styles, editing constraints, reusable content support, a spelling checker, and use of asset pickers to select documents and images to insert into a page’s content. This topic describes how to modify some features and attributes of the HTML Editor field control.
Constraints
If the content type of a page layout supports the Page Content column, you can add a Rich HTML field control to your page layout by using markup such as the following.
<PublishingWebControls:RichHtmlField id="ArticleAbstract" FieldName="ArticleAbstract"
AllowExternalUrls="false"
AllowFonts="true"
AllowReusableContent="false"
AllowHeadings="false"
AllowHyperlinks="false"
AllowImages="false"
AllowLists="false"
AllowTables="false"
AllowTextMarkup="false"
AllowHTMLSourceEditing="false"
DisalbeBasicFormattingButtons="false"
runat="server"/>
In the example above, RichHTMLField is the name of the field control that provides the richer HTML editing experience. Attributes such as AllowFonts and AllowTables specify restrictions on the field.
The HTML field control allows font tags, but the control does not allow URLs that are external to the current site collection, reusable content stored in a centralized list, standard HTML heading tags, hyperlinks, images, numbered or bulleted lists, tables, or text markup.
Table 1. HTML editor field control properties
Attribute |
Description |
---|---|
AllowExternalUrls |
Only URLs internal to the current site collection are allowed to be referenced in a link or an image. |
AllowFonts |
Content may contain Font tags. |
AllowHtmlSourceEditing |
HTML Editor can be switched into a mode that allows the HTML to be edited directly. |
AllowReusableContent |
Content may contain reusable content fragments stored in a centralized list. |
AllowHeadings |
Content may contain HTML heading tags (H1, H2, and so on). |
AllowTextMarkup |
Content may contain bold, italic, and underlined text. |
AllowImages |
Content may contain images. |
AllowLists |
Content may contain numbered or bulleted lists. |
AllowTables |
Content may contain table-related tags such as <table>, <tr>, and <td>. |
AllowHyperlinks |
Content may contain links to other URLs. |
AllowHtmlSourceEditing |
When set to false, the HTML editor is disabled from switching to HTML source editing mode. |
AllowHyperlinks |
Gets or sets the constraint that allows hyperlinks to be added to the HTML. If this flag is set to false, <A>, <AREA>, and <MAP> tags are removed from the HTML. Default is true. This property also determines whether the editing user interface (UI) enables these operations. |
AllowImageFormatting |
Gets or sets image formatting items. This restriction disables only menus and does not force the content to adhere to this restriction |
AllowImagePositioning |
Gets or sets the position of the image. This restriction disables only menus and does not force the content to adhere to this restriction. |
AllowImageStyles |
Gets or sets whether the Table Styles menu is enabled. This restriction disables only the menu and does not force the content to adhere to this restriction. |
AllowInsert |
Gets or sets whether Insert options are shown. This restriction disables only the menu and does not force the content to adhere to this restriction. |
AllowLists |
Gets or sets the constraint that allows list tags to be added to the HTML. If this flag is set to false, <LI>, <OL>, <UL>, <DD>, <DL>, <DT>, and <MENU> tags are removed from the HTML. Default is true. This also determines whether the editing UI enables these operations. |
AllowParagraphFormatting |
Gets or sets whether paragraph formatting items are enabled. This restriction disables only menus and does not force the content to adhere to this restriction. |
AllowStandardFonts |
Gets or sets whether standard fonts are enabled. This restriction disables only menus and does not force the content to adhere to this restriction. |
AllowStyles |
Gets or sets whether the Style menu is enabled. This restriction disables only the menu and does not force the content to adhere to this restriction. |
AllowTables |
Gets or sets the constraint to allow tables to be added when editing this field. |
AllowTableStyles |
Gets or sets whether the Table Styles menu is enabled. This restriction disables only the menu and does not force the content to adhere to this restriction. |
AllowTextMarkup |
Get or set the constraint to allow text markup to be added when editing this field. |
AllowThemeFonts |
Gets or sets whether theme fonts are enabled. This restriction disables only menus and does not force the content to adhere to this restriction. |
Predefined Table Formats
The HTML editor includes a set of predefined table formats, but it can be customized to fit the styling of an individual page. Each table format is a collection of cascading style sheet (CSS) classes for each table tag. You can define styling for the first and last row, odd and even rows, first and last column, and so on.
The HTML Editor dynamically applies certain styles from the referenced style sheets on the page and makes them available to users when formatting a table. For a custom style to be available when formatting a table, the relevant class names must follow the PREFIXTableXXX-NNN format, where:
PREFIX is ms-rte by default, but you can override the default by using the control PrefixStyleSheet() property of the RichHTML field control.
XXX is the specific table section, such as EvenRow or OddRow.
NNN is the name to identify the table styling.
The following example presents a complete set of classes for a table styling format.
.ms-rteTable-1 {border-collapse:collapse;border-top:gray 1.5pt;
border-left:gray 1.5pt;border-bottom:gray 1.5pt;
border-right:gray 1.5pt;border-style:solid;}
.ms-rteTableHeaderRow-1 {color:Green;background:yellow;text-align:left}
.ms-rteTableHeaderFirstCol-1 {padding:0in 5.4pt 0in 5.4pt;}
.ms-rteTableHeaderLastCol-1 {padding:0in 5.4pt 0in 5.4pt;}
.ms-rteTableHeaderOddCol-1 {padding:0in 5.4pt 0in 5.4pt;}
.ms-rteTableHeaderEvenCol-1 {padding:0in 5.4pt 0in 5.4pt;}
.ms-rteTableOddRow-1 {color:black;background:#FFFFDD;}
.ms-rteTableEvenRow-1 {color:black;background:#FFB4B4;}
.ms-rteTableFirstCol-1 {padding:0in 5.4pt 0in 5.4pt;}
.ms-rteTableLastCol-1 {padding:0in 5.4pt 0in 5.4pt;}
.ms-rteTableOddCol-1 {padding:0in 5.4pt 0in 5.4pt;}
.ms-rteTableEvenCol-1 {padding:0in 5.4pt 0in 5.4pt;}
.ms-rteTableFooterRow-1 {color:blue;font-style:bold;
font-weight:bold;background:white;border-top:solid gray 1.0pt;
border-bottom:solid gray 1.0pt;border-right:solid silver 1.0pt;
border-style:solid;}
.ms-rteTableFooterFirstCol-1 {padding:0in 5.4pt 0in 5.4pt;
border-top:solid gray 1.0pt;text-align:left}
.ms-rteTableFooterLastCol-1 {padding:0in 5.4pt 0in 5.4pt;
border-top:solid gray 1.0pt;text-align:left}
.ms-rteTableFooterOddCol-1 {padding:0in 5.4pt 0in 5.4pt;
text-align:left;border-top:solid gray 1.0pt;}
.ms-rteTableFooterEvenCol-1 {padding:0in 5.4pt 0in 5.4pt;
text-align:left;border-top:solid gray 1.0pt;}
Microsoft SharePoint Server 2010 includes a set of default table styles. However, if the system detects new styles that did not originate in the default .css file, it removes the default set and presents only those newly defined styles in the HTML editor dialog box.
Spelling Checker
In SharePoint Server 2010, the HTML editor includes a spelling checker, which can be customized by developers by using the SpellCheckV4Action Web control and the SpellCheckToolbarButton Web control. The spelling checker action registers client files and data during a spelling check. It also includes a method to get the console tab and calls the user rights to verify that the current user has rights to perform a spelling check operation on the selected item. The spelling checker action calls the appropriate ECMAScript (JavaScript, JScript) code, and sends information to the client about available spellings and the default language to use for the request.
See Also
Concepts
How to: Customize Styles in SharePoint Server 2010 (ECM)
How to: Customize the Asset Picker in SharePoint Server 2010 (ECM)