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 the name “Syntax”

syntaxhighlighter sharepoint 2010

You can either refer to the CSS & JS files in your Master page (Recommended) so that you want to use it anywhere. Or if it’s for one time, You can refer to the files in the content editor web part 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 it’s for one time, You can just place these references in Content Editor web part.
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.

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

4 thoughts on “How to Integrate Syntaxhighlighter with SharePoint?

  • Thanks very much for nice article
    “How to Integrate Syntaxhighlighter with SharePoint”

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

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

  • 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.


Leave a Reply

Your email address will not be published. Required fields are marked *