It would be great if the codefilter.module could preserve whitespace similar to how <pre> tags preserve whitespace. By not preserving whitespace, it removes any indentation in the code and makes it harder to read.

CommentFileSizeAuthor
#1 whitespace_0.patch441 bytestangent

Comments

tangent’s picture

StatusFileSize
new441 bytes

I mistakenly created a new issue for this and submitted a patch to it. I'll close the other issue. Here's the patch.

tangent’s picture

Category: feature » bug

This is a bug IMO.

Steven’s picture

I fixed this by making the filter preserve indentation by replacing it with &nbsp;. I also tweaked the trimming not to strip out leading whitespace in a code segment.

This is better than the pre because it still allows the code to wrap.

tangent’s picture

It is my opinion that wrapping code blocks should be avoided rather than intended. Code lines which wrap are often logically invalid. It would be better to allow them their content to scroll.

Steven’s picture

Pre blocks are a tricky situation in themes. Overflow: auto won't work without some hacks in more advanced CSS-based themes.

In any case, the wrapping would be visually only. If you copy/paste, it is copied without wrapping. When you read the code on a website, I think wrapping is acceptable and even desirable.

tangent’s picture

Steven wrote:

Pre blocks are a tricky situation in themes. Overflow: auto won't work without some hacks in more advanced CSS-based themes.

This is a problem with the theme and not the fault of the property. I've noticed problems in Bluebeach dealing with unwrappable content and I assume this is the reason you don't allow any PRE styles.

In any case, the wrapping would be visually only. If you copy/paste, it is copied without wrapping. When you read the code on a website, I think wrapping is acceptable and even desirable.

On my website I would prefer to use the white-space: pre style but having the filter add nbsp to the content would defeat this. Therefore I wouldn't upgrade to your new update.

mcd’s picture

I'm also using white-space: pre; instead of the filter stuff, but I ran into an issue of preserving whitespace in printer-friendly pages (e.g., for books), where codefilter.css isn't linked automatically. I'll probably just hardcode misc/print.css, but I thought I'd warn people about it.

Anonymous’s picture