Welcome to Pete Brown's 10rem.net

First time here? If you are a developer or are interested in Microsoft tools and technology, please consider subscribing to the latest posts.

You may also be interested in my blog archives, the articles section, or some of my lab projects such as the C64 emulator written in Silverlight.

(hide this)

Playing around with Syntax Highlighter

Pete Brown - 03 May 2009

Feel free to ignore this post. I’m toying around with changing the code on my blog to use the syntax highlighting made possible via:

Rather than the rather bloated (and unfriendly to RSS readers) paste from Visual Studio, I thought I’d try this. The “paste from VS” method retained all the colors and formatting from VS, but just made for bloated posts and left RSS readers (most anyway) with a jumbled mess without any line breaks. I need to actually post this live to see if this approach also gets munged in RSS readers.

XAML (using the XML formatting style)

<UserControl x:Class="PeteBrown.SilverlightSoundTest.Page"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:ui="clr-namespace:PeteBrown.SilverlightSoundTest.UI">
    <Grid x:Name="LayoutRoot" Background="{StaticResource MainBackgroundBrush}">

        <Grid>

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="320" />
                <ColumnDefinition Width="320" />
                <ColumnDefinition Width="320" />
            </Grid.ColumnDefinitions>

            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <ui:OscillatorEditor x:Name="Oscillator1Editor"
                                 Margin="5 5 0 5"
                                 Grid.Column="0"
                                 Grid.Row="0" />
            <ui:OscillatorEditor x:Name="Oscillator2Editor"
                                 Margin="0 5 0 5"
                                 Grid.Column="1"
                                 Grid.Row="0" />
            <ui:OscillatorEditor x:Name="Oscillator3Editor"
                                 Margin="0 5 5 5"
                                 Grid.Column="2"
                                 Grid.Row="0" />


            <ui:MixerEditor x:Name="MixerEditor"
                            Margin="5 5 5 5"
                            Grid.Row="1"
                            Grid.ColumnSpan="2" />



            <MediaElement x:Name="AudioPlayer"
                          AutoPlay="True" />



        </Grid>

C# code (using the C# formatting style)

for (int i = 0; i < MaxWaveforms; i++)
{
    double phase = CalculatePhaseWithOffset(state.PhaseOffset, state.Phase[i]);
    double sample = (state.MaxAmplitude.Value - (state.MaxAmplitude.Value / Math.PI) * phase) * (int)state.Polarity;

    //if (i % 2 != 0)
    //    sample *= -1;

    accumulatedAmplitude += sample;

    state.Phase[i] = CheckPhase(state.Phase[i] + ((MathUtility.TwoPI * detune[i]) / _sampleRate.SamplesPerSecond));

    //accumulatedAmplitude *= .75;    // warning, magic number at work

}
 
posted by Pete Brown on Sunday, May 3, 2009
filed under:  

6 comments for “Playing around with Syntax Highlighter”

  1. Pete Brownsays:
    Bummer. Looks like the rendering in RSS readers like outlook is still pretty poor (no line breaks). Not sure how it shows up in other readers.

    Since the rss reader experience doesn't seem any worse, but the online experience is better (automatic line wrapping, much easier copying of the raw source etc.) I'll probably stick with it.

    The copy/paste workflow when writing a post is a bit more cumbersome, but appears worth the final result.

    RSS Readers get no syntax highlighting in the new approach, but if they were getting mushed source in the past anyway, this isn't really any worse.

    Pete
  2. Steve Dunnsays:
    Hi Pete,
    Enjoying the blog - especially the C64 stuff. I loved the old machine! Some of my games are on Lemon 64, e.g. http://www.lemon64.com/games/details.php?ID=259

    I thought you'd like to know about my plug-in for Windows Live Writer that uses different kinds of formatting engines (SyntaxHighlighter (JavaScript), ActiPro (inline styles (also works in aggregators, and bitmap (looks the same everywhere!)). More info at http://stevedunns.blogspot.com/2009/03/update-to-code-formatter-plugin.html

    Cheers,

    Steve
    http://blog.dunnhq.com
  3. Ruurd Boekesays:
    yeah, exact same sentiment here. I've moved to syntax highlighter a few weeks ago and it has definitely been for the better.

    Google reader displays the code perfect (without highlighting ofcourse), but outlook does not.
    There is an option though, convert to br, that might help.

    Cheers,
    rj
  4. Steve Dunnsays:
    Hi again Pete,
    A new version of my code formatter plugin for Windows Live Writer is available for download at http://stevedunns.blogspot.com/2010/07/new-version-25-of-code-formatter-plug.html. New in this version is inserting code as a bitmap and bitmap effects (reflections etc.)

    Cheers,

    Steve
  5. alessandrosays:
    I recently released a syntax highlighter developed in silverlight. You or one of your readers might be interested so i'm posting the url :

    http://www.abmho.com

    It also runs in OOB mode and is installable. While now it may seem like a two step process because you have to copy and paste your code in it and then collect the output, in the future I plan to simplify this and make it work as a browser plugin.

Comment on this Post

Remember me