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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Limit HTML elements used in SimpleHTMLEditorField


Reply


3 Posts   1848 Views

Avatar
MarijnKampf

Community Member, 164 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.

Avatar
klikhier

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 :)
</p>

Avatar
klikhier

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):

HtmlEditorConfig::get('cms')->setOption('paste_auto_cleanup_on_paste','true');
HtmlEditorConfig::get('cms')->setOption('paste_remove_styles','true');
HtmlEditorConfig::get('cms')->setOption('paste_remove_styles_if_webkit','true');
HtmlEditorConfig::get('cms')->setOption('paste_strip_class_attributes','true');

Found here: [url]http://www.miuaiga.com/index.cfm/2010/1/7/New-TinyMCE-lets-you-paste-as-plain-text-automatically[/url]