« DevWeek next week - drop by for a chatDVD recorders are not for me »

dp.SyntaxHighlighter in Community Server

16/02/06

Permalink 08:09:55 pm
Categories: General

dp.SyntaxHighlighter in Community Server

I was trying to integrate dp.SyntaxHighlighter (the highlighting system that I use for my source code in this blog) into Community Server. I’ve never before had a look at the inner workings of Community Server, so I may certainly be missing something.

To integrate the highlighter into a blog, two things need to be done:

  1. A stylesheet must be added to (the head of) pages that want to use highlighting.
  2. JavaScript code must be added to those same pages, preferably right at the end, but certainly after all elements (normally textareas) that contain code that needs to be highlighted.

The first thing I was trying to understand is how CS builds its pages. I found that with the default blog theme, the main body of a blog post page is rendered by the file Themes\Blogs\default\BlogMaster.ascx. In that file, right in front of the tag </CS:Head>, I added my new stylesheet reference:

   <CS:Style  runat="server" Href="/syntaxhighlighting/SyntaxHighlighter.css" ID="Style3" Enqueue="true"/>

At the end, in front of </CS:MPContent>, I added the block of references to JavaScript code and also the final call to the highlighting code:

<script language="javascript" src="/syntaxhighlighting/shCore.js"></script>
<script language="javascript" src="/syntaxhighlighting/shBrushCSharp.js"></script>
<script language="javascript" src="/syntaxhighlighting/shBrushXml.js"></script>
<script language="javascript" src="/syntaxhighlighting/shBrushVb.js"></script>
<script language="javascript" src="/syntaxhighlighting/shBrushSql.js"></script>
<script language="javascript" src="/syntaxhighlighting/shBrushDelphi.js"></script>
<script language="javascript" src="/syntaxhighlighting/shBrushJScript.js"></script>
<script language="javascript" type="text/javascript">
  <!--
    dp.SyntaxHighlighter.HighlightAll('code');
  //-->
</script> 

Obviously Community Server doesn’t normally allow the necessary textarea tag in user posts, so I had to edit communityserver.config and add the entry <textarea name = "true" class = "true" /> to the <html> list under <MarkUp>. That done, I was able to create a post with a textarea and some C# code in it, and it was rendered correctly by the dp.SyntaxHighlighter code. Great stuff!

Now, the bad news is that once the theme for the blog is switched, my changes are useless. Why’s that? I switched to the theme PoisonIvy/Fire, and although there’s no other BlogMaster.ascx there, it doesn’t seem to use the one from the default theme. Apparently it doesn’t use any BlogMaster.ascx at all. Oh well. I wonder if there’s another mechanism that makes it possible to make changes in a place where they’ll be used automatically for all blog pages, regardless of the themes. Nobody in the Community Server Forums seems to care, or maybe I’m using the wrong search terms.

1 comment

I think the file other skins use is LayoutTemplate.ascx.

I hope this helps.
03/09/06 @ 19:03

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)
Please complete the song title below. Hint: enter 'h', 'e', 'a', 'v', 'e', 'n'
antispam test

Enter your email address:

Search

Oliver
MVP logo
March 2010
Sun Mon Tue Wed Thu Fri Sat
 << <   > >>
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31