Syntax highlighting
beginner - December 4, 2008 - 04:22
| Project: | Advanced help |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs work |
Description
Would it be easy to get support for php syntax highlighting?
Can the module work with codefilter module?
Here are two examples from the date.module.
In this advanced help page, the code highlighting is hard coded into the html:
http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/date/help/d...
In this one, a full block of php code is placed within <pre> tags, without any highlighting. Using <code> tags do not work:
http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/date/help/f...

#1
The advanced help output can be altered:
<?phpdrupal_alter('advanced_help_topic', $output, $popup);
?>
So if the maintainer won't implement it, at least we can create a little module which would filter the output with codefilter for automatic syntax highlighting. I haven't tried yet, but it looks fairly easy after all.
#2
I would really like code filter output, myself, but I was leery of doing it since it is an external module and we obviously don't want a dependency on it.
That said, I think maybe a setting that turns on codefilter filtering IF codefilter module is enabled is a good idea. That won't fly in core, probably, the codefilter could use drupal_alter for that version. For contrib, though, I'm willing to make codefilter not do the dirty work unless the maintainer wants to do it.
Patches considered.
#3
There is the additional problem that codefilter uses the
<code>tags.The php block in the example above uses
<pre>tags.<code>tags without codefilter just won't do.<pre>tags with codefilter won't do either.Hmmm... I guess the module would have to use both sets of tags, so that it works both with and without codefilter.
#4
In theory we could apply .css to the code tag so that it works properly. I didn't try very hard to do it, though.
#5
I tested a bit using the date.module (?q=help/date_api/form-elements) and the attached patch.
It doesn't work without patching date.module because the html contains
<?php ... ?>and not<?php ... ?>.If I patch date.module so that it has the proper php tags, codefilter works, but then without it the page is unreadable!
#6
This patch is a bit of a hack, but it works without patching date.module.
Since the help pages are supposed to be only html, it should be ok to check for php code this way and replace the html tags into real php tags to be filtered.
#7
I noticed Karen of this thread:
#343072: syntax highlighting for advanced help.