Opened 8 years ago

Closed 8 years ago

# php code does not seem to get highlighted

Reported by: Owned by: izzy Chris Heller normal IncludeSourcePartialPlugin normal 0.11

### Description

While e.g. Python code is highlighted ([[IncludeSource(file.py, start=30, end=38, rev=1)]]), PHP code seems to be handled like a simple plain text file - even if the mime type is explicitly specified. If including the entire file, it works - but as soon as there's no "<?php" string found in the quoted part, there's no highlighting. Could there be anything done about that?

### comment:1 Changed 8 years ago by Chris Heller

Status: new → assigned

The macro just uses the mimeview code under the covers, so whatever it is invoking to render the php code is the likely issue.

I see that there is a mimeview/php.py file in Trac that uses the php executable for doing php highlighting. I don't know if that gets used in preference to something like Pygments though. Can you see if that is being used in your install? (the path to the php executable is set in the trac.ini file).

If so, try temporarily disabling that and see if pygments handles this properly.

### comment:2 Changed 8 years ago by Chris Heller

The other thing that might be possible is a bit of hack, but it might work. The plugin could be modified to check that php source actually begins with whatever string the renderer is looking for in order to make it happy.

### comment:3 Changed 8 years ago by Chris Heller

I finally did a little experiment with this last night. Adding

#!/usr/bin/php -f
<?


to the beginning of the source when the beginning is trimmed off did do the trick for getting the syntax highlighting back on.

Here's the diff if you want to experiment further.

• ## IncludeSource.py

 start, end = kwargs.get('start', None), kwargs.get('end', None) if start or end: src, start, end = self._handle_partial(src, start, end) # fix up php - if there's no leading shebang line, then render # does not identify it properly if file_name.endswith('.php'): src = '#!/usr/bin/php -f\n

The main issue with this is that the two added lines needed to get the rendering are included in the output. I think that a Genshi transformation could strip these two lines back out from the render() output, but I didn't have time to look at that.

Once that works, then this can be cleaned up a bit (e.g. handle other php extensions, etc.) and put into the plugin code.

### comment:4 Changed 8 years ago by Chris Heller

Resolution: → fixed assigned → closed

Fixed this in changeset:5481 by prepending php lead-in and then stripping the lead-in back out. Not the most efficient way of doing things, but it does the job.

It's also setup that adding other types of files that need this sort of "trick the renderer" behavior can be added relatively easily.

### Modify Ticket

Action
as closed The owner will remain Chris Heller.
The resolution will be deleted. Next status will be 'reopened'.