Welcome! » Log In » Create A New Profile

Can I keep the name attribute without having id's?

Posted by joelguesclin 
Can I keep the name attribute without having id's?
November 09, 2016 07:00PM

I have some rather old HTML which was generated using something like CKeditor (it was probably TinyMCE or maybe even something older). The text (held in a database) makes extensive use of footnotes: long articles with references to footnotes that appear at the bottom. For some reason the 'a' tags have the 'name' attribute, but not the 'id' attribute, so that a reference from a footnote reference number back to the footnote looks like this:

<a href="/ri/054_decadence_part04.html#_ftnref2" name="_ftn2">[2]</a>

The footnote itself, in the text, is the same but the other way round. So, although I have set up the configuration like this:

    $config->set(&#039;Attr.EnableID&#039;, true);
    $config->set(&#039;HTML.Allowed&#039;, &#039;p,b,a[href][name],img[src][alt]&#039;);

The "name" still gets removed. Is there any way round this?

Re: Can I keep the name attribute without having id's?
November 10, 2016 12:37AM

Your %HTML.Allowed syntax is not correct; use a pipe to separate values.

Re: Can I keep the name attribute without having id's?
November 10, 2016 02:29AM

Thanks - so I tried it like this:

    $config->set(&#039;Attr.EnableID&#039;, true);
    $config->set(&#039;HTML.Allowed&#039;, &#039;p,b,a[href|name],img[src|alt]&#039;);

But the "name" still gets stripped out. Is there some way of putting in id's if there aren't any? I'm basing myself on this bit of the documentation by the way

Edited 1 time(s). Last edit at 11/10/2016 03:17AM by joelguesclin.

Re: Can I keep the name attribute without having id's?
November 10, 2016 10:06AM

Oh oops, the problem is that the id validator is rejecting names with leading underscore. Set %HTML.Attr.Name.UseCDATA to true.

Re: Can I keep the name attribute without having id's?
November 11, 2016 07:34AM

Cool, that works, thanks

Author:
Your Email:

Subject:

HTML input is enabled. Make sure you escape all HTML and angled brackets with &lt; and &gt;.

Auto-paragraphing is enabled. Double newlines will be converted to paragraphs; for single newlines, use the pre tag.

Allowed tags: a, abbr, acronym, b, blockquote, caption, cite, code, dd, del, dfn, div, dl, dt, em, i, ins, kbd, li, ol, p, pre, s, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, var.

For inputting literal code such as HTML and PHP for display, use CDATA tags to auto-escape your angled brackets, and pre to preserve newlines:

<pre><![CDATA[
Place code here
]]></pre>

Power users, you can hide this notice with:

.htmlpurifier-help {display:none;}

Message: