Active
Project:
Code Filter
Version:
5.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
15 Jan 2008 at 00:05 UTC
Updated:
16 Mar 2009 at 09:27 UTC
The following text will cause codefilter to prematurely stop syntax highlighting:
<code>
<?php
print "Hello </code>";
?>
</code>
Here's a live example:
<?php
print "Hello ";
?>
As you can (currently) see, that definitely needs to get fixed.
In addition, an html snippet that includes <code> will also cause Code filter to stop syntax highlighting prematurely:
<code><p>This is a snippet of <code>html</code> that includes the code tag</p></code>
Live Example:
<p>This is a snippet of html that includes the <code>code element.
Comments
Comment #1
johnalbinIt's actually the </code> string that causes the error, not <code>.
Comment #2
zeta ζ commentedWhereas:
is OK.
It only fails if there is an unclosed
<code>outside the.Comment #3
nancydruAs I mentioned in the other post, I had this problem too, so I'm tracking it.
Comment #4
zeta ζ commentedExample #2a is not very useful, because any html should be outside the <?php ?>.
If the
code tagsare outside the <?php ?>, the whole lot needs another pair of embracingcode tags, which is when codefilter fails.Should we not also bear in mind the vast back catalogue of nodes that were written with the codefilter as it works now? Maybe we might need
for d.o.
Comment #5
nancydruI doubt that fixing this will break any existing nodes because people haven't been able to get it to work. Also bear in mind that codefilter is not used solely on DO - I have two sites that I use it on and neither one is in any danger of reaching 210,000 nodes in my lifetime.
Comment #6
zeta ζ commentedNancy: I wasn’t intending to put it in codefilter just .
Currently can’t get my testsite to put <?php ?> in
, so I’ll have to work on this.
Comment #7
soxofaan commentedThe solution/workaround we offer in GeSHi filter is to support both <code> and [code] as code block delimiters, so if you need <code> in a code block you write [code]...<code>...</code>...[/code]
Supporting all sorts of nesting corner cases will lead to a regular expression nightmare or the need for a parser, which isn't worth it IMHO.
Comment #8
nancydruI looked at the module and admit I don't understand preg-replace. Can you increment a depth counter every time you encounter the start tag and decrement when you encounter an ending tag and only quit when the depth is back to zero?
Comment #9
johnalbinNancy, unfortunately, you can't implement a depth counter because the code can just be snippet of code and there's no guarantee that it will be well-formed (with matching opening and closing tags.) See my first example for what I mean.
Stefaan's solution is not bad. But I'm testing another solution (which I'm not sure will work at this stage).
This issue is similar to: http://drupal.org/node/38047 ("?>" string prematurely stops syntax highlighting)
Comment #10
zeta ζ commentedAh yes… I was thinking of a depth counter (using a gargantuan regex) :-(
Comment #11
zeta ζ commentedI think soxofaan #7 is on the right track. Although I wouldn’t support both as such. Rather I would leave <code>...</code> as html tags and require a different pair of tags to invoke codefilter to do its work (eg. for this post [cf]). There would then be no reason to nest codefilter tags (unless you want to specify what to type to invoke codefilter, In which case we could handle the single exception of [cf][cf].*[/cf][/cf] ie. no need to handle partial quote).
I’m confident this will make codefilter much simpler and quicker: Although it is supposed to filter input, it does so at output time (and time again) as far as I understand, so could be the source of a performance hit if we handle too many edge cases.
Comment #12
corsix commentedAs #9 mentioned the "?>" premature closing issue, I feel it is pertinent to point out that the patch in that issue handles this edge case as well (see http://img174.imageshack.us/img174/7770/codefilterow7.png for an example).
Comment #13
nancydru@zeta-zoo: it's interesting that they have so much more to say about <pre>.
@corsix: I'm sure Mr. Albin is aware of that and considering it.
Comment #14
mr.baileysSubscribing. I was trying to show my users how to use the code filter by embedding <code>-tags inside another set of <code>-tags...
As an unfortunate side effect, nesting <code>-tags also seems to render the resulting document invalid XHTML because of an unmatched </code> tag.