# Bloxsom Plugin: AutoRef # Author: Victor Hsieh # Version: 3.0 # It's for Bloxsom 3.0 package Blosxom::Plugin::AutoRef; use HTML::Parser; use strict; use constant db_file => 'reflinks'; my %_linkslist; my $_parser = undef; sub singleton { my $self = shift; return if $_parser; my $file = "$self->{settings}->{basedir}/".db_file; open (LINKS, "<$file") or die "$!: $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 run { my $self = shift; my $body_ref = \$self->{state}->{current_entry}->{body}; my $output; singleton($self); $_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 ($basedir/reflinks). Here is the format: Blosxom=http://www.blosxom.com/ perl=http://www.perl.org/ You should add Blosxom::Plugin::AutoRef::run to handlers.entry before Blosxom::shortcut_max_entries (before anything might change HTML structure). 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