# Bloxsom Plugin: AutoRef # Author: Victor Hsieh # Version: 2.0 # It's for Blosxom 2.0 package AutoRef; use HTML::Parser; use strict; my $_link_file = "$blosxom::datadir/reflinks"; my %_linkslist; my $_parser; sub start { open (LINKS, $_link_file); for my $i () { if ($i =~ /(.*?)=(.*)/) { $_linkslist{lc $1} = $2; } } close LINKS; $_parser = new HTML::Parser(api_version => 3) or die $!; $_parser->report_tags('body'); $_parser->ignore_elements('a', 'code', 'pre'); 1; } sub story { my ($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_; my $output; $_parser->handler( text => sub { foreach my $word (keys %_linkslist) { $_[1] =~ s/(?<=\b)($word)(?=\b)/$1<\/a>/gi; } $output .= join '', @_; }, 'skipped_text, text'); $_parser->parse($$body_ref); $_parser->eof(); $$body_ref = $output; 1; } 1; __END__ =head1 NAME Blosxom Plug-in: AutoRef =head1 SYNOPSIS Refer keywords in your page to related links. =head1 DESCRIPTION This plugin helps you refer keywords in your page to a reference link according to given database ($blosxom::datadir/reflinks). Here is the format: Blosxom=http://www.blosxom.com/ perl=http://www.perl.org/ Note that you should have HTML::Parser installed in your system. =head1 AUTHOR Victor Hsieh - http://victor.csie.org/ =head1 COPYRIGHT Copyright (c) 2005. Victor Hsieh. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html =cut