In a setup where codefilter processes before linebreak filter, if linebreak filter finds multiple newlines, it inserts a <p> tag (nested inside the <code> tags), causing a discontinuation in style (because <p> tag might have it's own styling).

For example

#include <stdio.h>
                                <!--if this line is blank, linebreak will add a <p> here-->
int main(void)
{
    printf("Hello world!");
    return 0;
}

We don't want linebreak to insert anything inside the <code> tags. And we don't want to put linebreak before codefilter because of the invalid XHTML problem.

I'm suggesting a fix. Patch attached (see comment in patch).

Comments

geerlingguy’s picture

I'm having the same problem on a bunch of my sites; when I have code, then a blank line, then more code, a pair of <p> </p> tags is inserted where the blank line was because of the 'Convert line breaks into HTML (i.e. <br> and <p>)' filter.

I tried simply applying the patch to the Drupal 7 version, and also changing the code in codefilter_process_php(), but that didn't work for me. It seems that the newlines are being changed elsewhere.

Here's a sample of code (as it looks on Drupal.org), with a screenshot of how it looks with the current D7 release attached:

/**
  * This comment should have a space on the 2nd/3rd lines.
  */
function test_function() {
  // This line is normal, it has no empty lines before it.

  // This line has spacing problems because there's a blank line before it.
  // This line appears normal again, as it has no empty lines before it.
}

(Go figure, everything looks normal on drupal.org...).

geerlingguy’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Needs review » Needs work
StatusFileSize
new18.77 KB

Forgot to attach screenshot with spacing issues...

geerlingguy’s picture

Well, after a bit more experimentation (after seeing that Drupal.org's filter order is different than mine), I found that if I put the Code Filter filter last, after both the HTML cleanup and the Convert linebreaks filters, everything looks correct. Maybe we can mark this issue fixed?

This could definitely use more documentation (the current project page documentation link goes to a CVS file viewer, which doesn't work anymore). Opened #1488276: Update project page Documentation link for that...

cameron tod’s picture

Status: Needs work » Fixed

This is covered in the handbook page as mentioned in #3, but feel free to clarify any documentation over there or reopen this if you think that the present docs are inadequate.

Status: Fixed » Closed (fixed)

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