dp-highlighter and Code Snippets

Filed under Uncategorized

I’ve seen a very nice effect on a number of blogs where code snippets were formatted and (somewhat) syntax highlighted.

I finally got a chance to do some digging and turned up the very cool javascript package called dp-highlighter.

In a nutshell, you put the dp-highlighter files in a folder on your website, then add the following code toward the bottom of any page that needs code highlighted:

<link type="text/css" rel="stylesheet" href="./dphighlighter/SyntaxHighlighter.css"></link>
<script language="javascript" src="./dphighlighter/shCore.js"></script>
<script language="javascript" src="./dphighlighter/shBrushVB.js"></script>
<script language="javascript" src="./dphighlighter/shBrushXml.js"></script>
<script language="javascript">
    dp.SyntaxHighlighter.ClipboardSwf = 'dphighlighter/clipboard.swf';

Make sure you change the shBrushVB.js to whichever language parser you want to use. Also, I put the files in a dphighlighter folder, but you can put them anywhere, really, just be sure to update the paths above.

Finally, for code you want to highlight, just stick it in a <PRE> tag, and add NAME=”code” CLASS=”VB”, like this

<pre name="code" class="vb">

if you got it right, you’ll end up with something like this:

Public Property Let HelpFile(ByVal NewValue$)

   If rbPrologueActivated Then
      rExc.HelpFile = NewValue$
      VBA.Err.HelpFile = NewValue$
   End If
End Property

There’s lots more documentation and examples at the link above.

Post a Comment

Your email is never published nor shared. Required fields are marked *