C# scanner file for CodeRay

Added by percy li over 3 years ago

I'm a C# programmer and don't have much knowledge on RoR.

When I came to Remine, the code highlighting tool "CodeRay" doesn't support C# right now. So I think I need to replace it with another highlighting tool, or make an extension for CodeRay.

There is already a Java scanner file in the current CodeRay library. So I tried to write a C# one according to the Java one. Fortunately, it went smoothly.

The attachment file is the C# scanner I made. It is a temporary solution, because I wrote it just for CodeRay 0.7.6.227, which is also the version Remine is currently using, although there seems to be some improvements in the newer versions of CodeRay. According to the CodeRay roadmap, C# support will be added in version 1.1.

Steps

Put the csharp.rb in <redmine folder>vendor/plugins/coderay-0.7.6.227/lib/coderay/scanners

And then you may use <pre><code class="csharp">.... block now.

(Optional) You may add aliases in the file <redmine folder>vendor/plugins/coderay-0.7.6.227/lib/coderay/_map.rb

(Optional) You may add file extensions' mappings in the file <redmine folder>vendor/plugins/coderay-0.7.6.227/lib/coderay/helpers/file_type.rb. And following is my settings:

    'cs' => :csharp,
    'config' => :xml,
    'aspx' => :html,
    'resx' => :xml,
    'asax' => :html,
    'ashx' => :html,
    'xaml' => :xml,
    'csproj' => :xml,
    'xsd' => :xml,
    'xsc' => :xml,
    'xss' => :xml,
    'settings' => :xml,

csharp.rb Magnifier (4.77 KB)

Replies (3)

RE: C# scanner file for CodeRay - Added by Steven Pardo about 3 years ago

Thanks for the c# scanner. It makes our code snippets much easier to read.

RE: C# scanner file for CodeRay - Added by Dmitry Popov 14 days ago

I've created a C# scanner for CodeRay 1.0.9 based on C++.

csharp.gif - A test (15.8 KB)

csharp-vscolors.gif - A test in Visual Studio default colors (14.7 KB)

csharp.rb Magnifier - C# scanner (6.36 KB)

_map.rb Magnifier - Scanners map (531 Bytes)

coderay_vscolors.css Magnifier - CSS file for Visual Studio default colors (4.56 KB)

(1-3/3)