diff -u a/mdwn_itex.pm b/mdwn_itex.pm --- a/mdwn_itex.pm 2010-09-29 17:30:37.000000000 -0400 +++ b/mdwn_itex.pm 2010-09-29 23:59:59.713046023 -0400 @@ -2,66 +2,70 @@ # # itex to MathML plugin for IkiWiki. Based on the itex MovableType # plugin by Jacques Distler. -# -# Jason Blevins -# Chapel Hill, March 16, 2008 package IkiWiki::Plugin::mdwn_itex; use warnings; use strict; -use IkiWiki 2.00; +use IkiWiki 3.00; use File::Temp qw(tempfile); -my $markdown_sub; -my %itex_pages; - sub import { - hook(type => "getopt", id => "mdwn_itex", call => \&getopt); - hook(type => "htmlize", id => "mdwn", call => \&htmlize); - hook(type => "preprocess", id => "itex", call => \&preprocess_itex); -} - -sub getopt () { - eval q{use Getopt::Long}; - error($@) if $@; - Getopt::Long::Configure('pass_through'); - GetOptions( - # Location of the itex2mml binary - "itex2mml=s" => \$config{itex2mml}, - # Enable or disable numbering of \[..\] equations - "itex_num_equations!" => \$config{num_equations}, - # Process all pages by default or require [[!itex ]] directive? - "itex_default!" => \$config{itex_default}, - ); - - # Default settings - $config{itex2mml} = '/usr/local/bin/itex2MML' unless defined $config{itex2mml}; - $config{itex_num_equations} = 1 unless defined $config{itex_num_equations}; - $config{itex_default} = 0 unless defined $config{itex_default}; -} - -sub preprocess_itex (@) { - my %params = @_; - if (defined $params{disable}) { - $itex_pages{$params{page}} = 0; - } else { - $itex_pages{$params{page}} = 1; + # register the plugin + hook(type => "getsetup", id => "mdwn_itex", call => \&getsetup); + hook(type => "checkconfig", id => "mdwn_itex", call => \&checkconfig); + hook(type => "preprocess", id => "itex", call => \&preprocess); + hook(type => "htmlize", id => "mdwn_itex", call => \&htmlize, + longname => "Markdown + itex"); +} + +sub getsetup () { + # declare plugin options etc. for the setup file + return + plugin => { + description => "itex to MathML conversion followed by Markdown formatting", + safe => 1, + rebuild => 1, + section => "format", + }, + itex2mml => { + type => "string", + example => '/usr/local/bin/itex2MML', + description => "path to the itex2MML binary", + safe => 0, # path + rebuild => 0, + }, + itex_num_equations => { + type => "boolean", + example => 1, + description => "autonumber \[..\] equations?", + safe => 1, + rebuild => 1, + }, +} + +sub checkconfig () { + # setup default settings + if (! exists $config{itex2mml}) { + $config{itex2mml} = '/usr/local/bin/itex2MML'; + } + if (! exists $config{itex_num_equations}) { + $config{itex_num_equations} = 1; + } + if (! exists $config{itex_default}) { + $config{itex_default} = 0; } - return ''; } -# Taken from mdwn plugin and modified to call itex2MML. sub htmlize (@) { + # convert the page contents to XHTML. my %params=@_; + my $content = $params{content}; my $page = $params{page}; - # Default settings - $itex_pages{$page} = $config{itex_default} unless defined $itex_pages{$page}; - - $params{content} = itex_filter($content) if $itex_pages{$page}; + $params{content} = itex_filter($content); return IkiWiki::Plugin::mdwn::htmlize(%params); } @@ -77,6 +81,7 @@ my ($Reader, $outfile) = tempfile( UNLINK => 1 ); my ($Writer, $infile) = tempfile( UNLINK => 1 ); + binmode $Writer, ":utf8"; print $Writer "$content"; system("$config{itex2mml} < $infile > $outfile"); my @out = <$Reader>; @@ -136,6 +141,9 @@ =head1 AUTHORS +W. Trevor King , +updates to IkiWiki v3.00 + Jason Blevins , itex Blosxom plugin @@ -144,6 +152,12 @@ =head1 SEE ALSO +W. Trevor King's blog entry for this plugin: +http://www.physics.drexel.edu/~wking/unfolding-disasters/posts/mdwn_itex/ + +Jason Blevins' ikiwiki plugin: +http://jblevins.org/git/ikiwiki/plugins.git/plain/mdwn_itex.pm + ikiwiki Homepage: http://ikiwiki.info/ @@ -155,6 +169,8 @@ =head1 LICENSE +Copyright (C) 2010 W. Trevor King + Copyright (C) 2008 Jason Blevins Copyright (C) 2003-2007 Jacques Distler