문제

Syntax highlighting for PHP refuses to work on Wiki pages in my installation of Trac. It works beautifully when browsing source, but not in the Wiki. Javascript, C, and Python syntax highlighting work in the Wiki, but not PHP. Woe is me.

I have Trac 0.11.7 installed on Ubuntu 10.04. My web server is Apache 2.2.14.

I have manually installed Pygments. No luck. I have changed the Pygments Theme in preferences. No luck.

I have absolutely 0 errors logged in the trac and apache logs. Logging level for Trac is set to WARNING (and Trac logging is working - I have other errors from earlier today). Firebug also displays no error with everything turned on (except one unrelated "Unknown property '-moz-opacity'" CSS error).

Viewing the HTML source of the page shows that the code is simply spit out as preformatted text. It does not have the tons of <span>'s all other syntax-highlighted code blocks have.

This is the code I'm using in the Wiki:

{{{
#!php
if(true)
{
    echo 'hi';
}
}}}

And this is the result:

<div class="code"><pre><span class="x">if(true)
{
    echo 'hi';
}
</span></pre></div>

Please help :-)


For an example of what I would expect, here's some JS code that works:

{{{
#!js
if(true)
{
    alert('hi');
}
}}}

And this is the result:

<div class="code"><pre><span class="k">if</span><span class="p">(</span><span class="kc">true</span><span class="p">)</span>
<span class="p">{</span>
    <span class="nx">alert</span><span class="p">(</span><span class="s1">'hi'</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
도움이 되었습니까?

해결책

I believe you can resolve this by including the <?php tag:

{{{
#!php
<?php
if(true)
{
    echo 'hi';
}
}}}

That works for me on my Trac wiki, anyhow. I still haven't been able to determine if this is intended behavior or a bug, though.

다른 팁

Don't know why this always happens to me. Of course I figure it out 5 minutes after posting the question.

The problem was that I didn't have <?php ?> in the php source, so the syntax-highlighter was treating it like HTML; just like the PHP parser.

C, Python, and JS don't have an equivalent, so that's why they seemed to work when PHP didn't.

This code works:

{{{
#!php
<?php
if(true)
{
    echo 'hi';
}
?>
}}}

I'm leaving this question here in case anyone else has the same problem, despite how stupid I feel.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top