Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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...
Comment | File | Size | Author |
---|---|---|---|
#6 | codefilter-advanced-help2.patch | 1.02 KB | beginner |
#5 | codefilter-advanced-help.patch | 788 bytes | beginner |
Comments
Comment #1
beginner CreditAttribution: beginner commentedThe advanced help output can be altered:
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.
Comment #2
merlinofchaos CreditAttribution: merlinofchaos commentedI 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.
Comment #3
beginner CreditAttribution: beginner commentedThere 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.
Comment #4
merlinofchaos CreditAttribution: merlinofchaos commentedIn theory we could apply .css to the code tag so that it works properly. I didn't try very hard to do it, though.
Comment #5
beginner CreditAttribution: beginner commentedI 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!
Comment #6
beginner CreditAttribution: beginner commentedThis 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.
Comment #7
beginner CreditAttribution: beginner commentedI noticed Karen of this thread:
#343072: syntax highlighting for advanced help.
Comment #8
helior CreditAttribution: helior commented#1649588: Support Input Filters might also interest you for achieving syntax highlighting via input filters. If this approach makes more sense for the feature request on this issue, please mark this issue as a duplicate.
Comment #9
gisleI don't want to create an dependency on Codefilter. Having it optional will mean that people who don't have Codefilter installed will see nothing (or garbage) instead of markup on advanced help-pages. This is not desired behaviour.
I plan to implement filtering by Markdown as an option for README.md (see #1405734: Output READMEs as parsed Markdown). This will allow the use of backquotes, indentation to mark inline code and code blocks. Markdown is designed to degrade nicely for people who don't have Markdown installed.