Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba

Limit HTML elements used in SimpleHTMLEditorField

Go to End

3 Posts   2564 Views


Community Member, 176 Posts

6 May 2010 at 9:50pm

Edited: 06/05/2010 9:54pm

Is it possible to limit the HTML elements that can be used (including copy and pasted) in the SimpleHTMLEditorField?

My reason for asking, one of my clients has a habit of copy and pasting text into the CMS from a word document. I have explained to copy and paste text into Word first, but they forget to do this. This results in SimpleHTMLEditorField code as:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="ProgId" content="Word.Document"><meta name="Generator" content="Microsoft Word 11"><meta name="Originator" content="Microsoft Word 11"><ul><li><link rel="File-List" href="file:///C:%5CUsers%5CEigenaar%5CAppData%5CLocal%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml"><span lang="EN-GB">Capra pyrenaica pyrenaica: extinct</span></li><li><span lang="EN-GB">...

whilst ideally it should be something as:

<ul><li>Capra pyrenaica pyrenaica: extinct</li><li>...

I think there may be three possible solutions, but before I start wrapping my own, I was wondering whether there is something out of the box, or code that somebody has on a shelve ready to be used.

1) Is there an easy way to configure the SimpleHTMLEditorField in that it will only allow certain HTML elements (e.g. ul, li, a, h1, h2) and ignores all other copied and pasted stuff? That is the actual text content should be pasted, the rogue HTML elements should be trashed.

2) If it isn't possible in the SimpleHTMLEditorField has there been anyone who has written a OnBeforeWrite function who filters the content?

[Edit] or 3) enable a 'paste as plain text' button similar as in the regular tinyMCE editor.


Community Member, 150 Posts

10 February 2011 at 10:16pm

Edited: 10/02/2011 10:21pm

Same question here. I tried the following in _config.php:

HtmlEditorConfig::get('cms')->setOption('invalid_elements', 'xml');

But this didn't work. Maybe because this code is only executed upon a TinyMCE cleanup (an I'm not sure if clean up is automatically performed upon "Save & Publish"

PS. This is the code that client managed to paste into the HTLMEditorField (this is before the actual content):

<p><!--[if gte mso 9]><xml> <o:OfficeDocumentSettings> <o:AllowPNG /> </o:OfficeDocumentSettings> </xml><![endif]--><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:TrackMoves /> <w:TrackFormatting /> <w:HyphenationZone>21</w:HyphenationZone> <w:PunctuationKerning /> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:DoNotPromoteQF /> <w:LidThemeOther>NL</w:LidThemeOther> <w:LidThemeAsian>X-NONE</w:LidThemeAsian> <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript> <w:Compatibility> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> <w:SplitPgBreakAndParaMark /> <w:EnableOpenTypeKerning /> <w:DontFlipMirrorIndents /> <w:OverrideTableStyleHps /> </w:Compatibility> <m:mathPr> <m:mathFont m:val="Cambria Math" /> <m:brkBin m:val="before" /> <m:brkBinSub m:val="&#45;-" /> <m:smallFrac m:val="off" /> <m:dispDef /> <m:lMargin m:val="0" /> <m:rMargin m:val="0" /> <m:defJc m:val="centerGroup" /> <m:wrapIndent m:val="1440" /> <m:intLim m:val="subSup" /> <m:naryLim m:val="undOvr" /> </m:mathPr></w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"   DefSemiHidden="true" DefQFormat="false" DefPriority="99"   LatentStyleCount="267"> <w:LsdException Locked="false" Priority="0" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Normal" /> <w:LsdException Locked="false" Priority="9" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="heading 1" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9" /> <w:LsdException Locked="false" Priority="39" Name="toc 1" /> <w:LsdException Locked="false" Priority="39" Name="toc 2" /> <w:LsdException Locked="false" Priority="39" Name="toc 3" /> <w:LsdException Locked="false" Priority="39" Name="toc 4" /> <w:LsdException Locked="false" Priority="39" Name="toc 5" /> <w:LsdException Locked="false" Priority="39" Name="toc 6" /> <w:LsdException Locked="false" Priority="39" Name="toc 7" /> <w:LsdException Locked="false" Priority="39" Name="toc 8" /> 


and much, much more :)


Community Member, 150 Posts

13 February 2011 at 11:12am

Sorry, I was refering to TinyMCE. I found a solution to auto enable paste from word in TinyMCE:

Think this does the trick (to be added to _config.php in /mysite):


Found here: