Defect #2575
closedPHP Syntax Highlighting Not Working
0%
Description
echo "Hello World";
When the above code is used highlighting does not work correctly. It seems to default to using plaintext instead of the php.rb. There are no errors in the Log files.
Any ideas what the issue could be, or how I could gather more debug information?
Files
Related issues
Updated by Rakesh Pathak almost 16 years ago
Sorry. The wiki has attempted to format this. I have attached the real code I am using.
Updated by Guillaume Lecanu almost 16 years ago
I have the same problems under v0.7.4
Thanks
Updated by Abhi Beckert over 15 years ago
It seems to me there are two issues here.
One is that the syntax highlighter doesn't handle a standalone code
tag. The line numbers don't mess up if I do:
<pre><code class="php"> ... </code>< /pre>
And the other issue is that php syntax highlighting only seems to work in the repository browser, not in the wiki. In our redmine installation, we are using javascript as a workaround for this, since the syntax is very similar.
Updated by Mischa The Evil about 15 years ago
Abhi Beckert wrote:
It seems to me there are two issues here.
One is that the syntax highlighter doesn't handle a standalone
code
tag. The line numbers don't mess up if I do:[...]
Hmm, this seems to be a design-choice made by the Redmine developers. I'll explain...
- Code within
code
tags (without aclass
definition) is handled by Redmine/RedCloth. Here's an example:
<c0de> <?php echo "Hello World!"; ?> </c0de>
renders as:
<?php
echo "Hello World!";
?>
Thus within these tags the content is rendered with a different font-family (monospace) and newlines are ignored. No line-numbering is added nor any highlighting is done.
- To enable highlighting (and to enable line-numbering) the
code
-tags should be used with aclass
-definition (which should be the name of a language which is supported by Redmine through the CodeRay-library) and they should be surrounded bypre
-tags.
Example:
<Pre><c0de class="ruby"> # The Greeter class class Greeter def initialize(name) @name = name.capitalize end def salute puts "Hello #{@name}!" end end</c0de></Pre>
renders as:
# The Greeter class
class Greeter
def initialize(name)
@name = name.capitalize
end
def salute
puts "Hello #{@name}!"
end
end
Thus, within code
-tags with a supported class
-definition, which are surrounded by pre
-tags, content is rendered with a different font-family (monospace), newlines are respected, line-numbering is added and highlighting is done.
code
-tags with a (supported) class-definition but without surroundingpre
-tags is not supported and will mess-up the output heavily.
Example:
<c0de class="ruby"> # The Greeter class class Greeter def initialize(name) @name = name.capitalize end def salute puts "Hello #{@name}!" end end </c0de>
will render as:
# The Greeter class
class Greeter
def initialize(name)
@name = name.capitalize
end
def salute
puts "Hello #{@name}!"
end
end
Thus, within code
-tags with a supported class
-definition, which are not surrounded by pre
-tags, content is rendered with a different font-family (monospace), highlighting is done but newlines are not respected while line-numbering is added.
Abhi Beckert wrote:
And the other issue is that php syntax highlighting only seems to work in the repository browser, not in the wiki. In our redmine installation, we are using javascript as a workaround for this, since the syntax is very similar.
Here you have the "real" issue. Currently PHP syntax-highlighting does not work in Redmine at all except in the Repository browser. IIRC this was made possible due to a custom change by the Redmine Developers.
An example of the issue:
<Pre><c0de class="php"> function add_ending_slash($path){ $slash_type = (strpos($path, '\\')===0) ? 'win' : 'unix'; $last_char = substr($path, strlen($path)-1, 1); if ($last_char != '/' and $last_char != '\\') { // no slash: $path .= ($slash_type == 'win') ? '\\' : '/'; } return $path; } </c0de></Pre>
will render without highlighting as:
function add_ending_slash($path){
$slash_type = (strpos($path, '\\')===0) ? 'win' : 'unix';
$last_char = substr($path, strlen($path)-1, 1);
if ($last_char != '/' and $last_char != '\\') {
// no slash:
$path .= ($slash_type == 'win') ? '\\' : '/';
}
return $path;
}
The recent upgrade to CodeRay 0.9 RC2 solved this issue temporarily. The upgrade is reverted due to several other reasons (see issue #3359 and it's relatives).
Most likely this issue will still be solved after completion of #3359.
Updated by Mischa The Evil almost 15 years ago
- Category changed from Wiki to Documentation
- Status changed from New to Closed
- Assignee deleted (
Jean-Philippe Lang) - Resolution set to Fixed
Mischa The Evil wrote:
(...)
Abhi Beckert wrote:
And the other issue is that php syntax highlighting only seems to work in the repository browser, not in the wiki. In our redmine installation, we are using javascript as a workaround for this, since the syntax is very similar.
Here you have the "real" issue. Currently PHP syntax-highlighting does not work in Redmine at all except in the Repository browser. IIRC this was made possible due to a custom change by the Redmine Developers.
An example of the issue:
[...]
will render without highlighting as:
[...]
The recent upgrade to CodeRay 0.9 RC2 solved this issue temporarily. The upgrade is reverted due to several other reasons (see issue #3359 and it's relatives).
Most likely this issue will still be solved after completion of #3359.
The solution for #3359 indeed solved the initial defect, thus I close this issue now.
NB: set the category to remind myself to rewrite the info for the Redmine Guide.