HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Please upgrade here. These earlier versions are no longer being updated and have security issues.

Writing Custom Brush

This discussion is related to the CreativeSyntaxHighlighter addon.
edited March 2015 in Vanilla 2.0 - 2.8

Hi,

Just installed Creative Syntax Highlighter and it works great for standard stuff. Now I need to write a custom brush for a strange language.

I've done my homework and found several tutorials on writing a custom brush. I followed the instructions and wrote one but it's not working. On page load it says "Can't find brush: custom".

Here is what I'm doing. To simplify things without funny business, rather than showing my custom code, let me copy the existing shBrushRuby.js file, call it shBrushRubyAbc.js file. So we know that code works, and is for a new dummy language called RubyAbc.

In that file I modify only these lines:

Brush.prototype = new SyntaxHighlighter.Highlighter();
Brush.aliases   = ['ruby', 'rails', 'ror', 'rb'];
SyntaxHighlighter.brushes.Ruby = Brush;

to this:

Brush.prototype = new SyntaxHighlighter.Highlighter();
Brush.aliases   = ['rubyabc'];
SyntaxHighlighter.brushes.RubyAbc = Brush;

So far so good. Next, I notice that in shInit.js there is a declaration for each shBrushXXX.js file, so let me add our new one in below the existing entry for Ruby:

    "ruby rails ror rb      @shBrushRuby.js",
    "rubyabc                @shBrushRubyAbc.js",

Save, upload both files to the respective folder, Disable and re-Enable the Creative Syntax Highlighter for good measure, and load a page containing this code:

<pre class="brush: ruby">Some ruby code</pre>

That works. But this doesn't work (it says "can't find brush: rubyabc"):

<pre class="brush: rubyabc">Some ruby code</pre>

What am I missing?

Thanks,
David

Comments

  • edited March 2015

    Typo:

    The first two code blocks above should be:

    Brush.prototype = new SyntaxHighlighter.Highlighter();
    Brush.aliases   = ['ruby', 'rails', 'ror', 'rb'];
    SyntaxHighlighter.brushes.Ruby = Brush;
    

    and

    Brush.prototype = new SyntaxHighlighter.Highlighter();
    Brush.aliases   = ['rubyabc'];
    SyntaxHighlighter.brushes.RubyAbc = Brush;
    

    The typo was only in this text - in the code itself I had it right but the plugin is still not working for 'rubyabc'.

  • Got it working! I'm not sure what was wrong, maybe just syntax error :-( Sorry. Thanks for your great plugin!

Sign In or Register to comment.