Selling cookie info to third-parties is a classic example of you can make money without doing evil.
RSS

Wiki-ish markup for Nanoblogger

2005/04/15 filed under /nanoblogger

I 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.

Posted by: B10m | permanent link | comments (9)

Comments

Val Schmidt wrote at 2005-12-22 17:33:

Thanks for the wiki formatting hint!

I took your idea and made an entry formating "plugin" so the changes are applied automatically and I don't have to run the script in advance. I simply modified what you have above to read from STDIN and write to STDOUT. I named the script "wiki.pl" and put it in

$NBHOME/plugins/entry/format/

Then I added a bash wrapper for inclusion into the nanoblogger api. This script is callled wiki.sh and is also in $NBHOME/plugins/entry/format/

wiki.sh

# NanoBlogger Wiki plugin to convert entries made in Wiki Text to html # Requires Text::WikiFormat CPAN module and a wiki.pl script also included # in this directory. # nb_msg "$plugins_textformataction `basename $nb_plugin` ..." NB_EntryBody=`echo "$NB_EntryBody" | plugins/entry/format/wiki.pl`

Now when I make an entry, I specify "wiki" in the FORMAT: field and my text gets pushed through the wiki filter on the fly!

-Val

BOK wrote at 2005-04-15 18:59:

You should make a script that changes your name into Warmelink or sthg. like that, hahaha!

BOK wrote at 2005-04-17 23:03:

Also... it seems like the comment-counter needs a little tuning!

B10m wrote at 2005-04-18 10:12:

Nope, I use static files, so comment counter will go up whenever I add something, and the blog is re-created ;)

Maybe I should give some fancy modernish methods, such as SSI, a chance ;)

BOK wrote at 2005-04-18 17:18:

Then my show a number anyway..?

BOK wrote at 2005-04-18 17:19:

WHY that is.

B10m wrote at 2005-04-18 19:23:

Yeah ... maybe I should fix that.

B10m wrote at 2005-04-19 10:18:

... done

B10m wrote at 2005-04-20 14:26:

... and now it's back to the original. I don't like slow down the site and break the Last-Modified header just to show some counters ;)

Comments are closed for this story.
Trackbacks are closed for this story.
return-member