Welcome! » Log In » Create A New Profile

Adding <b> and <i> to Tidy

Posted by Iquito 
Adding <b> and <i> to Tidy
November 18, 2008 06:07PM

I wanted users in a forum of mine to be able to use <b> and <i>, yet they should be converted to <strong> and <em> and I therefore did not want to allow <b> and <i>, they should only be converted.

I added the lines

$r['b'] = new HTMLPurifier_TagTransform_Simple('strong');
$r['i'] = new HTMLPurifier_TagTransform_Simple('em');

into XHTMLAndHTML4.php in the Tidy HTMLModule, and in my script through

$config->set('HTML', 'TidyAdd', 'b');
$config->set('HTML', 'TidyAdd', 'i');

these additional Tidy rules are enforced - which works fine.

I wanted to suggest to maybe add these rules as optional (only gets used if specifically chosen through TidyAdd) to Tidy, also a few other HTML tags like <big> or <small> could be added to help replace tags which should better not be used nowadays, although <b> and <i> are by far the most commonly still used (especially by users). These tags are not deprecated, that's why it should only be optional, or it could also be an own module independent of Tidy.

If something like this already exists than I apologize for bringing it up (and would be glad to hear where to find it) - I just thought it would be great to have this feature included without having to edit the library itself :-) And I did not know of any other way to easily convert one tag to another with HTMLPurifier (which is probably also not a common use case).

Re: Adding <b> and <i> to Tidy
November 18, 2008 08:28PM

It is possible to add tag transform rules without editing code:

$config->set('HTML', 'DefinitionID', 'extra-transforms');
$config->set('HTML', 'DefinitionRev', 1);
$def = $config->getHTMLDefinition(true);
$def->info_tag_transform['b'] = new HTMLPurifier_TagTransform_Simple('strong');
$def->info_tag_transform['i'] = new HTMLPurifier_TagTransform_Simple('em');

As for something built-in, it might be a good idea. Would you be interested? ;-)

Re: Adding <b> and <i> to Tidy
May 26, 2010 01:39PM

I disagree that <i> should not be used. It does not have at all the same meaning as <em>. There are plenty of grammatical reasons for wanting italics which have nothing to do with emphasis.

TRiG.

Re: Adding <b> and <i> to Tidy
May 26, 2010 02:07PM

It certainly wouldn't be built in by default.

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: