From: Barijaona Ramaholimihaso Date: Thu, 13 Sep 2007 02:49:30 +0000 (+0000) Subject: Initial addition of textile2 plugin X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=742d07411ec64c2640c3dd1be8471e9548264433;p=matthijs%2Fupstream%2Fblosxom-plugins.git Initial addition of textile2 plugin --- diff --git a/general/textile2 b/general/textile2 new file mode 100644 index 0000000..5241bfd --- /dev/null +++ b/general/textile2 @@ -0,0 +1,110 @@ +# Blosxom Plugin: textile2 -*- perl -*- +# Author: Todd Larason (jtl@molehill.org) +# Version: 0+1i +# Blosxom Home/Docs/Licensing: http://www.raelity.org/blosxom +# Textile plugin Home/Docs/Licensing: +# http://molelog.molehill.org/blox/Computers/Internet/Web/Blosxom/Plugins/Textile/ + +package textile2; + +# Configuration Variables +# ---------------------------------------------------------------------------- +#$flavour = "xhtml" unless defined $flavour; +$flavor = "xhtml" unless defined $flavour; +$character_encoding = 1 unless defined $character_encoding; +$character_set = "utf-8" unless defined $character_set; +$head_offset = 3 unless defined $head_offset; +$image_root = $blosxom::datadir unless defined $image_root; +$handle_textile_1 = 0 unless defined $handle_textile_1; +# ---------------------------------------------------------------------------- +use strict; + +# Blosxom interface + +use lib qq{$blosxom::plugin_dir/lib}; +use vars qw/$flavor $character_encoding $character_set $head_offset + $image_root $handle_textile_1 $textile/; +sub start { + eval {require Text::Textile;}; + return 1 if (!$@); + return 0; +} + +sub story { + my($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_; + if ($meta::markup eq 'textile2' || + ($handle_textile_1 && $meta::markup eq 'textile')) { + my $c = { + image_root => $image_root, + image_rel_base => "$blosxom::datadir/$path" + }; + + $$body_ref = blostile($$body_ref, $c); + } + return 1; +} + +# Simplified interface to Blosxom::Textile + +# context items: +# image_root absolute image filenames relative to this +# image_rel_base relative image filenames relative to this + +sub blostile { + # modif : http://groups.yahoo.com/group/blosxom/message/4052 + local $_; + my $str = shift @_; + my $ctx = shift @_; + if (!$textile) { + $textile = new Blosxom::Textile; + # XXX named filters + $textile->char_encoding($character_encoding); + $textile->charset($character_set); + } + $textile->flavor($flavor); + $textile->filter_param($ctx); + + $str = $textile->process($str); + + if (defined $head_offset && ($head_offset > 1)) { + for (my $h = 7 - $head_offset; $h > 0; $h--) { + my $h2 = $h + $head_offset - 1; + $str =~ s/(<\/?)h$h([ >])/$1h$h2$2/g; + } + } + + # XXX beautifier + # XXX smarty? + + return $str; +} + +# Blosxom::Textile +package Blosxom::Textile; +use Text::Textile; +@Blosxom::Textile::ISA = qw(Text::Textile); + +sub image_size { + my ($self, $src) = @_; + my $ctx = $self->filter_param; + if ($src !~ m{^http:}) { + eval {require Image::Size;}; + if (!$@) { + my $file; + if ($src =~ m{^/}) { + $file = "$ctx->{image_root}$src"; + } else { + $file = "$ctx->{image_rel_base}/$src"; + } + my ($w, $h) = Image::Size::imgsize($file); + return ($w, $h); + } + } + warn "Image sizing without Image::Size not implemented"; + undef; +} + +# XXX format_link ? +# XXX format_url ? + +1; diff --git a/general/textile2.README b/general/textile2.README new file mode 100644 index 0000000..485fe26 --- /dev/null +++ b/general/textile2.README @@ -0,0 +1,20 @@ +Textile Text Formatter +Plugin for Blosxom + + + +Blosxom Installation +1. Install CPAN's Text::Textile module in your Perl installation, + or alternatively, create a 'lib/Text' directory under your Blosxom + plugin directory and copy 'Textile.pm' to $plugin_dir/lib/Text +3. Copy 'textile2' to $plugin_dir. You may wish to name it something like + '50textile2', and rename other plugins with other numbers, to get them + loaded in the right order. "The right order" is still somewhat unknown, + but I'd suggest using textile before SmartPants but after most other + body-modifying plugins (such as macro packages). +4. Install Rael's meta plugin if you don't already have it installed. +5. Create a test post; mark it as Textile by using "meta-markup: textile2" + on the line after the title. See the meta documentation for more + information on meta variables. You can also set + $meta::markup = "textile2" in your config file or your storyprefs file + if you use the config or the prefs plugin.