Feature #2985

Make syntax highlighting pluggable

Added by Jean-Baptiste Barth almost 14 years ago. Updated almost 13 years ago.

Status:ClosedStart date:2009-03-16
Priority:NormalDue date:
Assignee:-% Done:


Category:Text formatting
Target version:1.0.0 (RC)


As discussed in #1651, actual CodeRay support in Redmine is limited, and it could be interesting to make syntax highlighting pluggable. Here is a proposal which keeps actual CodeRay behaviour by default, and allow plugins to implement syntax highlighting. See syntax_highlighting.diff

The second patch prevents Redcloth from escaping some chars when they're in a code block which will be treated by syntax highlighter. There's also a minor change to desactivate a broken (useless?) facility. It doesn't matter for coderay, but other highlighters like Ultraviolet cannot parse code with ampersands everywhere... Note this patch is necessary if you want the plugin below to work well in wikis sections (no impact on attached files). Also note the same kind of trick can easily solve #1416. See redcloth.diff

As an example, I leave a basic plugin to support Ultraviolet syntax highlighting, with active4d theme. It's quite simple, you just have to make your own module under Redmine::SyntaxHighlighting and define some methods. See ultraviolet_highlighter.zip

Any comment about all that is welcome !

syntax_highlighting.diff Magnifier (9.11 KB) Jean-Baptiste Barth, 2009-03-16 17:38

redcloth.diff Magnifier (3.54 KB) Jean-Baptiste Barth, 2009-03-16 17:38

ultraviolet_highlighter.zip - Sample plugin to support Ultraviolet. Read the README before installing. (21.8 KB) Jean-Baptiste Barth, 2009-03-16 17:38

ultraviolet_highlighter.zip - Compatible with r3584 (3.04 KB) Jean-Philippe Lang, 2010-03-14 15:38

Related issues

Related to Redmine - Patch #1651: Hack to make redmine use pygmentize instead of CodeRay Closed 2008-07-15
Related to Redmine - Feature #3032: Use google Prettify for syntax highlighting instead of Co... Closed 2009-03-23
Related to Redmine - Feature #1313: Optionally use ultraviolet for syntax highlighting Closed 2008-05-27

Associated revisions

Revision 3582
Added by Jean-Philippe Lang almost 13 years ago

Do not html escape code that is going to be highlighted (#2985, #3359).

Revision 3584
Added by Jean-Philippe Lang almost 13 years ago

Extract CodeRay calls to Redmine::SyntaxHighlighting (#2985).


#1 Updated by Jean-Philippe Lang almost 13 years ago

  • File ultraviolet_highlighter.zip added
  • Category set to Text formatting
  • Status changed from New to Closed
  • Target version set to 1.0.0 (RC)
  • Resolution set to Fixed

Code highlighting methods where extracted to a module in r3584. It doesn't support online configuration in application settings but it can be replaced with a plugin.
Attached a simple plugin that make use of Ultraviolet. BTW, it seems way slower than Coderay, at least for ruby highlighting.

#2 Updated by Kornelius Kalnbach almost 13 years ago

I read on the German Ruby forum that UV was about 20 times slower that CodeRay. But they really use the TextMate bundles, which are very complex. It's still fast enough for a lot of projects (Pastie, most notably), and they support a lot more languages.

Pygments would be faster, but if you have to call it via a shell command each time you want to highlight something, it may be even slower than Ultraviolet.

Also available in: Atom PDF