EnableID is set to "Yes". In the node edit screen, I can insert an anchor (name="top") into CKEditor using the "Filtered HTML" text format. When I click save, the anchor appears in the node's code. When I go back in to edit the node using the Seven theme, the anchor disappears in the CKEditor. I can see the code for half a second with the named anchor, but when CKEditor loads, it is stripped. I know it's related to the HTML Purifier because if I disable this filter, the anchor works on both the node and the node edit screen.

Comments

heddn’s picture

@jmart
Try using advanced configuration and HTML.AllowedAttributes to enable a.name.

jmart’s picture

heddn, enabling a.name in HTML.AllowedAttributes did not work.

bright8’s picture

Having a very similar problem, except in my case it is the "target" attribute that is getting stripped from the anchor tag. For example, I add some text to a node using CKEditor and include a hyperlink in the text which I want to open the link in a new tab/window. So my content could be:

here is some text with a <a target="_blank" href="http://somewebsite.com">hyperlink</a>

I save the node and my anchor tag is preserved correctly (ie the link opens in a new tab/window). I then edit the node again and as soon as the node is opened in edit mode the target attribute is stripped from the anchor tag, so my code now reads (in the CKEditor window):

here is some text with a <a href="http://somewebsite.com">hyperlink</a>

The target attribute was preserved on saving the node, but stripped on opening it in edit mode.

Like jmart, if I disable the HTML Purifier (advanced) filter on the text format I'm using, the problem goes away.

Interestingly, if I then re-enable the HTML Purifier (advanced) filter, it is added again to the text format configuration page with all its configuration parameters intact except AllowedFrameTargets. Before I disabled the filter AllowedFrameTargets was set to an array of "_blank, _self, _parent, _top". After disabling the filter, saving the text format then re-enabling the filter AllowedFrameTargets is empty.

I've tried flushing the HTML Purifier cache, but that makes no difference. I'm using module version 7.x-2.x-dev (2012-Jan-29) with HTML Purifier library 4.4.0. I'm using the CKEditor module (version 7.x-1.9+14-dev (2012-Jun-29)) to load CKEditor library 3.6.2. Like jmart, I'm using the Seven admin theme.

I'm not sure if jmart is losing the whole anchor tag or just the name attribute from within the tag??

Perhaps this is an interaction between CKEditor and HTML Purifier? The strange thing is I always assumed filters only got applied on node save and not on opening the node in edit mode.

Any suggestions? Many thanks...

bright8’s picture

I have confirmed the filter gets run every time CKEditor loads (eg on opening node in edit mode, switching between text formats which use CKEditor, disabling/re-enabling rich text editing, etc). The target attribute gets stripped from the <a> tag every time HTMLPurifier runs EXCEPT on node save.

I tried setting HTML.TargetBlank to true, to force all anchors to use target=_blank, but still no target attribute in the anchor tag.

Anybody able to help or suggest further diagnostics? Thanks.

heddn’s picture

Might issue #1140216: name/target attribute being stripped from links be a duplicate to this one? It seems to give instructions on how to configure target, etc in advanced configuration mode. I don't have time to test it right now (I'm at work) or I'd try it myself.

bright8’s picture

Thanks for the response heddn. It's not clear whether it's the same issue or not, especially as the original poster seems to have abandoned the issue without saying if it was ever resolved.

In that issue the last poster, ñull, points out that it's necessary to set the array of possible target values in AllowedFrameTargets. I have done that in my HTML Purifier (advanced) configuration. He also points out that target has to be among the AllowedAttributes. According to this page target is one of the attributes on the standard HTML Purifier white list.

In any case, when the HTML Purifier filter runs on saving the node, the target attribute is preserved. It's only stripped when the filter runs under all other circumstances.

I have checked a different site I have which runs Drupal 6 and also uses HTML Purifier (same library version) and CKEditor, but on that site CKEditor is handled by the WYSIWYG module. The HTML Purifier configuration is identical. This problem does not occur on that site.

heddn’s picture

Status: Active » Postponed (maintainer needs more info)

After doing more research, I am theorizing this is an issue with CKEditor. I don't think that HTML Purifier modifies/changes any of the data that gets stored in the database. However, CKEditor will and does modify data in its editor at save time. Please try switching out ckeditor module for wysiwyg module in a sandbox to see if the issue still persists.

heddn’s picture

After doing more research, I am theorizing this is an issue with CKEditor. I don't think that HTML Purifier modifies/changes any of the data that gets stored in the database. However, CKEditor will and does modify data in its editor at save time. Please try switching out ckeditor module for wysiwyg module in a sandbox to see if the issue still persists.

heddn’s picture

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