version info: codefilter.module,v 1.10.2.2 2005/04/23 02:40:04

Because the text in comments are being outputed with HTML tags around it my web pages with the PHP code blocks were not validating as XHTML Transitional. The codefilter div tags were being returned surrounded by p tags, which the W3C validator doesn't like.

I was able to workaround this by changing the div tags on lines 47 and 82 of the codefilter.module (PHP related outputs) to span tags and then modifying the CSS to turn the span into block elements. Here's what the changed lines look like now:

47: return '<span class="codeblock">'. highlight_string("<?php\n$text\n?>", 1) .'</span>';
82: if ($multiline) $text = '<span class="codeblock">'. $text .'</span>';

Then I changed the div to span and added display:block; in the CSS:
span.codeblock {
display: block;
padding: 15px;
border: 1px solid #CCC;
background-color: #EEE;
}

The page validated after this and I haven't noticed any other adverse affects.

Hope this helps.

CommentFileSizeAuthor
#14 line_break.patch1.15 KBIsland Usurper

Comments

deekayen’s picture

-1, span breaks my code blocks in firefox, but I did verify the sequence <p><div class... does not validate.

Stuart Greenfield’s picture

I found this too, with codefilter.module,v 1.10.2.5 2006/03/28 02:42:55. To work around I added these two lines after line 111

      $text = preg_replace('@<p><div class="codeblock">@&#039;,&#039;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&#039;,$text);&#10;      $text = preg_replace(&#039;@</div></p>@','</code></div>',$text);

So it strips the offending

and

before returning the string. Not very elegant but code then passes validation.

Stuart Greenfield’s picture

That didn't look quite right!

$text = preg_replace('@&lt;p&gt;&lt;div class="codeblock"&gt;&lt;code&gt;@','&lt;div class="codeblock"&gt;&lt;code&gt;',$text);
$text = preg_replace('@&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;@','&lt;/code&gt;&lt;/div&gt;',$text);
deekayen’s picture

That still doesn't look right. Could you put it in a txt file and attach it?

johnalbin’s picture

Status: Active » Postponed (maintainer needs more info)

The code has changed since this issue was last updated. Does this problem still exist?

wim leers’s picture

Version: 4.6.x-1.x-dev » 5.x-1.x-dev
Status: Postponed (maintainer needs more info) » Active

I can confirm that the problem still exists. Example: http://wimleers.com/blog/textmate-command-look-functions-api.drupal.org.

wim leers’s picture

Title: Output for PHP related code is not valid XHTML Transitional, but I think I have fix... » Invalid XHTML output
wim leers’s picture

Category: bug » support
Status: Active » Fixed

Ok this is not a bug.

In your input format, you have to move the code filter *before* the line break converter, if you're using it. People who don't use the line break converter in their input format(s), should not experience this issue.

johnalbin’s picture

I’ve added this to the INSTALL.txt doc. Thanks for finding the fix!

johnalbin’s picture

FYI, I just added an issue about the input filtering order on d.o.

http://drupal.org/node/198179

wim leers’s picture

Wow, I wasn't aware this problem existed here on Drupal.org as well! :D Nice catch :)

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

johnalbin’s picture

Title: Invalid XHTML output » Conflict with Link Break converter causes invalid XHTML output
Category: support » bug
Status: Closed (fixed) » Active

I’ve been playing around with input ordering until my eyes bug out. Any ordering dependency that we can get rid of is a good thing.

If codefilter wraps its code blocks in its own <p> tags during the 'prepare' stage of input filtering, than Line Break Converter won't wrap one around it. Then we can strip the <p> off during 'process'.

Island Usurper’s picture

Version: 5.x-1.x-dev » 6.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new1.15 KB

I had a hard time getting that to work until I remembered the line breaks just inside the <p> tags.

I can confirm that enabling Code filter on a format automatically puts it at weight 10, so this should help keep people's content up to standards.

avpaderno’s picture

If the module surrounds the code with <div> tags, then you cannot put <p> tags around that.

Island Usurper’s picture

True, but like John suggested, it's taking out the <p> tags in the process step with the preg_replace().

cameron tod’s picture

Status: Needs review » Closed (works as designed)

Closing as part of issue queue cleanup. Feel free to reopen.