Locking Down Styles in the MOSS Publishing HTML Field Control

 

 

THIS BLOG HAS MOVED !!!

 

THE UPDATED POST CAN BE FOUND HERE –  http://sharepoint-sezai-moss-2007.blogspot.com/2008/02/locking-down-styles-in-moss-publishing.html

 

 

 

 

 

In SharePoint Designer, open a page layout and select a HTML field control

You should then be presented with a series of properties in the Tag window.

There are a series of AllowBlahBlah properties which you simply set to false if you want that specific validation enabled on the field control.

You can also set these properties in code view on the page layout

   

Descriptions of these field control properties from the MOSS SDKhttp://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.publishing.webcontrols.richhtmlfield_members.aspx

 

Name Description
AllowExternalUrls Gets or sets the constraint that allows external URLs in the HTML when validating the value in this RichHtmlField object.
AllowFonts Gets or sets the constraint that allows font element tags to be added to the HTML.
AllowHeadings Gets or sets the constraint that allows heading tags to be added to the HTML.
AllowHtmlSourceEditing Determines whether you can switch the HtmlEditor object into a mode where the HTML can be edited directly.
AllowHyperlinks Gets or sets the constraint that allows hyperlinks to be added to the HTML.
AllowImages Gets or sets the constraint that allows image tags to be added to the HTML.
AllowLists Gets or sets the constraint that allows list tags to be added to the HTML.
AllowReusableContent Gets or sets the flag that enables the reusable content picker button when editing this field.
AllowTables Gets or sets the constraint that allows table handling tags to be added to the HTML.
AllowTextMarkup Gets or sets the constraint that allows explicit text markup tags, such as bold and italic, to be added to the HTML.

What happens when they are set to FALSE?

Eg. If I set  AllowFonts="False" and AllowTextMarkup="False"

It disables the font and text colour buttons on the HTML Editor.

If a content author pastes in HTML with Font tags or text mark-up in the field control and now attempts to save or check in the page :

You get this on the Page Editing Toolbar –  

And the HTML Field Control now contains an Auto Correct button and a message related to `unsupported formatting'

Now simply click the Auto Correct button, and the content is cleaned up client side with javascript, nice
 

What happens to the HTML?

BEFORE
FONT color=#ff8000 size=5>WesTrac </FONT></STRONG>has a huge range of <FONT color=#ff0000>reliable low hour </FONT>used equipment, all meticulously prepared for resale. <SPAN>&nbsp;</SPAN>If you <FONT size=4>can't find exactly </FONT>what.

AFTER
WesTrac has a huge range of reliable low hour used equipment, all meticulously prepared for resale. <SPAN>&nbsp;</SPAN>If you can't find exactly what

One more thing.

If you set any of these properties to false it won't automatically go through and clean-up the content in your site, but if a page contains content with these tags, the next time a content author edits the page and tries to save or check-in this validation will kick-in and it won't let the user save the page unless they click the button to clean up the HTML.

Copy and Pasting Content from Word Documents

You can still paste in content from Word Documents, and this won't automatically clean-up that HTML, these settings only seem to affect explicit font tags or other text markup, not in-line styles.

You get the following icon showing up in the field control

 

You can also access remove inline styles from the floating tool-bar

      

BEFORE
<P class=MsoNormal>Sezai's <SPAN style="COLOR: red">pasting</SPAN> this <SPAN class=Heading2Char><SPAN style="FONT-SIZE: 13pt; LINE-HEIGHT: 115%">content</SPAN></SPAN> in from word!</P>

AFTER
<P>Sezai's <SPAN>pasting</SPAN> this <SPAN><SPAN>content</SPAN></SPAN> in from word!</P>

Conclusion

There is no AllowStyles or AllowInlineStyles property! That's dumb because I can paste in content from word that is setting Font and Font Colour with inline styles !
That means even though I have set the following properties to false AllowFonts="False" and AllowTextMarkup="False" I can still set different fonts and font colours in Word, then paste it into a page, and save and check-in the page !!! and MOSS will let me.  you need to remember to always click the Remove Inline Styles explicitly.

   
Would be great if remove inline styles got rid of those un-needed SPAN tags ! If a SPAN is in the HTML such as <SPAN style="COLOR: red"> then it won't remove the tag, it will simply strip out the style="COLOR: red" leaving <SPAN>blah</SPAN> throughout the HTML content. Although I guess this is what is preffered if you are using specific HTML elements like DIVs with specific IDs to control style, in that case you would still want the HTML Element in place, and the ID preserved, just the style tag removed.

Nice features, but they don't go all the way, in conclusion, you can't really lock-down styles 100% in MOSS publishing sites. it isn't idiot proof you still need to explain this all to content authors and make them mindful that they need to remember to remove in-line styles from content pasted in from word.

 

 

THIS BLOG HAS MOVED !!!

 

THE UPDATED POST CAN BE FOUND HERE –  http://sharepoint-sezai-moss-2007.blogspot.com/2008/02/locking-down-styles-in-moss-publishing.html

 

 

Leave a Reply