Select the code in the editor and type :TOhtml. This command opens a new buffer containing your code converted to html (including the colors). Now you only have to copy the html code and paste it to your entry.
As an example, here's my solution to Project Euler's #2:
#!/usr/bin/perl -w
use strict;
use feature 'say';
use Memoize;
memoize('fib');
my $n = 1;
my $fib = fib($n);
my $sum = 0;
while ($fib < 1_000_000) {
if ($fib % 2 == 0) {
say $fib;
$sum += $fib;
}
$n++;
$fib = fib($n);
}
say "Result: $sum";
sub fib {
my $n = shift;
return 1 if $n < 2;
fib ($n-1) + fib($n-2);
}
As you can see, the code coloring functionality of a default setup of MacVim doesn't recognize the new Perl 5.10 features (like the say function), but the result is quite readable.
NOTE: For an MT4 blog, the entry format should be None (pure HTML).
There is a similar solution for Emacs/XEmacs users. You can find the details here: htmlize.

Leave a comment