Hi, I am using Custom filters module and I need to place my own code after first end of paragraph. How can I do this using Custom Filters?

I have </p> in pattern and in replacement text i have this:

$result = '</p>';
$result .= '<!-- info -->';
return $result;

However that doesn't seem to work. It replace every occurrence of paragraph end. The bigger problem is that it seems to be placed into another < and >. :-(

Comments

maxiorel’s picture

anyone has an advice for me please?

Jan Polzer, Drupal & Symfony developer

papile’s picture

I never used the custom filters module. A question like this may be best answered in the "I installed drupal, how do I.." forum. This forum is for people coding their own modules.

maxiorel’s picture

OK, sorry for my bad choose.

Jan Polzer, Drupal & Symfony developer

arhip’s picture

Hi, maxiorel,

The key is, there should be a mechanism to record the first paragraph detected, and to replace matched string only when it is the first detected paragraph. An example might be like this:

// If $vars->firstp not set, this is the first paragraph
if (! $vars->firstp) {
  $vars->firstp = 1;

  return '<!-- info -->';
}
// If set, this is another paragraph
else
  return '</p>';

The pattern cannot just a plain </p>, but we should enclose it with (..) or <..> like this: (</p>).

Hope it helps.

maxiorel’s picture

Thank you very much! This works excellent.

Jan Polzer, Drupal & Symfony developer

federico’s picture

First <p> replacement solution by arhip works well.

Is it possible to replace <!--break-->? Or print something after <!--break--> on node view?

Thanks.

Federico