Opened 16 years ago
Closed 16 years ago
#4346 closed defect (fixed)
php code does not seem to get highlighted
Reported by: | izzy | Owned by: | Chris Heller |
---|---|---|---|
Priority: | normal | Component: | IncludeSourcePartialPlugin |
Severity: | normal | Keywords: | |
Cc: | Trac Release: | 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?
Attachments (0)
Change History (4)
comment:1 Changed 16 years ago by
Status: | new → assigned |
---|
comment:2 Changed 16 years ago by
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 16 years ago by
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
151 151 start, end = kwargs.get('start', None), kwargs.get('end', None) 152 152 if start or end: 153 153 src, start, end = self._handle_partial(src, start, end) 154 155 # fix up php - if there's no leading shebang line, then render 156 # does not identify it properly 157 if file_name.endswith('.php'): 158 src = '#!/usr/bin/php -f\n<?\n' + src 159 154 160 context.startline = start 155 161 156 162 mimetype = kwargs.get('mimetype', None)
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 16 years ago by
Resolution: | → fixed |
---|---|
Status: | 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.
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.