redmine_ckeditor
redmine_ckeditor copied to clipboard
Syntax highlighting support
Currently entering something like following code snippets doesn't produce syntax-highlighted output:
Ruby example:
<pre dir="ltr"><code class="ruby"># The Greeter class
class Greeter
def initialize(name)
@name = name.capitalize
end
def salute
puts "Hello #{@name}!"
end
end
</code></pre>
C++ example:
<pre dir="ltr"><code class="cpp">#include <iostream>
int main() { std::cout << "Salaam" << std::endl; return 0; }
</code></pre>
Reported the issue to upstream: http://www.redmine.org/issues/8120
I got syntax highlighting to work by modifying lib/redmine_ckeditor/wiki_formatting/formatter.rb as follows:
def initialize(text)
@text = text.gsub(/<code\s+class="(\w+)">\s*(.+?)<\/code>/m) do
"<code class=\"#{$1} syntaxhl\">" +
Redmine::SyntaxHighlighting.highlight_by_language($2, $1) +
"</code>"
end
end