I'm not sure I'm posting this in the right issue queue. Apologies if it should go somewhere else. I use the Media module and the CKEditor. When I insert an image using the media module it works fine. When I then go to image properties and set align to left it still works fine. But when I save or preview the style tag gets stripped from the media tag (which sort of makes me think I should really post this in the Media issue queue).

Source before saving / after using the Media plugin to insert an image and aligning it left:

[[{"type":"media","view_mode":"media_preview","fid":"5","attributes":{"class":"media-image","style":"float: left;"}}]]

Source after saving:

[[{"type":"media","view_mode":"media_preview","fid":"5","attributes":{"class":"media-image"}}]]

Comments

alyssum’s picture

Status: Active » Closed (duplicate)

Confirmed the bug here too, but this is a duplicate of an issue in the Media module http://drupal.org/node/1043570

jlbretton’s picture

Version: 7.x-2.x-dev » 7.x-2.1
Status: Closed (duplicate) » Active

Hi I'm reopening this one. I'm having the same issue on 2 projects, without the Media module.
One project is using TinyMCE and the other one the ckeditor. I guess it's probably more related to the Wysiwyg module.
This happen not only on images, but also on aligning text content.

Wysiwyg 7.x-2.1
TinyMCE 3.5.1.1
IMCE Wysiwyg API bridge 7.x-1.0
IMCE 7.x-1.5

Thanks

TwoD’s picture

Status: Active » Postponed (maintainer needs more info)

If you disable the editor using the "Disable rich-text" link, is the style attribute there?
Is it still there if you edit the node again?
If so, this is not a Wysiwyg or editor problem.
You probably want to move the IMCE filter so it runs after the previously mentioned filter(s) so its output isn't affected by any whitelists.

Since you also have problems with alingning text, you most likely want to disable the "Limit allowed HTML tags" filter on the text format(s) you are using the editor with. That filter always removes style attributes during rendering for security reasons.

There is a much more advanced and flexible filter, if you need one, in WYSIWYG Filter. It will allow you to specify which tags are allowed to use the style attribute - and which style properties are allowed - using whitelists.
That module is also able to auto-configure TinyMCE's extended_valid_elements setting so it should not filter out any tag which Drupal will allow to render before the contents are sent to the editor.

Did that help?

TwoD’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

Without further details about the problem I can only close this issue. Please re-open it if you can provide the requested information.

darksnow’s picture

Version: 7.x-2.1 » 7.x-2.2
Issue summary: View changes
Status: Closed (cannot reproduce) » Active

Hi. I'd like to revisit this.

I have WYSIWYG 7.22 installed with media 7.x-2.0-alpha3 and have tried with CKEditor 4.0.3 and 4.4.1 with no luck.

There are loads of issues scattered over WYSIWYG and Media about this, but none of the fixes I found work.

The problem is simple enough. If I insert an image it appears fine after being uploaded or selected from the library. If I then double click on the image and set it's alignment to right, it appears to float right in the editor. If I then press "disabled rich text" there are no style attributes in the media tag.

Similarly, if I save the node the image is not floated right.

There seems to be some debate over which module is responsible for this, so if this is a media issue please point me in the right direction. I've been on this for hours with only frustration so far.

Thanks for any help you can offer.

TwoD’s picture

CKEditor 4 has what they call an Advanced Content Filter, responsible for removing any markup not explicitly allowed by one of its enabled plugins, or by user configuration. If you're using CKEditor 4, you're currently using Wysiwyg 7.x-2.x-dev, which has settings to control this feature by either specifying your own rules, or adding to the rules whitelist from within the editor configuration. The syntax is explained there, though the exact rules vary depending on which version of Media you're using, and possibly with the settings you use for its WYSIWYG mode previews.

One problem is that Media module's plugin runs after the editor has generated (and thus filtered) the markup, so sometimes the Media module may not just lose inline styles, but it will be unable to even recognize its placeholder tags because the filters are too strict.

There's currently no easy way for plugins to add to these filter rules automatically, or specify entire tag hierarchies as "placholders" meant to be left alone, but I've been working on it for some time now. I'm trying to get it into the next relase, but it may take time before plugins implement it.

I'll redirect all the issues related to this to a new issue once I've posted the patch.

darksnow’s picture

Thanks for the quick reply TwoD very helpful.

I'm not using the dev release of WYSIWYG but I'm confortable in the code. Is there a quick and dirty way to turn off ACF? I added allowedContent => FALSE to $settings in wysiwyg_ckeditor_settings which seems to now allow a comment tag through, but has not fixed my issue.

Is it possible that media also filters the tag, so ACF removes it in WYSIWYG but a corresponding change is needed in media to make this actually work.

Thanks for the help so far and good luck getting the patch in. Seems like such a simple thing that it should work if it's in the UI.

TwoD’s picture

You can implement hook_wysiwyg_editor_settings_alter() to not have to hack Wysiwyg module, see below. You say you're not using the dev release, but you should not be able to use CKEditor 4 with Wysiwyg 7.x-2.2 or earlier, since they won't even detect CKEditor 4 as installed. If you've previously applied some patch to get CKEditor 4 working with Wysiwyg 7.x-2.2, I would advice to use the -dev snapshot instead since it has most likely had several more changes to improve compatibility with that editor version and its new/renamed/removed plugins and buttons.

/**
 * Implements hook_wysiwyg_editor_settings_alter().
 *
 */
function MYMODULE_wysiwyg_editor_settings_alter(&$settings, $context) {
  if ($context['profile']->editor == 'ckeditor') {
    $settings['allowedContent'] = TRUE; // TRUE actually disables ACF, as in "allow anything"
  }
}
TwoD’s picture

Status: Active » Closed (works as designed)
Related issues: +#2510970: CKEditor removes the "style" attribute, +#3017048: Onclick with CKeditor

Please see the related issues for how to deal with ACF (which now has a config section on CKEditor profiles and #3017048-2: Onclick with CKeditor gives an example of how to work with it).

Getting plugins to specify which tags/attributes they require is tricky but I think there's already another issue for that. Didn't find it now but when I do I'll reference this issue from there.