From 84780f927c1990613bdde1a6563deb129ed080fc Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 4 Oct 2010 13:38:00 -0400 Subject: [PATCH] Updated mdwn_itex.pm for Ikiwiki 3.00. --- IkiWiki/Plugin/mdwn_itex.pm | 94 ++++++++++++++++++++++--------------- 1 file changed, 55 insertions(+), 39 deletions(-) diff --git a/IkiWiki/Plugin/mdwn_itex.pm b/IkiWiki/Plugin/mdwn_itex.pm index fea128e12..99efc24fe 100644 --- a/IkiWiki/Plugin/mdwn_itex.pm +++ b/IkiWiki/Plugin/mdwn_itex.pm @@ -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); + # 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 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 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 preprocess_itex (@) { - my %params = @_; - if (defined $params{disable}) { - $itex_pages{$params{page}} = 0; - } else { - $itex_pages{$params{page}} = 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 @@ sub itex_filter { 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 @@ Jacques Distler's itex2MML commands page. =head1 AUTHORS +W. Trevor King , +updates to IkiWiki v3.00 + Jason Blevins , itex Blosxom plugin @@ -144,6 +152,12 @@ itex2MML and itex2MML Movable Type Plugin =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 @@ http://golem.ph.utexas.edu/~distler/blog/itex2MML.html =head1 LICENSE +Copyright (C) 2010 W. Trevor King + Copyright (C) 2008 Jason Blevins Copyright (C) 2003-2007 Jacques Distler -- 2.26.2