|
Adding <b> and <i> to Tidy November 18, 2008 06:07PM |
Registered: 5 years ago Posts: 5 |
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 |
Admin Registered: 6 years ago Posts: 2,632 |
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 |
Registered: 2 years ago Posts: 3 |
|
Re: Adding <b> and <i> to Tidy May 26, 2010 02:07PM |
Admin Registered: 6 years ago Posts: 2,632 |