<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel>
        <title>Problem with HTML.TargetBlank and HTML.Nofollow</title>
        <description>Hi,

I have problem with HTML Purifier.
I tried to find solution, but I can't.

My problem is:

I want to add/change 2 attributes (target=&quot;_blank&quot; and rel=&quot;nofollow&quot;) to each  tag.

My code:

set('HTML.Nofollow', true);
	$config-&gt;set('HTML.TargetBlank', true);
	$config-&gt;set('HTML.Allowed', 'a,b,strong,i,em,u');
$purifier = new HTMLPurifier($config);
echo $purifier-&gt;purify('test page');
?&gt;
]]&gt;

And result of execution is:

test page
]]&gt;

Everytime HTMLPurifier adds &quot;target&quot; attribute only.

I tried to change order like this:

set('HTML.TargetBlank', true);
$config-&gt;set('HTML.Nofollow', true);
]]&gt;

but result always is the same:

test page
]]&gt;

Is it possible to add both of attributes to the same HTML tag?
What I do wrong?

Thank you for each response and help.</description>
        <link>http://htmlpurifier.org/phorum/read.php?3,6182,6182#msg-6182</link>
        <lastBuildDate>Wed, 22 May 2013 21:51:04 -0400</lastBuildDate>
        <generator>Phorum 5.2.18</generator>
        <item>
            <guid>http://htmlpurifier.org/phorum/read.php?3,6182,6854#msg-6854</guid>
            <title>Re: Problem with HTML.TargetBlank and HTML.Nofollow</title>
            <link>http://htmlpurifier.org/phorum/read.php?3,6182,6854#msg-6854</link>
            <description><![CDATA[<p>ok, got you now. :) I always read books from the back. lol</p>

<p><a href="http://www.impresscms.org">ImpressCMS: Make A Lasting Impression</a></p>]]></description>
            <dc:creator>vaughan</dc:creator>
            <category>Support</category>
            <pubDate>Wed, 06 Mar 2013 07:45:08 -0500</pubDate>
        </item>
        <item>
            <guid>http://htmlpurifier.org/phorum/read.php?3,6182,6853#msg-6853</guid>
            <title>Re: Problem with HTML.TargetBlank and HTML.Nofollow</title>
            <link>http://htmlpurifier.org/phorum/read.php?3,6182,6853#msg-6853</link>
            <description><![CDATA[<p>I don't think we're on the same page :)</p>

<p>There is a bug that sets the target as "blank" rather than "_blank", notice the lack of the underscore.
There seems to be another bug where if you set the target as _blank and also use rel="nofollow", - nofollow gets removed somehow.</p>

<p>My fix above sorts out both problems - in the standalone version.</p>

<p>It should perhaps be shortened like below, no real need for the "else":</p>

<pre>
if ($config-&gt;get('HTML.Nofollow')) {
    $attr['rel'] = 'nofollow';
}
$attr['target'] = '_blank';
</pre>]]></description>
            <dc:creator>sitesense</dc:creator>
            <category>Support</category>
            <pubDate>Mon, 04 Mar 2013 14:47:55 -0500</pubDate>
        </item>
        <item>
            <guid>http://htmlpurifier.org/phorum/read.php?3,6182,6850#msg-6850</guid>
            <title>Re: Problem with HTML.TargetBlank and HTML.Nofollow</title>
            <link>http://htmlpurifier.org/phorum/read.php?3,6182,6850#msg-6850</link>
            <description><![CDATA[<p>well after reading up, bean a while.</p>

<p>parent="_blank" was invalid under XHTML W3C spec. so no pages would validate if that was used, which is why a javascript trick was created to use rel="external" to open links in a new window/tab.</p>

<p>the reasoning given by w3C for not being valid, is that it should be up to the user to decide if they want to open in new window or same page (afterall there's the right click context menu), but as we know many users don't bother or even know to use that, neither are they bothered about web standards.</p>

<p>i agree in some ways, but in others not, it can be annoying at times if u click a link and it opens in the same window, especially if you were in the middle of a long post or using an app.</p>

<p>my opinion is that, internal links should really open in the same window, with information links (like help tips) opening a small popup window, not the website itself.</p>

<p>external links to other websites should open in a new window so that you are not directed off the website you were on.</p>

<p>the good news in all this, is that under HTML5 they have caved to demand from developers &amp; website owners, &amp; target="_blank" is now a valid attribute, that means if _blank is used in your URL's it will pass when validated by W3C. not that being fully validated has ever bothered me or any of my clients anyway. I think it was just a fad so some companies could make more money.</p>

<p><a href="http://www.impresscms.org">ImpressCMS: Make A Lasting Impression</a></p>]]></description>
            <dc:creator>vaughan</dc:creator>
            <category>Support</category>
            <pubDate>Sun, 03 Mar 2013 13:57:53 -0500</pubDate>
        </item>
        <item>
            <guid>http://htmlpurifier.org/phorum/read.php?3,6182,6849#msg-6849</guid>
            <title>Re: Problem with HTML.TargetBlank and HTML.Nofollow</title>
            <link>http://htmlpurifier.org/phorum/read.php?3,6182,6849#msg-6849</link>
            <description><![CDATA[<p>Where is target="blank" valid? It's just wrong whatever the doctype.</p>]]></description>
            <dc:creator>sitesense</dc:creator>
            <category>Support</category>
            <pubDate>Sat, 02 Mar 2013 23:07:06 -0500</pubDate>
        </item>
        <item>
            <guid>http://htmlpurifier.org/phorum/read.php?3,6182,6805#msg-6805</guid>
            <title>Re: Problem with HTML.TargetBlank and HTML.Nofollow</title>
            <link>http://htmlpurifier.org/phorum/read.php?3,6182,6805#msg-6805</link>
            <description><![CDATA[<p>parent="_blank" is not recommended anyway, _blank is not valid xhtml so if you use it with xhtml doc types it will not validate.</p>

<p>best way being as you are using rel is instead of using parent, use rel="external" instead. along with nofollow, rel="external nofollow"</p>

<p><a href="http://www.impresscms.org">ImpressCMS: Make A Lasting Impression</a></p>]]></description>
            <dc:creator>vaughan</dc:creator>
            <category>Support</category>
            <pubDate>Fri, 15 Feb 2013 10:58:08 -0500</pubDate>
        </item>
        <item>
            <guid>http://htmlpurifier.org/phorum/read.php?3,6182,6803#msg-6803</guid>
            <title>Re: Problem with HTML.TargetBlank and HTML.Nofollow</title>
            <link>http://htmlpurifier.org/phorum/read.php?3,6182,6803#msg-6803</link>
            <description><![CDATA[<p>Standalone version 4.4.0 suffers from same problem.
I fixed it by replacing line 11273 in HTMLPurifier-standalone.php with the following:</p>

<pre>
if ($config-&gt;get('HTML.Nofollow')) {
    $attr['rel'] = 'nofollow';
    $attr['target'] = '_blank';
} else {
    $attr['target'] = '_blank';
}
</pre>]]></description>
            <dc:creator>sitesense</dc:creator>
            <category>Support</category>
            <pubDate>Thu, 14 Feb 2013 16:43:11 -0500</pubDate>
        </item>
        <item>
            <guid>http://htmlpurifier.org/phorum/read.php?3,6182,6778#msg-6778</guid>
            <title>Re: Problem with HTML.TargetBlank and HTML.Nofollow</title>
            <link>http://htmlpurifier.org/phorum/read.php?3,6182,6778#msg-6778</link>
            <description><![CDATA[<p>Ah nevermind, I just set:
</p>

<pre>
$config-&gt;set('URI.Host', 'mysite.com');
</pre>

<p>to:
</p>

<pre>

$config-&gt;set('URI.Host', $_SERVER['HTTP_HOST']);
</pre>

<p>This seems to does the trick. It removes the rel="nofollow" on internal links and adds it to external links, just like I wanted. Although it also removes the target="_blank" from internal links at the same time. This is not a big deal though, we can live with it!</p>

<p>I did find a possible bug though. I noticed that when these two lines exist at the same time:
</p>

<pre>
$config-&gt;set('Attr.AllowedRel', array('nofollow'));
$config-&gt;set('HTML.Nofollow', true);
</pre>

<p>Any rel="nofollow" on external links that get re-saved during edit, will turn into rel="Array nofollow". </p>

<p>Thanks
Kind regards</p>

<p>Edited 1 time(s). Last edit at 01/26/2013 04:25PM by peppy.</p>]]></description>
            <dc:creator>peppy</dc:creator>
            <category>Support</category>
            <pubDate>Sat, 26 Jan 2013 16:24:59 -0500</pubDate>
        </item>
        <item>
            <guid>http://htmlpurifier.org/phorum/read.php?3,6182,6777#msg-6777</guid>
            <title>Re: Problem with HTML.TargetBlank and HTML.Nofollow</title>
            <link>http://htmlpurifier.org/phorum/read.php?3,6182,6777#msg-6777</link>
            <description><![CDATA[<p>OOPS!! After looking for hours trying to flush the cache, I figured it out 1 minute after posting a question.</p>

<p>In case anyone else is trying to figure it out, go to maintenance/.htaccess and remove: Deny from all . Then go to maintenance/common.php and change:
</p>

<pre>
if (php_sapi_name() != 'cli' &amp;&amp; !getenv('PHP_IS_CLI')) {
</pre>

<p>to:</p>

<pre>
if (php_sapi_name() == 'cli' &amp;&amp; getenv('PHP_IS_CLI')) {
</pre>

<p>Save both files, run maintenance/flush.php in your browser and it should work. Then reverse all the changes in these two files to what they were originally and save them.</p>

<p>.
.
.</p>

<p><u>There is one last piece</u> to the puzzle that is not working right. rel="nofollow" is still being added to internal links.</p>

<p>Please let me know what needs to be done.</p>

<p>Thanks
Kind regards</p>]]></description>
            <dc:creator>peppy</dc:creator>
            <category>Support</category>
            <pubDate>Sat, 26 Jan 2013 16:10:48 -0500</pubDate>
        </item>
        <item>
            <guid>http://htmlpurifier.org/phorum/read.php?3,6182,6776#msg-6776</guid>
            <title>Re: Problem with HTML.TargetBlank and HTML.Nofollow</title>
            <link>http://htmlpurifier.org/phorum/read.php?3,6182,6776#msg-6776</link>
            <description><![CDATA[<p>Greetings,</p>

<p>I am new to HTML purifier, it looks like an excellent and easy to use script!!</p>

<p>Unfortunately, I am having the same issues related to this post. I am using HTMLPurifier in conjunction with CKEditor. So far, I've got the entire TargetBlank issue on my end all cleared up. I can also allow "nofollow" when CKEditor automatically adds the attribute. The drawback with CKEditor is users can view the source code and manually erase the rel="nofollow" and save the post, which is a hole to get around the editor.</p>

<p>My only problem now is I can't get HTMLPurifier to add rel="nofollow" to external links when users somehow get around CKEditor. (I would like to remove rel="nofollow" on my INTERNAL links though).</p>

<p>Here is what I have:
</p>

<pre>
require_once("../htmlpurifier-4.4.0/library/HTMLPurifier.auto.php");
$config = HTMLPurifier_Config::createDefault();
$config-&gt;set('URI.Host', 'mysite.com');
$config-&gt;set('Attr.AllowedRel', array('nofollow'));
$config-&gt;set('HTML.Nofollow', true);
$config-&gt;set('HTML.TargetBlank', true);
$config-&gt;set('AutoFormat.RemoveEmpty', true);
$purifier = new HTMLPurifier($config);
</pre>

<p>
I've followed your instructions here and changed the source files in HTMLPurifier: <a href="http://repo.or.cz/w/htmlpurifier.git/commit/7291f19347b05f5833421eaf5152558bfbd2b454">http://repo.or.cz/w/htmlpurifier.git/commit/7291f19347b05f5833421eaf5152558bfbd2b454</a></p>

<p>Now when I go to maintenance/flush.php , I get the following error:</p>

<p>Forbidden</p>

<p>You don't have permission to access /htmlpurifier-4.4.0/maintenance/flush.php on this server.</p>

<p>Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.</p>

<p>
How can I clear the cache so that your fix will work?</p>

<p>Thanks
Kind regards</p>

<p>Edited 3 time(s). Last edit at 01/26/2013 03:55PM by peppy.</p>]]></description>
            <dc:creator>peppy</dc:creator>
            <category>Support</category>
            <pubDate>Sat, 26 Jan 2013 15:52:31 -0500</pubDate>
        </item>
        <item>
            <guid>http://htmlpurifier.org/phorum/read.php?3,6182,6677#msg-6677</guid>
            <title>Re: Problem with HTML.TargetBlank and HTML.Nofollow</title>
            <link>http://htmlpurifier.org/phorum/read.php?3,6182,6677#msg-6677</link>
            <description><![CDATA[<p>Sorry, I have the same problem here, I make everything except the final flush, don't know how to use it. Trying to access in browser gives me a 403.</p>]]></description>
            <dc:creator>xomero</dc:creator>
            <category>Support</category>
            <pubDate>Wed, 24 Oct 2012 21:42:43 -0400</pubDate>
        </item>
        <item>
            <guid>http://htmlpurifier.org/phorum/read.php?3,6182,6286#msg-6286</guid>
            <title>Re: Problem with HTML.TargetBlank and HTML.Nofollow</title>
            <link>http://htmlpurifier.org/phorum/read.php?3,6182,6286#msg-6286</link>
            <description><![CDATA[<p>Thanks. Now work as I expect. :)</p>]]></description>
            <dc:creator>stelmik</dc:creator>
            <category>Support</category>
            <pubDate>Mon, 19 Mar 2012 16:15:57 -0400</pubDate>
        </item>
        <item>
            <guid>http://htmlpurifier.org/phorum/read.php?3,6182,6285#msg-6285</guid>
            <title>Re: Problem with HTML.TargetBlank and HTML.Nofollow</title>
            <link>http://htmlpurifier.org/phorum/read.php?3,6182,6285#msg-6285</link>
            <description><![CDATA[<p>Try flushing the cache with maintenance/flush.php</p>]]></description>
            <dc:creator>Ambush Commander</dc:creator>
            <category>Support</category>
            <pubDate>Sun, 18 Mar 2012 18:21:55 -0400</pubDate>
        </item>
        <item>
            <guid>http://htmlpurifier.org/phorum/read.php?3,6182,6284#msg-6284</guid>
            <title>Re: Problem with HTML.TargetBlank and HTML.Nofollow</title>
            <link>http://htmlpurifier.org/phorum/read.php?3,6182,6284#msg-6284</link>
            <description><![CDATA[<p>OK. I replaced files from:
<a href="http://repo.or.cz/w/htmlpurifier.git/commit/7291f19347b05f5833421eaf5152558bfbd2b454">http://repo.or.cz/w/htmlpurifier.git/commit/7291f19347b05f5833421eaf5152558bfbd2b454</a>
but the result doesn't change.</p>

<p>All the time the result is:</p>

<pre>
&lt;a href="<a href="http://www.google.com/">http://www.google.com/</a>" target="_blank"&gt;test page&lt;/a&gt;
</pre>

<p>Probably you didn't commit all files or not tested my example.</p>]]></description>
            <dc:creator>stelmik</dc:creator>
            <category>Support</category>
            <pubDate>Sun, 18 Mar 2012 17:22:57 -0400</pubDate>
        </item>
        <item>
            <guid>http://htmlpurifier.org/phorum/read.php?3,6182,6279#msg-6279</guid>
            <title>Re: Problem with HTML.TargetBlank and HTML.Nofollow</title>
            <link>http://htmlpurifier.org/phorum/read.php?3,6182,6279#msg-6279</link>
            <description><![CDATA[<p>Fixed in <a href="http://repo.or.cz/w/htmlpurifier.git/commit/7291f19347b05f5833421eaf5152558bfbd2b454">http://repo.or.cz/w/htmlpurifier.git/commit/7291f19347b05f5833421eaf5152558bfbd2b454</a></p>]]></description>
            <dc:creator>Ambush Commander</dc:creator>
            <category>Support</category>
            <pubDate>Fri, 16 Mar 2012 23:12:43 -0400</pubDate>
        </item>
        <item>
            <guid>http://htmlpurifier.org/phorum/read.php?3,6182,6278#msg-6278</guid>
            <title>Re: Problem with HTML.TargetBlank and HTML.Nofollow</title>
            <link>http://htmlpurifier.org/phorum/read.php?3,6182,6278#msg-6278</link>
            <description><![CDATA[<p>Diagnosed, fixing...</p>]]></description>
            <dc:creator>Ambush Commander</dc:creator>
            <category>Support</category>
            <pubDate>Fri, 16 Mar 2012 22:41:46 -0400</pubDate>
        </item>
        <item>
            <guid>http://htmlpurifier.org/phorum/read.php?3,6182,6277#msg-6277</guid>
            <title>Re: Problem with HTML.TargetBlank and HTML.Nofollow</title>
            <link>http://htmlpurifier.org/phorum/read.php?3,6182,6277#msg-6277</link>
            <description><![CDATA[<p>Looks like a bug. Investigating...</p>]]></description>
            <dc:creator>Ambush Commander</dc:creator>
            <category>Support</category>
            <pubDate>Fri, 16 Mar 2012 22:32:21 -0400</pubDate>
        </item>
        <item>
            <guid>http://htmlpurifier.org/phorum/read.php?3,6182,6276#msg-6276</guid>
            <title>Re: Problem with HTML.TargetBlank and HTML.Nofollow</title>
            <link>http://htmlpurifier.org/phorum/read.php?3,6182,6276#msg-6276</link>
            <description><![CDATA[<p>Below simple code doesn't work properly too:</p>

<pre>
&lt;?php
ini_set('display_errors', TRUE);
error_reporting(E_ALL);

include_once 'include/htmlpurifier/HTMLPurifier.auto.php';
$config = HTMLPurifier_Config::createDefault();
	$config-&gt;set('Core.Encoding', 'UTF-8');
	$config-&gt;set('HTML.Doctype', 'XHTML 1.0 Transitional');
	$config-&gt;set('URI.Host', $_SERVER['HTTP_HOST']);
	$config-&gt;set('HTML.TargetBlank', true);
	$config-&gt;set('HTML.Nofollow', true);
$purifier = new HTMLPurifier($config);
echo $purifier-&gt;purify('&lt;a href="<a href="http://www.google.com/">http://www.google.com/</a>"&gt;test page&lt;/a&gt;');
?&gt;
</pre>

<p>The result is:</p>

<pre>
&lt;a href="<a href="http://www.google.com/">http://www.google.com/</a>" target="_blank"&gt;test page&lt;/a&gt;
</pre>

<p>but should be:</p>

<pre>
&lt;a href="<a href="http://www.google.com/">http://www.google.com/</a>" target="_blank" rel="nofollow"&gt;test page&lt;/a&gt;
</pre>]]></description>
            <dc:creator>stelmik</dc:creator>
            <category>Support</category>
            <pubDate>Fri, 16 Mar 2012 17:54:15 -0400</pubDate>
        </item>
        <item>
            <guid>http://htmlpurifier.org/phorum/read.php?3,6182,6275#msg-6275</guid>
            <title>Re: Problem with HTML.TargetBlank and HTML.Nofollow</title>
            <link>http://htmlpurifier.org/phorum/read.php?3,6182,6275#msg-6275</link>
            <description><![CDATA[<p>OK. I executed the code on other server and there were some warnings.
I modified code and now it look like:</p>

<pre>
&lt;?php
ini_set('display_errors', TRUE);
error_reporting(E_ALL);

include_once 'include/htmlpurifier/HTMLPurifier.auto.php';
$config = HTMLPurifier_Config::createDefault();
	$config-&gt;set('Core.Encoding', 'UTF-8');
	$config-&gt;set('HTML.Doctype', 'XHTML 1.0 Transitional');
	$config-&gt;set('AutoFormat.AutoParagraph', true);
	$config-&gt;set('URI.Host', $_SERVER['HTTP_HOST']);
	$config-&gt;set('HTML.AllowedElements', array('a','b','strong','i','em','u','img','p','span'));
	$config-&gt;set('HTML.AllowedAttributes', array('a.href', 'img.src', '*.alt', '*.title', '*.border', '*.align', '*.width', '*.height', 'img.vspace', 'img.hspace', 'a.target', 'a.rel'));
	$config-&gt;set('AutoFormat.RemoveEmpty.RemoveNbsp', true);
	$config-&gt;set('AutoFormat.RemoveEmpty', true);
	$config-&gt;set('AutoFormat.RemoveSpansWithoutAttributes', true);
	$config-&gt;set('Core.RemoveProcessingInstructions', true);
	$config-&gt;set('HTML.TargetBlank', true);
	$config-&gt;set('HTML.Nofollow', true);
	$config-&gt;set('HTML.TidyLevel', 'heavy');
$purifier = new HTMLPurifier($config);
echo $purifier-&gt;purify('&lt;a href="<a href="http://www.google.com/">http://www.google.com/</a>"&gt;test page&lt;/a&gt;');
?&gt;
</pre>

<p>and the result is:</p>

<pre>
&lt;p&gt;&lt;a href="<a href="http://www.google.com/">http://www.google.com/</a>" target="_blank"&gt;test page&lt;/a&gt;&lt;/p&gt;
</pre>

<p>but should be:</p>

<pre>
&lt;p&gt;&lt;a href="<a href="http://www.google.com/">http://www.google.com/</a>" target="_blank" rel="nofollow"&gt;test page&lt;/a&gt;&lt;/p&gt;
</pre>

<p>Why? :(</p>]]></description>
            <dc:creator>stelmik</dc:creator>
            <category>Support</category>
            <pubDate>Fri, 16 Mar 2012 17:28:00 -0400</pubDate>
        </item>
        <item>
            <guid>http://htmlpurifier.org/phorum/read.php?3,6182,6274#msg-6274</guid>
            <title>Re: Problem with HTML.TargetBlank and HTML.Nofollow</title>
            <link>http://htmlpurifier.org/phorum/read.php?3,6182,6274#msg-6274</link>
            <description><![CDATA[<p>No, I haven't. :(</p>]]></description>
            <dc:creator>stelmik</dc:creator>
            <category>Support</category>
            <pubDate>Fri, 16 Mar 2012 17:15:51 -0400</pubDate>
        </item>
        <item>
            <guid>http://htmlpurifier.org/phorum/read.php?3,6182,6272#msg-6272</guid>
            <title>Re: Problem with HTML.TargetBlank and HTML.Nofollow</title>
            <link>http://htmlpurifier.org/phorum/read.php?3,6182,6272#msg-6272</link>
            <description><![CDATA[<p>Yeah, I get a lot of warnings and notices when I execute your code. Do you have custom error handler installed or something?</p>]]></description>
            <dc:creator>Ambush Commander</dc:creator>
            <category>Support</category>
            <pubDate>Fri, 16 Mar 2012 11:29:47 -0400</pubDate>
        </item>
        <item>
            <guid>http://htmlpurifier.org/phorum/read.php?3,6182,6271#msg-6271</guid>
            <title>Re: Problem with HTML.TargetBlank and HTML.Nofollow</title>
            <link>http://htmlpurifier.org/phorum/read.php?3,6182,6271#msg-6271</link>
            <description><![CDATA[<p>I added lines (top of the PHP file):</p>

<pre>
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
</pre>

<p>and now it look like:</p>

<pre>
&lt;?php
ini_set('display_errors', TRUE);
error_reporting(E_ALL);

include_once 'library/HTMLPurifier.auto.php';
$config = HTMLPurifier_Config::createDefault();
	$config-&gt;set('Core.Encoding', 'UTF-8');
	$config-&gt;set('HTML.Doctype', 'XHTML 1.0 Transitional');
	$config-&gt;set('AutoFormat.AutoParagraph', true);
	$config-&gt;set('URI.Host', $_SERVER['HTTP_HOST']);
	$config-&gt;set('HTML.AllowedElements', array('a','b','strong','i','em','u'));
	$config-&gt;set('HTML.AllowedAttributes', array('a.href', 'img.src', '*.alt', '*.title', '*.border', '*.align', '*.width', '*.height', 'img.vspace', 'img.hspace', 'a.target', 'a.rel'));
	$config-&gt;set('AutoFormat.RemoveEmpty.RemoveNbsp', true);
	$config-&gt;set('AutoFormat.RemoveEmpty', true);
	$config-&gt;set('AutoFormat.RemoveSpansWithoutAttributes', true);
	$config-&gt;set('Core.RemoveProcessingInstructions', true);
	$config-&gt;set('HTML.TargetBlank', true);
	$config-&gt;set('HTML.Nofollow', true);
	$config-&gt;set('HTML.TidyLevel', 'heavy');
$purifier = new HTMLPurifier($config);
echo $purifier-&gt;purify('&lt;a href="<a href="http://www.google.com/">http://www.google.com/</a>"&gt;test page&lt;/a&gt;');
?&gt;
</pre>

<p>But result is clear, no warnings or notices.</p>

<p>Do you tried execute my code? Is it working for you?</p>]]></description>
            <dc:creator>stelmik</dc:creator>
            <category>Support</category>
            <pubDate>Fri, 16 Mar 2012 07:01:56 -0400</pubDate>
        </item>
        <item>
            <guid>http://htmlpurifier.org/phorum/read.php?3,6182,6270#msg-6270</guid>
            <title>Re: Problem with HTML.TargetBlank and HTML.Nofollow</title>
            <link>http://htmlpurifier.org/phorum/read.php?3,6182,6270#msg-6270</link>
            <description><![CDATA[<p>Turn on your PHP warnings and notices.</p>]]></description>
            <dc:creator>Ambush Commander</dc:creator>
            <category>Support</category>
            <pubDate>Thu, 15 Mar 2012 23:47:54 -0400</pubDate>
        </item>
        <item>
            <guid>http://htmlpurifier.org/phorum/read.php?3,6182,6267#msg-6267</guid>
            <title>Re: Problem with HTML.TargetBlank and HTML.Nofollow</title>
            <link>http://htmlpurifier.org/phorum/read.php?3,6182,6267#msg-6267</link>
            <description><![CDATA[<p>2) sorry, my mistake, patched library/HTMLPurifier/AttrTransform/TargetBlank.php works fine!</p>

<p>1) not working, what I do wrong? :(</p>]]></description>
            <dc:creator>stelmik</dc:creator>
            <category>Support</category>
            <pubDate>Wed, 14 Mar 2012 17:08:50 -0400</pubDate>
        </item>
        <item>
            <guid>http://htmlpurifier.org/phorum/read.php?3,6182,6266#msg-6266</guid>
            <title>Re: Problem with HTML.TargetBlank and HTML.Nofollow</title>
            <link>http://htmlpurifier.org/phorum/read.php?3,6182,6266#msg-6266</link>
            <description><![CDATA[<p>My correction:</p>

<p>2)
I patched library/HTMLPurifier/AttrTransform/TargetBlank.php and I replaced "blank" with "_blank" (2 occure: one inside a comment and one inside a code), but it doesn't change the result.</p>]]></description>
            <dc:creator>stelmik</dc:creator>
            <category>Support</category>
            <pubDate>Wed, 14 Mar 2012 17:00:56 -0400</pubDate>
        </item>
        <item>
            <guid>http://htmlpurifier.org/phorum/read.php?3,6182,6265#msg-6265</guid>
            <title>Re: Problem with HTML.TargetBlank and HTML.Nofollow</title>
            <link>http://htmlpurifier.org/phorum/read.php?3,6182,6265#msg-6265</link>
            <description><![CDATA[<p>I think I understand everything.</p>

<p>As you explain I change my code to:</p>

<pre>
&lt;?php
include_once 'library/HTMLPurifier.auto.php';
$config = HTMLPurifier_Config::createDefault();
	$config-&gt;set('Core.Encoding', 'UTF-8');
	$config-&gt;set('HTML.Doctype', 'XHTML 1.0 Transitional');
	$config-&gt;set('AutoFormat.AutoParagraph', true);
	$config-&gt;set('URI.Host', $_SERVER['HTTP_HOST']);
	$config-&gt;set('HTML.AllowedElements', array('a','b','strong','i','em','u'));
	$config-&gt;set('HTML.AllowedAttributes', array('a.href', 'img.src', '*.alt', '*.title', '*.border', '*.align', '*.width', '*.height', 'img.vspace', 'img.hspace', 'a.target', 'a.rel'));
	$config-&gt;set('AutoFormat.RemoveEmpty.RemoveNbsp', true);
	$config-&gt;set('AutoFormat.RemoveEmpty', true);
	$config-&gt;set('AutoFormat.RemoveSpansWithoutAttributes', true);
	$config-&gt;set('Core.RemoveProcessingInstructions', true);
	$config-&gt;set('HTML.TargetBlank', true);
	$config-&gt;set('HTML.Nofollow', true);
	$config-&gt;set('HTML.TidyLevel', 'heavy');
$purifier = new HTMLPurifier($config);
echo $purifier-&gt;purify('&lt;a href="<a href="http://www.google.com/">http://www.google.com/</a>"&gt;test page&lt;/a&gt;');
?&gt;
</pre>

<p>And the result is:</p>

<p>1)
</p>

<pre>
&lt;a href="<a href="http://www.google.com/">http://www.google.com/</a>" target="blank"&gt;test page&lt;/a&gt;
</pre>

<p>But in my opinion should:</p>

<pre>
&lt;a href="<a href="http://www.google.com/">http://www.google.com/</a>" rel="nofollow" target="_blank"&gt;test page&lt;/a&gt;
</pre>

<p>As you can see no "rel" attribute was added.</p>

<p>2)
I patched library/HTMLPurifier/AttrTransform/TargetBlank.php and I replaced "blank" with "_blank" (1 occure), but it doesn't change the result.</p>

<p>I use "HTML Purifier 4.4.0".</p>]]></description>
            <dc:creator>stelmik</dc:creator>
            <category>Support</category>
            <pubDate>Wed, 14 Mar 2012 16:53:37 -0400</pubDate>
        </item>
        <item>
            <guid>http://htmlpurifier.org/phorum/read.php?3,6182,6238#msg-6238</guid>
            <title>Re: Problem with HTML.TargetBlank and HTML.Nofollow</title>
            <link>http://htmlpurifier.org/phorum/read.php?3,6182,6238#msg-6238</link>
            <description><![CDATA[<p>Thank you for your help :)</p>]]></description>
            <dc:creator>stelmik</dc:creator>
            <category>Support</category>
            <pubDate>Mon, 05 Mar 2012 17:34:38 -0500</pubDate>
        </item>
        <item>
            <guid>http://htmlpurifier.org/phorum/read.php?3,6182,6217#msg-6217</guid>
            <title>Re: Problem with HTML.TargetBlank and HTML.Nofollow</title>
            <link>http://htmlpurifier.org/phorum/read.php?3,6182,6217#msg-6217</link>
            <description><![CDATA[<p>Aw, that's embarrassing. target="blank" rather than target="_blank" is a bug. You can fix it by patching library/HTMLPurifier/AttrTransform/TargetBlank.php looking for "blank" and replacing it with "_blank". This should be fixed in the next version.</p>

<p>As for rel, this is probably a bad interaction between Allowed and AllowedAttributes. If you follow pinkgothic's advice that should clear this up.</p>]]></description>
            <dc:creator>Ambush Commander</dc:creator>
            <category>Support</category>
            <pubDate>Sat, 18 Feb 2012 11:30:07 -0500</pubDate>
        </item>
        <item>
            <guid>http://htmlpurifier.org/phorum/read.php?3,6182,6211#msg-6211</guid>
            <title>Re: Problem with HTML.TargetBlank and HTML.Nofollow</title>
            <link>http://htmlpurifier.org/phorum/read.php?3,6182,6211#msg-6211</link>
            <description><![CDATA[<blockquote cite="stelmik">
<p>And this code isn't work as I would like to. :-(</p>
</blockquote>

<p>Without knowing specifically if this is your problem, you seem to have some misconceptions about some of the configuration values. Allow me to explain:</p>

<p><strong>1)</strong></p>

<blockquote cite="stelmik">
<pre>
	$config-&gt;set('HTML.Allowed', 'a,b,strong,i,em,u');
	$config-&gt;set('HTML.AllowedAttributes', '*.href,*.src,*.alt,*.border,*.align,*.width,*.height,*.vspace,*.hspace,*.target,*.rel,*.style');
</pre>
</blockquote>

<p>You either want to use <tt>HTML.AllowedElements</tt> and <tt>HTML.AllowedAttributes</tt> or <em>only</em> <tt>HTML.Allowed</tt>. From <a href="http://htmlpurifier.org/live/configdoc/plain.html#HTML.Allowed">the <tt>HTML.Allowed</tt> doc</a>:</p>

<blockquote><em>This is a preferred convenience directive that <strong>combines <a href="/live/configdoc/plain.html#HTML.AllowedElements">%HTML.AllowedElements</a> and <a href="/live/configdoc/plain.html#HTML.AllowedAttributes">%HTML.AllowedAttributes</a></strong>.</em></blockquote>

<p><strong>2)</strong></p>

<blockquote cite="stelmik">
<pre>
	$config-&gt;set('HTML.ForbiddenAttributes', '*@action,*@background,*@codebase,*@dynsrc,*@lowsrc,*@class,*@on*');
</pre>
</blockquote>

<p>From <a href="http://htmlpurifier.org/live/configdoc/plain.html#HTML.ForbiddenAttributes">the <tt>HTML.ForbiddenAttributes</tt> doc</a>:</p>

<blockquote><em><strong>Warning:</strong> This directive complements <a href="http://htmlpurifier.org/live/configdoc/plain.html#HTML.ForbiddenElements">%HTML.ForbiddenElements</a>, accordingly, check out that directive for a discussion of why you should think twice before using this directive.</em></blockquote>

<p>From the <tt>HTML.ForbiddenElements</tt> doc:</p>

<blockquote><em>This is the logical inverse of <a href="/live/configdoc/plain.html#HTML.AllowedElements">%HTML.AllowedElements</a>, <strong>and it will override that directive, or any other directive</strong>.</em></blockquote>

<p><strong>Conclusion</strong></p>

<p>In short: You want <em>either</em> (<tt>HTML.ForbiddenAttributes</tt>) <em>or</em> (<tt>HTML.AllowedAttributes</tt> and <tt>HTML.AllowedElements</tt>) <em>or</em> (<tt>HTML.Allowed</tt>).</p>

<p>If you fix that, your problem will probably go away.</p>

<p>(Edit: Fixed formatting after an HTML escaping glitch on the forum.)</p>

<p>Edited 1 time(s). Last edit at 07/30/2012 01:49PM by pinkgothic.</p>]]></description>
            <dc:creator>pinkgothic</dc:creator>
            <category>Support</category>
            <pubDate>Fri, 17 Feb 2012 04:47:56 -0500</pubDate>
        </item>
        <item>
            <guid>http://htmlpurifier.org/phorum/read.php?3,6182,6185#msg-6185</guid>
            <title>Re: Problem with HTML.TargetBlank and HTML.Nofollow</title>
            <link>http://htmlpurifier.org/phorum/read.php?3,6182,6185#msg-6185</link>
            <description><![CDATA[<p>Sorry. You have right!</p>

<p>The real full code is:</p>

<pre>
&lt;?php
include_once 'library/HTMLPurifier.auto.php';
$config = HTMLPurifier_Config::createDefault();
	$config-&gt;set('Core.Encoding', 'UTF-8');
	$config-&gt;set('HTML.Doctype', 'XHTML 1.0 Transitional');
	$config-&gt;set('AutoFormat.AutoParagraph', true);
	$config-&gt;set('URI.Host', $_SERVER['HTTP_HOST']);
	$config-&gt;set('HTML.Allowed', 'a,b,strong,i,em,u');
	$config-&gt;set('AutoFormat.RemoveEmpty.RemoveNbsp', true);
	$config-&gt;set('AutoFormat.RemoveEmpty', true);
	$config-&gt;set('AutoFormat.RemoveSpansWithoutAttributes', true);
	$config-&gt;set('Core.RemoveProcessingInstructions', true);
	$config-&gt;set('HTML.AllowedAttributes', '*.href,*.src,*.alt,*.border,*.align,*.width,*.height,*.vspace,*.hspace,*.target,*.rel,*.style');
	$config-&gt;set('HTML.ForbiddenAttributes', '*@action,*@background,*@codebase,*@dynsrc,*@lowsrc,*@class,*@on*');
	$config-&gt;set('HTML.TargetBlank', true);
	$config-&gt;set('HTML.Nofollow', true);
	$config-&gt;set('HTML.TidyLevel', 'heavy');
$purifier = new HTMLPurifier($config);
echo $purifier-&gt;purify('&lt;a href="<a href="http://www.google.com/">http://www.google.com/</a>"&gt;test page&lt;/a&gt;');
?&gt;
</pre>

<p>And this code isn't work as I would like to. :-(</p>

<p>I tried to include standalone version:</p>

<pre>
include_once 'library/HTMLPurifier.standalone.php';
</pre>

<p>But there is the same result. :-(</p>

<p>The result is:</p>

<pre>
&lt;a href="<a href="http://www.google.com/">http://www.google.com/</a>" target="blank"&gt;test page&lt;/a&gt;
</pre>

<p>What is wrong?
1. there is "blank", but should be "_blank".
2. no "rel" attribute with "nofollow" value, but should be.</p>]]></description>
            <dc:creator>stelmik</dc:creator>
            <category>Support</category>
            <pubDate>Fri, 03 Feb 2012 07:25:35 -0500</pubDate>
        </item>
        <item>
            <guid>http://htmlpurifier.org/phorum/read.php?3,6182,6183#msg-6183</guid>
            <title>Re: Problem with HTML.TargetBlank and HTML.Nofollow</title>
            <link>http://htmlpurifier.org/phorum/read.php?3,6182,6183#msg-6183</link>
            <description><![CDATA[<p>I don't believe you.</p>

<pre>ezyang@javelin:~/Dev/htmlpurifier$ cat &gt; foo.php
&lt;?php
include_once 'library/HTMLPurifier.auto.php';
$config = HTMLPurifier_Config::createDefault();
	$config-&gt;set('HTML.Nofollow', true);
	$config-&gt;set('HTML.TargetBlank', true);
	$config-&gt;set('HTML.Allowed', 'a,b,strong,i,em,u');
$purifier = new HTMLPurifier($config);
echo $purifier-&gt;purify('&lt;a href="<a href="http://www.google.com/">http://www.google.com/</a>"&gt;test page&lt;/a&gt;');
?&gt;
ezyang@javelin:~/Dev/htmlpurifier$ php foo.php 
&lt;a&gt;test page&lt;/a&gt;</pre>

<p>I don't think you're telling me the whole story here, so I can't debug your problem. (At a guess, the problem is that you're not allow href as an attribute.)</p>]]></description>
            <dc:creator>Ambush Commander</dc:creator>
            <category>Support</category>
            <pubDate>Thu, 02 Feb 2012 20:22:33 -0500</pubDate>
        </item>
    </channel>
</rss>
