using RemoveEmpty? or other way to remove empty paragraphs (<p></p>)?

mattgilbert - May 29, 2009 - 14:20
Project:HTML Purifier
Version:6.x-1.0
Component:User interface
Category:support request
Priority:minor
Assigned:Unassigned
Status:closed
Description

Apparently HTML Purifier has a RemoveEmpty filter, which would be handy for removing empty paragraph tags. Is this accessible from this module? Are there other ways to remove empty paragraphs?

#1

ezyang - May 29, 2009 - 15:18
Status:active» fixed

You have a few choices.

One is to use the advanced configuration method, documented in the config/ directory of your modules. This would require no patching.

The other is to do a slight patch: open up htmlpurifier.module and go where it says $allowed = array(. Immediately below this line, add 'AutoFormat.RemoveEmpty'

For the future, I should probably change this to include all AutoFormat modules by default.

#2

mattgilbert - May 29, 2009 - 17:33

Thanks, the slight patch works perfectly for empty paragraphs.

Unfortunately, (different problem) it turns out that there's one non-breaking space in each empty paragraph. :(

#3

ezyang - May 29, 2009 - 17:43

There's a patch that fixes it; however, given the massive amount of changes to 4.0.0 it probably doesn't apply. If you're interested in running a bleeding edge version, check out: http://repo.or.cz/w/htmlpurifier.git?a=commit;h=e3c2063f69ff156bd05431f8...

#4

mattgilbert - May 29, 2009 - 19:02

Thanks! I'm using the trunk version now, and it does the trick. Looking forward to the next stable release.

#5

System Message - June 12, 2009 - 19:10
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

#6

mattgilbert - July 2, 2009 - 17:43

Well, the trunk version was working fine, but it did throw user notices that parts of the module were using a deprecated API. The notices all looked something like this:

user notice: Using deprecated API: use $config->set('AutoFormat.Linkify', ...) instead on line...

I made all the changes it suggested, and it seems to work fine still, but with no more user notices. Specifically I changed lines 186-199 of htmlpurifier.module, which originally said

  $config->set('AutoFormat', 'AutoParagraph', TRUE);
  $config->set('AutoFormat', 'Linkify', TRUE);
  $config->set('HTML', 'Doctype', 'XHTML 1.0 Transitional'); // Probably
  $config->set('Core', 'AggressivelyFixLt', TRUE);
  $config->set('Cache', 'DefinitionImpl', 'Drupal');
 
  // Filter HTML doesn't allow external images, so neither will we...
  // for now. This can be configured off.
  $config->set('URI', 'DisableExternalResources', TRUE);
 
  if (!empty($_SERVER['SERVER_NAME'])) {
    // SERVER_NAME is more reliable than HTTP_HOST
    $config->set('URI', 'Host', $_SERVER['SERVER_NAME']);
  }

to this:

$config->set('AutoFormat.AutoParagraph', TRUE);
  $config->set('AutoFormat.Linkify', TRUE);
  $config->set('HTML.Doctype', 'XHTML 1.0 Transitional'); // Probably
  $config->set('Core.AggressivelyFixLt', TRUE);
  $config->set('Cache.DefinitionImpl', 'Drupal');
 
  // Filter HTML doesn't allow external images, so neither will we...
  // for now. This can be configured off.
  $config->set('URI.DisableExternalResources', TRUE);
 
  if (!empty($_SERVER['SERVER_NAME'])) {
    // SERVER_NAME is more reliable than HTTP_HOST
    $config->set('URI.Host', $_SERVER['SERVER_NAME']);
  }

Pretty simple changes, but I thought this might be useful for anyone else wanting to use trunk, or perhaps the developer if he wanted to get the module using a later version.

#7

ezyang - July 2, 2009 - 17:47

Yeah, I need to cut a new branch for the Drupal extension and put in the config API changes. (Unfortunately, CVS is making me REALLY not want to have to deal with it.) Good to hear that the error messages were good enough to let you fix it. Can you file a bug for this separately?

#8

mattgilbert - July 3, 2009 - 15:51

Sure, here you go:
http://drupal.org/node/509468

 
 

Drupal is a registered trademark of Dries Buytaert.