redmine_ckeditor icon indicating copy to clipboard operation
redmine_ckeditor copied to clipboard

Syntax highlighting support

Open ebrahim opened this issue 13 years ago • 2 comments

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 &quot;Hello #{@name}!&quot;
  end
end
</code></pre>

C++ example:

<pre dir="ltr"><code class="cpp">#include &lt;iostream&gt;
int main() { std::cout &lt;&lt; &quot;Salaam&quot; &lt;&lt; std::endl; return 0; }
</code></pre>

ebrahim avatar Apr 10 '11 12:04 ebrahim

Reported the issue to upstream: http://www.redmine.org/issues/8120

ebrahim avatar Apr 10 '11 15:04 ebrahim

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

eddieroadcap avatar Oct 07 '11 17:10 eddieroadcap