Roy A. Triesscheijn’s Weblog

My programming world

Code snippets from Visual Studio to WordPress.com

Posted by royalexander on Tuesday 30 September, 2008

To keep everything nice and tidy I was hoping for some feature in WordPress to allow me to instert C# (or any style) code nicely. But wordpress wont even remember the indenting makeing everything gibberish unless I manually add spaces instead of tabs.

Many people use the <pre> tag but after some whining at the forums there is an actual function that does syntax highlighting and everything if you spell it exactly right.

Fill in your code between: {sourcecode language=’cshar’} … {/sourcecode} but replace the ‘{‘ and  ‘}’ by the standard brackets ‘[' and ']‘. This works really nicely like here below.

public partial class Form1 : Form
{
        public Form1()
        {
            InitializeComponent();
        }

        private void buttonGenerate_Click(object sender, EventArgs e)
        {
            string source = richTextSource.Text;
            textOutput.Text = source;
        }
}

The FAQ item can be found here
Special thanks to user ‘a sacred path’

3 Responses to “Code snippets from Visual Studio to WordPress.com”

  1. EvilNando said

    Damn this is handy

    thanks!

  2. Glad you like it, took me some time to find it (it’s so hidden in the faq’s)

  3. milang said

    I have been searching for days for exactly this feature… thank the high heavens for your blog.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>