Wiki-ish markup for Nanoblogger
2005/04/15 filed under /nanobloggerI for one hate coding HTML. It's boring, repetitive and scripts can and should do it for you. That's why I figured it'd be nice to use Wiki-ish markup in my posts.
A plugin could be written do convert Wiki markup to HTML automagically, yet I don't trust automatic conversion that much, so I'd like to see the result before I publish my posting.
For this, I used Text::WikiFormat, a Perl plugin, that I call from my editor (vim, of course ;). First, you'll need to create a small script like the following:
#!/usr/bin/perl
use strict;
use File::Basename;
use Text::WikiFormat;
# Read contents of file
open FH, "<", $ARGV[0];
my $text = join("", <FH>);
close FH;
# Convert
my $html = Text::WikiFormat::format( $text, {
newline => "\n",
indent => qr/^(?:\t+|\s{2,})/,
strong_tag=> qr/\*([^\*]+)\*/,
paragraph => ["<p>\n","\n</p>\n\n",'',"\n", 1 ],
}, {
extended => 1,
implicit_links => 0
}
);
# Backup, if requested
if($ARGV[1]) {
my ($base,$path,$type) = fileparse($ARGV[0]);
rename($ARGV[0], "$path.$base");
}
# Write output
open FH, ">", $ARGV[0];
print FH $html;
close FH;
Of course, you'd want to tweak all of this and put in some error handling, but it's a start ;)
After this, you just create your article, or blog entry and save the file when you're done (:w in vim). After that, you launch the converter:
:!wiki.pl %
Or, if you want to save a backup copy (nice for articles)
:!wiki.pl % 1
Now your original file will be backed up as .$FILE_NAME and you will get back the HTML.



Comments
Val Schmidt wrote at 2005-12-22 17:33:
BOK wrote at 2005-04-15 18:59:
BOK wrote at 2005-04-17 23:03:
B10m wrote at 2005-04-18 10:12:
BOK wrote at 2005-04-18 17:18:
BOK wrote at 2005-04-18 17:19:
B10m wrote at 2005-04-18 19:23:
B10m wrote at 2005-04-19 10:18:
B10m wrote at 2005-04-20 14:26: