Conflict with Link Break converter causes invalid XHTML output

macunni - September 26, 2005 - 03:04
Project:Code Filter
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review
Description

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.

#1

deekayen - January 9, 2006 - 16:08

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

#2

Stuart Greenfield - April 7, 2006 - 23:11

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

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

So it strips the offending

and

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

#3

Stuart Greenfield - April 7, 2006 - 23:14

That didn't look quite right!

<?php
$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);
?>

#4

deekayen - April 9, 2006 - 17:05

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

#5

JohnAlbin - August 17, 2007 - 22:33
Status:active» postponed (maintainer needs more info)

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

#6

Wim Leers - December 1, 2007 - 23:24
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.

#7

Wim Leers - December 1, 2007 - 23:26
Title:Output for PHP related code is not valid XHTML Transitional, but I think I have fix...» Invalid XHTML output

#8

Wim Leers - December 1, 2007 - 23:55
Category:bug report» support request
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.

#9

JohnAlbin - December 4, 2007 - 21:59

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

#10

JohnAlbin - December 5, 2007 - 21:09

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

http://drupal.org/node/198179

#11

Wim Leers - December 5, 2007 - 21:48

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

#12

Anonymous - December 19, 2007 - 21:51
Status:fixed» closed

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

#13

JohnAlbin - January 14, 2008 - 03:27
Title:Invalid XHTML output» Conflict with Link Break converter causes invalid XHTML output
Category:support request» bug report
Status:closed» 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'.

#14

Island Usurper - June 15, 2009 - 22:02
Version:5.x-1.x-dev» 6.x-1.x-dev
Status:active» needs review

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.

AttachmentSize
line_break.patch 1.15 KB

#15

kiamlaluno - June 16, 2009 - 22:56

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

#16

Island Usurper - June 17, 2009 - 13:19

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

 
 

Drupal is a registered trademark of Dries Buytaert.