0

I am working on a project where the admin wishes to be able to insert a element into a node's body field. The site makes use of TinyMCE editor (wysiwyg module) to edit text area fields.

Currently admin is able to add the element to the body field by switching to source mode of Full HTML text format (by toggling "disable rich-text"). He can then insert the element and then save node. In this case the element will be preserved in the saved markup.

But if the node is edited again the wysiwyg appears to filter out the element, which means the admin has to re-add it using the method just described.

This unwanted removal of element also occurs when switching back and forth between the rich-text editor (toggling the "Enable rich-text" or "Disable rich-text" link below the field) after adding the element.

So it seems it is the wysiwyg is filtering this element out.

Is there a way of preventing this from happening?

1 Answer 1

1

TinyMCE outputs HTML 4.01 Transitional markup by default, and is not allowed inside in that (or XHTML) because styles are not block elements.

You can however force TinyMCE to accept [the invalid] style elements inside the body by overriding the valid_children setting.

/**
 * Implements hook_wysiwyg_editor_settings_alter().
 */
function MYMODULE_wysiwyg_editor_settings_alter(&$settings, $context) {
  if ($context['profile']->editor == 'tinymce') {
    $settings['valid_children'] = '+body[style]';
  }
}

Thanks to TwoD for supplying the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.