Thursday, April 18, 2013

Razor brush for Alex Gorbatchev's SyntaxHighlighter

While I was putting together a new blog post about customizing the Web API Help page I took a look at how to display code in Blogger. SyntaxHighlighter is a popular tool for highlighting code in your blog posts which uses Javascript files and CSS to modify code snippets.

I followed this quick guide to using SyntaxHighlighter with Blogger (tip: don't add script references to brushes that you're not using!) and was generally pleased with the results but sad that no Razor brush is available. After a quick dabble however I have created a quick and dirty Razor brush for SyntaxHighlighter which I hope people find useful!

Example razor syntax:

10 comments:

  1. Very userful! I use it in my blog thanks.

    returnsmart.blogspot.com

    ReplyDelete
  2. Nice one. I was looking for it.

    Thank you :)

    ReplyDelete
  3. Ya man! Very useful. Everyones got C# but they forget about the Razor highlighting in cshtml pages. I used it CMS where people can write views without needing to publish. THis helped me allot ! Thanks

    ReplyDelete
  4. There's a bug in this brush script. Towards the end of the script is the line

    SyntaxHighlighter.brushes.Xml = Brush;

    This causes problems if you're referencing the XML brush on the same page.

    There's a simple fix: change that above line to

    SyntaxHighlighter.brushes.Razor = Brush;

    Presumably this bug has been introduced by the author copying the contents of the XML brush and then modifying it for the Razor syntax.

    Otherwise it's a great addition - my thanks to the author.

    ReplyDelete
  5. it's greate i have been searching for months
    for my blog.
    www.mitechdev.com

    ReplyDelete
  6. hi i am getting
    Error parsing XML, line 91, column 33: The content of elements must consist of well-formed character data or markup.

    errors while saving my blogger template after addition of above razor brush
    please help me.

    ReplyDelete
  7. Caution. There is a bug in Alex's script due to the addition of Razor syntax: https://stackoverflow.com/questions/27258554/syntax-highlighter-cant-find-brush-for-xml

    ReplyDelete
    Replies
    1. Yes thanks, this was actually fixed in the file download a few years back! However since then, Alex has made a lot of refactoring to the code so it would probably be worth checking out his latest code base: https://github.com/syntaxhighlighter

      Delete
  8. 2021 ford escape titanium hybrid - Tiagettech
    2021 is upon us. Today we titanium canteen are at the launch of black titanium fallout 76 a titanium meaning new, innovative titanium block gaming concept called “The Ultimate Guide to Hybrid Casinos and Slots,” with the launch titanium bicycle

    ReplyDelete