How to Integrate Syntaxhighlighter with SharePoint?

Needless to say, the format and style of our code play a vital part when writing technical blogs. Among the other code formatting plugins, I personally like SyntaxHighlighter as it is very easy to configure and use while keeping the code readable and easy to copy.

In this article I'm sharing my experience on integrating syntax highlighter with SharePoint 2010.

Step 1: Download the SyntaxHighlighter & upload to SharePoint
Download the syntax highlighter from and upload the files to a document library (or on the SharePoint server's 14 hive) so that you can reference them. Here I've created a document library with name "Syntax"
syntaxhighlighter sharepoint 2010

Step 2:Link/Refer the CSS and JS files
You can either refer the CSS & JS files in your Master page (Recommended) so that you wan to use it for anywhere.Or if its for one time, You can refer the files in content editor webpart even.
  • Go to SharePoint Designer, Open your site
  • Edit your Master page in advanced mode
  • Search for
<asp:ContentPlaceHolder id="PlaceHolderAdditionalPageHead" runat="server"/>
  • and Place this code just below, in Master page
syntaxhighlighter in sharepoint

<asp:ContentPlaceHolder id="PlaceHolderAdditionalPageHead" runat="server"/>
<!-- Reference for CSS files from current site collection -->
<SharePoint:CssRegistration name="<%$SPUrl:~SiteCollection/Syntax/shCore.css%>" runat="server"/>
<SharePoint:CssRegistration name="<%$SPUrl:~SiteCollection/Syntax/shThemeDefault.css%>" runat="server"/>
<!-- Reference for Js files  -->
<SharePoint:ScriptLink language="javascript" name="~sitecollection/Syntax/shCore.js" Defer="true" runat="server"/>
<SharePoint:ScriptLink language="javascript" name="~sitecollection/Syntax/shBrushCSharp.js" Defer="true" runat="server"/>
<!-- Call the script to apply formatting -->
<script type='text/javascript'>SyntaxHighlighter.all();</script>

OR If you want to refer from file system:
<!--This will search Shcore.js file in "14/template/layouts/1033/syntax/shcore.js"-->
<SharePoint:ScriptLink ID="ScriptLink1" Name="/Syntax/shCore.js" runat="server"/>
<SharePoint:ScriptLink ID="ScriptLink2" Name="/Syntax/shBrushCSharp.js" runat="server"/>
<!-- Call the script to apply formatting -->
<script type='text/javascript'>SyntaxHighlighter.all();</script>

If its for one time, You can just place these references in Content Editor webpart.
Add a content editor, Place this code. once done, Hide this content editor webpart.
<link href="/Syntax/shCore.css" rel="stylesheet" type="text/css"/>
<link href="/Syntax/shThemeDefault.css" rel="stylesheet" type="text/css"/>
<script src="/Syntax/shCore.js" type="text/javascript"></script>
<script src="/Syntax/shBrushCSharp.js" type="text/javascript"></script>
<!-- Call the script to apply formatting -->
<script type='text/javascript'>SyntaxHighlighter.all();</script>

Check-in and Publish your master page.

Step 3: Use the <Pre Class> wherever required.

<pre class="brush:c#"> YOUR CODE GOES HERE</pre>
syntaxhighlighter sharepoint blog

You will get Output like this when you place some more code: Syntaxhighlighter in SharePoint wiki
syntaxhighlighter sharepoint wiki

Here I've added the core functionality to highlight the code and the highlighting color brush for C# code only. For other code types, you add the appropriate brushes as separate references.


  1. The information in your post about SharePoint is more interesting. and this info is more useful for the developers to develop the SharePoint apps. Thanks for share this valuable info.

  2. That's a awesome! I found your posts are very useful as well as interesting.

  3. Brilliant !! Its just very interesting to read your blogs.. please keep posting such ideas . Thanks

  4. Thanks very much for nice article
    "How to Integrate Syntaxhighlighter with SharePoint"


Please Login and comment to get your questions answered!

Powered by Blogger.