trac

PHP MimeViewer for Trac

As John Herren pointed out in the comments to yesterday's post, my suggestion for PHP syntax coloring wasn't working for several versions of Trac.

After a little digging, it turned out that my CSS rules were based on the non-standard SilverCity highlighting output, rather than the newer and more common native PHP highlighting.

While reviewing the output from the native PHP highlighter, I noticed that Trac's manipulation of the output from highlight_string() isn't quite right. The way things are now, as of Trac 0.10rc1, an intended multi-line docblock only has the first "/**" highlighted as a comment ... the rest of the docblock is highlighted as default PHP (the code-lang class).

I've been clamoring for good PHP syntax coloring output in Trac for a long time. Rather than pass the buck and put this on the Trac team, I've released a little PHP-based shell script called php_mimeview.

With php_mimeview installed, simply update the [mimeviewer] config section of trac.ini in your Trac project to point php_path to the full path location of php_mimeview. With that script, plus these rules in your site_css.cs template file:

[source language=":css"]
.code-keyword { color: #007700; }
.code-lang { color: #0000BB; }
.code-comment { color: #FF8000; }
.code-string { color: #DD0000; }
[/source]

... you'll get what you're probably used to seeing in syntax-highlighted PHP code.

Thanks to John Herren for the nudge to investigate this further.

Quickie Trac Notes

Two quick notes for Trac users out there:

  • I banged out all 33 lines of my first Trac plugin last night. The FlexJsPlugin allows Trac users to add JavaScript to the <head> block of their Trac-powered sites without needing to hack ClearSilver templates.
  • For PHP source files to display in the Trac Browser with default PHP syntax highlighting colors, use this:
    /* trac php syntax highlighting */
    .code-block {
        line-height: 1em;
        font-family: Courier, monotype;
        font-size: 12px;
        }
    .h_question { color: #0000BB; } /* highlight.default */
    .hphp_commentline { color: #FF8000; } /* highlight.comment */
    .hphp_operator { color: #007700; } /* highlight.keyword */
    .hphp_word { color: #007700; } /* highlight.keyword */
    .hphp_default {}
    .hphp_variable { color: #0000BB; } /* highlight.default */
    .hphp_hstring { color: #DD0000; } /* highlight.string */
    .hphp_simplestring { color: #DD0000; } /* highlight.string */
    .h_tagunknown {}
    .h_default {}
    

Drop the CSS in your project's site_css.cs file and you'll feel a little less like a stranger in a strange land. And while I haven't started playing too much with what some easily customizable JavaScript can bring to a Trac project, I'm looking forward to experimenting. Trac is great, but for all its coolness, it's lacking a bit in the area of today's JavaScript coolness.