With help from some members on the SitePoint forums, I've modified the serendipity_event_plugin_nl2br to work with HTML textarea, pre, and the BBCode GeSHi modifiers so that those ugly <br /> tags aren't added when they aren't wanted.
Here's what I did:
- Open up plugins\serendipity_event_nl2br\serendipity_event_nl2br.php in your serendipity folder
- add two new functions (within the class, but order of where they go is unimportant, I placed them before the event_hook function) as shown below:
Code: Select all
function isolate($src, $regexp = NULL)
if($regexp) return preg_replace_callback($regexp, array($this, 'isolate'), $src);
$_buf = $src;
return "\001" . (count($_buf) - 1);
return preg_replace('~\001(\d+)~e', '$_buf[$1]', $text);
- find the following line in the event_hook function: <strong><code>$eventData[$element] = nl2br($eventData[$element]);</code></strong> and replace it with the following:
Code: Select all
$eventData[$element] = $this->isolate($eventData[$element], '~[<\(textarea|pre|geshi).*?[>\]].*?[<\/\1[>\]]~si');
$eventData[$element] = nl2br($eventData[$element]);
$eventData[$element] = $this->restore($eventData[$element]);
What I'd like to do is to allow for users to modify the tags that would be used within the REGEXP (I know, I'd have to modify the regex, not a problem) by using a plugin administration page...this way, if a plugin that I'm not aware of yet is created that would benefit from this, a user (or possibly even the plugin itself) could modify the tags that are skipped from the nl2br PHP call.
This modified version should not effect anyone using the rich text editor, but will help those trying to use GeSHi or other code-posting methods. I would strongly suggest applying this to the current nl2br plugin, and/or replacing it and giving it a different name (nl2br_enhanced).