Facebook LinkedIn Wordpress Tumblr Twitter

Enabling Syntax Highlighting in Wordpress

Hi all,

Tonight, while doing my business as an Informatics ITB university students in sixth term :P, I suddenly found an interesting plug-in of Wordpress that maybe has been already known by some of Wordpress user, but I do not think that all of Wordpress users know about this. It is SyntaxHighlighter plug-in. It will make you easier to post source code in Wordpress, so perhaps most of Informatics university students will activate this plugin on their own blog.

Well, I guess that you will just activate the plug-in and it will automatically work if you are a native Wordpress user - which means your blog are hosted on wordpress.com -, but how about a non-native Wordpress user like me (for your information, I am currently using Wordpress 2.3.3), whose blog is hosted in my own machine? So, here are the following action to activate the SyntaxHighlighter plug-in:
  1. Download the SyntaxHighlighter plug-in from wordpress official plug-in site. Just download the syntaxhighlighter.zip.
  2. Do not forget to download the core scripts (some JavaScript scripts) on Google Code, because Wordpress uses the SyntaxHighlighter JavaScript package by Alex Gorbatchev - I would like to say thank you very much to this person -. Download the SyntaxHighlighter_1.5.1.rar.
  3. Extract the first one of those compressed files in your Wordpress plug-in directory (wp-content/plugins/). The new folder will be created and its name is syntaxhighlighter.
  4. Go to syntaxhighlighter directory.
  5. Create a new directory namely files.
  6. Extract the last one in any place of your machine (it is not obligatory to extract it into your Wordpress plug-in directory). It will contain three directories: Scripts, Styles, and Uncompressed.
  7. Copy all files contained in Scripts and Styles directory into files directory (which mentioned in step 5) inside of your syntaxhighlighter directory. If your server operating system is UNIX family, please make sure that you have set the permission of your plug-in directory correctly.
  8. Now, you may enable the SyntaxHighlighter plug-in via Wordpress administration page. Just go directly to Plugin, and then activate your SyntaxHighlighter plug-in.

If it works, you can post your source code like this following example:

#include "Parser.h"

List parseLine(char* line) {
    List L;

    for(int i = 0; i < len(line); i++) {
        if(isNumber(line[i])) {
            //kalau bertemu angka
            char* temp = (char *)malloc(255*sizeof(char));
            for (int j = 0; j < 255; j++) {
                temp[j] = '';
            }

            j = 0;
            while(line[i] != ',') {
                temp[j] = line[i];
                i++;
                j++;
            }

            Point P;
            P.setX(atoi(temp));

            i++;
            j = 0;
            while(line[i] != ']') {
                temp[j] = line[i];
                i++;
                j++;
            }
            P.setY(atoi(temp));
            L.addLast(P);
        }
    }
    return L;
}
Just simply write your code inside of [sourcecode language='supported_language'] ...[/sourcecode], but do not forget to assign the language attribute of the sourcecode tag. There are several programming languages that have been supported by this plug-in (e.g.: C++, C#, Java, JavaScript, XML, etc.). It is better if you see its official FAQ. Do not forget to check your Wordpress version first, because it requires version 2.3.0 or above. This is all of my post for today. Actually, this is not the only way to enable the SyntaxHighlighter plug-in. Perhaps, you have the other way to enable it with the simpler steps. Alas! I still have to do my other tasks. They are Computer Graphics task and also other non-academics tasks that need to be done! So, good night everybody, I have got to go, but do not forget to leave your comment here if you are interested with the topic. :D

-KnightDNA-
blog comments powered by Disqus