Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Limit HTML elements used in SimpleHTMLEditorField

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 1783 Views
  • MarijnKampf
    Community Member
    164 Posts

    Limit HTML elements used in SimpleHTMLEditorField Link to this post

    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.

  • klikhier
    Community Member
    150 Posts

    Re: Limit HTML elements used in SimpleHTMLEditorField Link to this post

    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

  • klikhier
    Community Member
    150 Posts

    Re: Limit HTML elements used in SimpleHTMLEditorField Link to this post

    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: http://www.miuaiga.com/index.cfm/2010/1/7/New-TinyMCE-lets-you-paste-as-plain-text-automatically

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.