tags:

views:

69

answers:

1

Using copy-paste (or the code plugin) users are able to insert content including spans yielding to nested spans even though i thought that my settings forbid nested spans. I do want to have nested spans been filtered out when the "cleanup" action gets performed.

Doing a manual cleanup (command "mceCleanup" which is triggered after pasting text) does not help either.

Reffering to the TinyMCE documentation a user may choose which child elements tinymce discards when performing "cleanup" for defined parent nodes.

Is there a problem with my config? If yes, what is wrong? Any suggestions?

Here's my configuration (the relevant part, i am using the newest tinymce version (3.3.8), occurs in all major browsers):

    cleanup : true,

    encoding: "xml",

    dialog_type : "modal",

    object_resizing: false,
    paste_strip_class_attributes: "all",

    entity_encoding: "raw",

    fix_nesting: true,

    invalid_elements: "strong,ul,ol,li",


    // The valid_elements option defines which elements will remain in the edited text when the editor saves.
    valid_elements: "@[id|class|title|style],"
    + "a[name|href|target|title],"
    + "#p,-ol,-ul,-li,br,img[src],-sub,-sup,-b,-i,"
    + "-span,hr",

    valid_child_elements : "body[p|ol|ul]"  //EDIT: had some ","s instead of "|"s
    + ",p[a|span|b|i|sup|sub|img|hr|#text]"
    + ",span[a|b|i|sup|sub|img|#text]"
    + ",a[span|b|i|sup|sub|img|#text]"
    + ",b[span|a|i|sup|sub|img|#text]"
    + ",i[span|a|b|sup|sub|img|#text]"
    + ",sup[span|a|i|b|sub|img|#text]"
    + ",sub[span|a|i|b|sup|img|#text]"
    + ",li[span|a|b|i|sup|sub|img|ol|ul|#text]"
    + ",ol[li]"
    + ",ul[li]"
+1  A: 

I don't think there is any problem with your config.

The problem is that the TinyMCE code totally ignores the valid_child_elements attribute since version 3.3b1 (25 January 2010). I used Window Grep to examine all files in the 3.3.8 download and the valid_child_elements string is only found twice (and on the same line) in /jscripts/tiny_mce/Classes/Editor.js - this turns out to be a simple assignment statement that is not used anywhere else.

It turns out that in version 3.2.7 (22 September 2009) or below (see http://sourceforge.net/projects/tinymce/files), the valid_child_elements attribute calls a function called addValidChildRules in /jscripts/tiny_mce/Classes/dom/Serializer.js which I believe does what you essentially want. There are bugs in this version mind you. I eventually got the nested tags to be removed after adding a simplified valid_child_elements config parameter to one of the sample files in the download:

valid_child_elements : "span[a|b|i|sup|sub|img|#text]"

Hope this helps.

Bermo
Already had searched through the code and only found the two places you did. The explanation that this was once working (version 3.2.7) somewhat explains it a bit. So you did configure tinymce using valid_child_elements in version 3.2.7?
Thariama
Yes, while using 3.2.7 and configuring using the `valid_child_elements` settings as I've shown in the code block above, it correctly removed the nested span tags. When I tried with the extra elements you provided for `valid_child_elements` in your question above however, I get Javascript errors.
Bermo
thanks for your efforts - this helped me a lot (bounty is yours). tinymce chief developer told me when asked that his functionality will return in version 3.4 but will be applied using an other more convenient way of configuration
Thariama
After replacing some ","s with "|"s (an error in configuration) 3.2.7 accepts my whole configuration of valid_child_elements
Thariama
I missed that, I'm glad to hear you've got it working.
Bermo