web 3.0

Syntax Highligting on Server Side (aka Code Format Rendering)

Here is the code being used as and Extension to render code.

The format is [code:lang;ln=on|off;alt=on|off] all of your code [code].  I am tinkering with the format because I am curious if there will be a need for other options.  Like forcing  a block display so that the code wraps, does not wrap, etc.  the

Replace LANG in [code:lang]  with the options c#, vb, js, html, xml, tsql, or msh.  <--Sets language
Set LN= to on or off <-- Sets line numbers
Set ALT= to on or off <-- Sets alternating background line colors.

The system handles the rest.

By the way you need the current builds or need to add the style sheet additions at the end of the post.

[code:c#;ln=off;alt=off]

#region using

using System;
using System.IO;
using System.Web;
using System.Text.RegularExpressions;
using BlogEngine.Core;
using BlogEngine.Core.Web;
using CodeFormatter;

#endregion


/// <summary>
/// </summary>
/// <remarks>
/// It is a work in progress.....
/// </remarks>
[Extension("Changes <code:lang></code>.  Adapted from Jean-Claude Manoli [jc@manoli.net].", "0.0.0.1", "www.manoli.net")]
public class CodeFormatters
{

      private enum CodeLanguages
    {
        csharp, vb, js, html, xml, tsql, msh
    }

    public CodeFormatters()
    {
        Post.Serving += new EventHandler<ServingEventArgs>(Post_Serving);
    }

    void Post_Serving(object sender, ServingEventArgs e)
    {
        /*  It supports the following.
         * C#
         * VB
         * JS
         * HTML
         * XML
         * T-SQL
         * MSH (code name Monad) --I don't have a clue.
         */
        if (!string.IsNullOrEmpty(e.Body))
        {
            e.Body = _CSharpRegex.Replace(e.Body, new MatchEvaluator(MatchEval));
            e.Body = _VBRegex.Replace(e.Body, new MatchEvaluator(MatchEval));
        }
    }

   }

[/code]

[code:c#;ln=on;alt=on]

#region using

using System;
using System.IO;
using System.Web;
using System.Text.RegularExpressions;
using BlogEngine.Core;
using BlogEngine.Core.Web;
using CodeFormatter;

#endregion


/// <summary>
/// </summary>
/// <remarks>
/// It is a work in progress.....
/// </remarks>
[Extension("Changes <code:lang></code>.  Adapted from Jean-Claude Manoli [jc@manoli.net].", "0.0.0.1", "www.manoli.net")]
public class CodeFormatters
{

      private enum CodeLanguages
    {
        csharp, vb, js, html, xml, tsql, msh
    }

    public CodeFormatters()
    {
        Post.Serving += new EventHandler<ServingEventArgs>(Post_Serving);
    }

    void Post_Serving(object sender, ServingEventArgs e)
    {
        /*  It supports the following.
         * C#
         * VB
         * JS
         * HTML
         * XML
         * T-SQL
         * MSH (code name Monad) --I don't have a clue.
         */
        if (!string.IsNullOrEmpty(e.Body))
        {
            e.Body = _CSharpRegex.Replace(e.Body, new MatchEvaluator(MatchEval));
            e.Body = _VBRegex.Replace(e.Body, new MatchEvaluator(MatchEval));
        }
    }

   }

[/code]

[code:c#;ln=off;alt=on]

#region using

using System;
using System.IO;
using System.Web;
using System.Text.RegularExpressions;
using BlogEngine.Core;
using BlogEngine.Core.Web;
using CodeFormatter;

#endregion


/// <summary>
/// </summary>
/// <remarks>
/// It is a work in progress.....
/// </remarks>
[Extension("Changes <code:lang></code>.  Adapted from Jean-Claude Manoli [jc@manoli.net].", "0.0.0.1", "www.manoli.net")]
public class CodeFormatters
{

      private enum CodeLanguages
    {
        csharp, vb, js, html, xml, tsql, msh
    }

    public CodeFormatters()
    {
        Post.Serving += new EventHandler<ServingEventArgs>(Post_Serving);
    }

    void Post_Serving(object sender, ServingEventArgs e)
    {
        /*  It supports the following.
         * C#
         * VB
         * JS
         * HTML
         * XML
         * T-SQL
         * MSH (code name Monad) --I don't have a clue.
         */
        if (!string.IsNullOrEmpty(e.Body))
        {
            e.Body = _CSharpRegex.Replace(e.Body, new MatchEvaluator(MatchEval));
            e.Body = _VBRegex.Replace(e.Body, new MatchEvaluator(MatchEval));
        }
    }

   }

[/code]

Currently rated 1.8 by 4 people

  • Currently 1.75/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Categories:

Bookmark and Share
Comments are closed