Sitecore Stuff and Such

- by Christian Kay Linkhusen

NAVIGATION - SEARCH

Syntax highlighting with highlight.js

Highlight.js supplies a javascript library for syntax highlighting your code snippets on the web. The solution is hosted and is setup with inserting 3 lines of code. 

Include the Javascript, stylesheet and initialize the highlighting, by inserting the following 3 lines to the head section of your page:

<link rel="stylesheet" href="http://yandex.st/highlightjs/8.0/styles/vs.min.css"> <script src="http://yandex.st/highlightjs/8.0/highlight.min.js"></script> <script type="text/javascript">hljs.initHighlightingOnLoad();</script>

All you have to do now, is to mark up your code snippet in the content with <pre><code>[content]</code</pre> and you are up and running.
If you want to read more about highlight.js see the website highlightjs.org for more information, on selecting different stylesheets, different usages of the library, customizing the code and more...  
 
Below are examples of different syntax highlights with highlight.js and the visual studio stylesheet:
Example with C#:
// Hello1.cs
public class Hello1
{
   public static void Main()
   {
      System.Console.WriteLine("Hello, World!");
   }
}

Example with XML:
<BlogEngine>
    <blogProvider defaultProvider="XmlBlogProvider" fileStoreProvider="XmlBlogProvider">
      <providers>
        <add description="Xml Blog Provider" name="XmlBlogProvider" type="BlogEngine.Core.Providers.XmlBlogProvider, BlogEngine.Core" />
        <add connectionStringName="BlogEngine" description="Sql Database Provider" name="DbBlogProvider" type="BlogEngine.Core.Providers.DbBlogProvider, BlogEngine.Core" />
      </providers>
    </blogProvider>
    <blogFileSystemProvider defaultProvider="XmlBlogProvider">
      <providers>
        <add description="Xml Blog Provider" name="XmlBlogProvider" type="BlogEngine.Core.Providers.XmlFileSystemProvider, BlogEngine.Core" />
        <add storageVariable="BlogEngine" description="Sql Database Provider" name="DbBlogProvider" type="BlogEngine.Core.Providers.DbFileSystemProvider, BlogEngine.Core" />
        <!--<add storageVariable="\\UNCPath\BlogFiles" description="UNC Path Provider" name="UNCBlogProvider" type="BlogEngine.Core.Providers.UNCFileSystemProvider, BlogEngine.Core" />-->
      </providers>
    </blogFileSystemProvider>
  </BlogEngine>

Add comment