package IkiWiki::Plugin::mathjax; use warnings; use strict; use IkiWiki 3.00; use MIME::Base64; # Strategy: ## - filter replaces normal TeX delimiters with imath and dmath directives ## (perhaps while considering a mathconf directive); also, it adds a script ## block if there is any math on the page relevant. ## - preprocess handles the directives themselves. ## ## Later: config hooks for mathjax script tag and mathjax config block ## sub import { hook(type => "filter", id => "mathjax", call => \&filter); hook(type => "format", id=>"mathjax", call=> \&format); } sub format { my %params = @_; my $content = $params{content}; return $content unless $content =~ /\!\!mathjaxbegin/; #]/{{ $content =~ s{\!\!mathjaxbegin-i!! (.*?)\s\!\!mathjaxend-i\!\!}{'\('.decode_base64($1).'\)'}ges; #{ $content =~ s{\!\!mathjaxbegin-d!! (.*?)\s\!\!mathjaxend-d\!\!}{'\['.decode_base64($1).'\]'}ges; #{ my $scripttag = _scripttag(); $content =~ s{()}{$scripttag\n$1}i; #}{ return $content; } sub filter (@) { my %params=@_; my $content = $params{content}; return $content unless $content =~ /\$[^\$]+\$|\\[\(\[][\s\S]+\\[\)\]]/; # first, handle display math... $content =~ s{(?/>/g; #{" $directive .= encode_base64($formula, " "); $directive .= "!!mathjaxend-$mode!!"; return $directive; } sub _scripttag { my $config = 'TeX-AMS_HTML'; # another possibility: TeX-AMS-MML_HTMLorMML return '' . ''; } 1;