ebrahim / redmine_ckeditor

Redmine plugin for integrating CKEditor. This branch upgrades CKEditor to >=3.4 which supports bidirectional writing for right-to-left languages, such as Persian, Arabic, and Hebrew.
http://code.ebrahim.ir/redmine_ckeditor
15 stars 2 forks source link

Syntax highlighting support #1

Open ebrahim opened 13 years ago

ebrahim commented 13 years ago

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 commented 13 years ago

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

eddieroadcap commented 13 years ago

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