I'm hoping someone out there has a good solution to a nagging problem I'm having with the codefilter module. I've already solved my first problem: that the codefilter css does not preserve the white space. I fixed that by modifying the codefilter.css file. Here is what my css looks like now:

div.codeblock {
  margin-top: 10px;
  margin-bottom: 10px;
  padding: 4px 4px 4px 4px;
  border: 1px solid #CCC;
  background-color: #EEE;
  font: normal 12px "courier new", courier, monospace;
  white-space: pre;
}

I can see from the Preview of this post that the Drupal site has not addressed this white space issue either (the css code above is inside of "code" tags), as the indenting of the lines inside of the curly braces has been lost. You'll notice in the code itself that I've also fiddled with the margins a bit, and also set a monospace font (two things that I'd love to see added to the codefilter head). The white-space element at the end takes care of the preservation of the indenting. Here is a post on my site that shows the result of my CSS:

http://www.developerdotstar.com/community/node/132

However, one problem remains: the extra line breaks. Depending on when you are reading this (that is, depending on whether I've found some solution to this problem), if you check out the link I just pasted above you'll see that while the indenting is preserved, there is an extra line break after each line. Here is the actual HTML that shows up in the browser:

<p><div class="codeblock"><code>public editUser2 editUser(){<br />

        editUser2 nextPage = (editUser2)pageWithName("editUser2");<br />
        nextPage.setUser(user);<br />
        return nextPage;<br />
    }

I've put this code inside of "pre" tags, and again here in the Drupal site's Preview, I see extra line breaks being added. It's pretty clear that whatever is doing this auto line-breaking (something in the node module, perhaps?) really should be skipping this for text that is inside of "pre" or "code" tags. What I mean is, we should not have any of those "p" or "br" tags.

Does anyone have any ideas? It's kind of embarrassing on my software development-oriented blogging site that my bloggers don't really have a way to post code without either a) losing all the white space altogether or b) keeping the white space but getting a ton of extra blank lines. It seems to me that I've done all I can within the codefilter css itself, and the only way to get past this is to address the auto-line-breaking that is happening in some downstream code.

Thanks,
Daniel Read

Comments

tangent’s picture

I submitted a patch for the whitespace issue. See this issue for the patch. The line breaks you're talking about are created for php code blocks as far as I know.

daniel read’s picture

Hi Tangent,

I had already seen your patch before I started this thread. (I did a full search of the site before posting.) However, I missed a subtlety in your patch, and now that I've adjusted for it, it is working great with indentation preserved and no extra line breaks.

Before I saw your patch, I had already added the "white-space" element to my css, so when I saw your patch I figured I already had that covered. However, looking again, I see now that your patch actually adds another "code" class inside of the "codeblock" div, whereas my "white-space" element modified "codeblock" directly. I've adjusted my CSS like so and it now works great:

div.codeblock {
  margin-top: 10px;
  margin-bottom: 10px;
  padding: 4px 4px 4px 4px;
  border: 1px solid #CCC;
  background-color: #EEE;
  font: normal 12px "courier new", courier, monospace;
}

div.codeblock code {
  white-space: pre;
}

Here again is that post on my site, and you can now see that the code is formatted properly. Thanks, Tangent!

http://www.developerdotstar.com/community/node/132

Dan

---------------------------------------------------------------
developer.* - The Independent Magazine for Software Developers
http://www.developerdotstar.com

daniel read’s picture

I just stumbled into this old post of mine while troubleshooting a different codefilter issue. This PRE issue is not present anymore in 4.6, so the CSS changes listed above should be unnecessary. The problem I'm having now is that blank lines in the original text are eliminated such that the displayed code block has no blank lines. It appears that the code in codefilter_process_code is not preserving them.

Dan