RSS

WordPress free site: how to format/syntax highlighting your code without any plugin installed

08 Mar

WordPress has many plugins to format or highlight your code for almost every modern programming languages such as C, C++, C#, Java, Php, Pyton, Perl, Matlab, Javascript, to list a few.

However, for free WordPress sites which do not have access or control to install plugins, it is very hard to post your code with color syntax highlighted. I have been suffering from this, and resort to capture my code in images, which look nice, but often complained by the readers. For instance, one of my answer at StackOverflow, some coder complained: why image, not code?

enter image description here
http://stackoverflow.com/questions/7749341/very-basic-python-client-socket-example

To solve this problem, you can search Google with “code to html”, “code formatter” etc, and then you are directed to a bunch of very rich set of online html formatters. My favorite sites would be:

Given the code, you copy the source to the aforementioned site as input, and HTML colored, syntax highlighted code will be generated. And you can then copy the HTML to your blog writer, e.g. Windows Live Writer.

Go to the source tab of Live Writer, Copy the HTML code in the right side text block as shown below, paste it to the Source window of Live writer, modify the margin, line spaces etc to customize the code view:

image  image

image  image

class Program
{
    static CuteRobot bot;
    static void Main(string[] args)
    {
        bot = new CuteRobot();
        string input = "Hello, what is your name";
        var output = bot.getOutput(input);
        Console.WriteLine(input);
        Console.WriteLine(output);
        Console.ReadKey();
    }
}

I usually change the line spacing from 125% to 100%, and change the font to Consolas, as shown below:

class Program
{
    static CuteRobot bot;
    static void Main(string[] args)
    {
        bot = new CuteRobot();
        string input = "Hello, what is your name";
        var output = bot.getOutput(input);
        Console.WriteLine(input);
        Console.WriteLine(output);
        Console.ReadKey();
    }
}

Pretty, isn’t it? Happy blogging!

 
1 Comment

Posted by on March 8, 2014 in General, Linux, Windows

 

Tags: , , , , , , ,

One response to “WordPress free site: how to format/syntax highlighting your code without any plugin installed

  1. plagwitz

    December 20, 2014 at 3:53 am

    Thank for your suggestion, have you tried this: http://en.support.wordpress.com/code/posting-source-code/. Strangely, it does not seem to work for c# currently – that is how i landed on your page which could be an answer, but i have to admit rather get the builtin tag to work again… 🙂

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: