1

Topic: convert <b> to <strong>

thanks for this great resource

is there an easy way to convert <b> to <strong> and <i> to <em>?

or would i need to write a custom hook function? and if so, are there any snippets existing for what i'm looking for?

cheers!

2

Re: convert <b> to <strong>

No, there is no configuraton setting for that, but I will keep this in mind as a possible new feature of htmLawed.

I think the following code will work:

// First, run htmLawed
$out = htmLawed($in, ...);
// Replace closing b and i tags
$out = str_replace(array('</b>', '</i>'), array('</strong>', '</em>'), $out);
// Replace opening b and i tags
$out = preg_replace(array('`(<b)([^\w])`i', '`(<i)([^\w])`i'), array("<strong$2", "<em$2"), $out);

3

Re: convert <b> to <strong>

Thanks.. so I'm new to this and also using htmlLawed within drupal - where would this code go?

I guess there are 2 questions:
1. do I create a function and set "hook_tag" or "hook"?
2. where should this code literally go.. within the drupal module somewhere?

thank you!

patnaik wrote:

No, there is no configuraton setting for that, but I will keep this in mind as a possible new feature of htmLawed.

I think the following code will work:

// First, run htmLawed
$out = htmLawed($in, ...);
// Replace closing b and i tags
$out = str_replace(array('</b>', '</i>'), array('</strong>', '</em>'), $out);
// Replace opening b and i tags
$out = preg_replace(array('`(<b)([^\w])`i', '`(<i)([^\w])`i'), array("<strong$2", "<em$2"), $out);

4

Re: convert <b> to <strong>

Best would be to edit the htmLawed function in the htmLawed.php file within the Drupal htmLawed module folder. The function is at the top, and you'd edit just before it's closing so it looks like:

...
if(isset($reS)){$GLOBALS['S'] = $reS;}
// My modification to replace b and i with strong and em (24 Mar'10)
$t = preg_replace(array('`(<b)([^\w])`i', '`(<i)([^\w])`i'), array("<strong$2", "<em$2"), str_replace(array('</b>', '</i>'), array('</strong>', '</em>'), $t));
return $t;
// eof
}
...

5

Re: convert <b> to <strong>

brilliant - worked perfectly .. thanks so much!