Source code highlighting in Drupal

It is nice to be able to blog about software. For instance, a few years ago I wrote an article about web development using C++. I still get a comment or two about it almost every week, despite the fact that not a single line of code has been written for the project, unfortunately. However, if I ever took the initiative and started working on it, I would, no doubt, write some interesting progress reports here as well. As things go, it would be very neat to show off some code in the process. By using the Geshi source code highligher/formatter, it is much easier with Drupal nowadays. Just install the module, install the library and off you go!

Don't forget to enable/disable additional languages in the settings of the module.

Here is a nice example from the open source C++ library boost, taken from here:

class image;
 
class animation
{
public:
 
    void advance(int ms);
    bool inactive() const;
    void render(image & target) const;
};
 
std::vector<animation> anims;
 
template<class C, class P> void erase_if(C & c, P pred)
{
    c.erase(std::remove_if(c.begin(), c.end(), pred), c.end());
}
 
void update(int ms)
{
    std::for_each(anims.begin(), anims.end(), boost::bind(&animation::advance, _1, ms));
    erase_if(anims, boost::mem_fn(&animation::inactive));
}
 
void render(image & target)
{
    std::for_each(anims.begin(), anims.end(), boost::bind(&animation::render, _1, boost::ref(target)));
}

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
Please confirm you are a human being
Image CAPTCHA
Enter the characters shown in the image.