/itexToMML

To download this project, use:
bzr branch http://golem.ph.utexas.edu/~distler/code/itexToMML/

« back to all changes in this revision

Viewing changes to plugin/itex2MML/TextileMarkdownMML.pl

  • Committer: Jacques Distler
  • Date: 2007-01-17 07:00:16 UTC
  • Revision ID: distler@golem.ph.utexas.edu-20070117070016-meaagnft95pf7ww1
Update MovableType plugin to support equation numbering and cross-referencing.
Bundle the TextileMarkdownMML plugin.

Show diffs side-by-side

added added

removed removed

 
1
# TextileMarkdownMML.pl
 
2
#
 
3
# Provides two MT text filters
 
4
#
 
5
#   Textile+itex2MML
 
6
#  Markdown+itex2MML
 
7
#
 
8
# You must have the itex2MML, Textile 1.1 and Markdown filters already installed
 
9
# This filter first runs your text through itex2MML and then through
 
10
# either Textile or Markdown.
 
11
#
 
12
# The Textile+itex2MML filter requires a small patch to the Textile 1.1 plugin.
 
13
# See:
 
14
#     http://golem.ph.utexas.edu/~distler/blog/archives/000374.html
 
15
#
 
16
# Based on textileMML.pl, by Yuan-Chung Cheng.
 
17
#
 
18
# Copyright, 2004-2007, Jacques Distler.
 
19
# This code is released under the GPL
 
20
#
 
21
 
 
22
package MT::Plugins::TextileMarkdownMML;
 
23
 
 
24
use vars qw($VERSION);
 
25
$VERSION = 1.2;
 
26
 
 
27
use strict;
 
28
 
 
29
use MT;
 
30
use MT::Template::Context;
 
31
use MT::Plugin::itex2MML;
 
32
 
 
33
eval{ require MT::Plugin;};
 
34
unless ($@) {
 
35
   my $plugin = {
 
36
      name => "TextileMarkdownMML",
 
37
      version => $VERSION,
 
38
      description => "A Text-Filter, adding support for embedded itex equations to Markdown and/or Textile 1.1. Requires itex2MML and one or both of the latter plugins be installed.",
 
39
      doc_link => 'http://golem.ph.utexas.edu/~distler/blog/archives/000374.html',
 
40
   };
 
41
   MT->add_plugin(new MT::Plugin($plugin));
 
42
}
 
43
 
 
44
my $filters = MT->all_text_filters();
 
45
 
 
46
if (exists($filters->{'textile_1'})) {
 
47
        MT->add_text_filter('textile_1MML' => {
 
48
                                     label => 'Textile with itex to MathML',
 
49
                                     on_format => sub { &textileMML; },
 
50
                                    });
 
51
}
 
52
if (exists($filters->{'markdown'})) {
 
53
        MT->add_text_filter('markdownMML' => {
 
54
                                     label => 'Markdown with itex to MathML',
 
55
                                     on_format => sub { &markdownMML; },
 
56
                                    });
 
57
}
 
58
 
 
59
sub textileMML {
 
60
 
 
61
  my $text=shift;
 
62
  my $ctx=shift;
 
63
 
 
64
  # now call apply_text_filters() to do the job
 
65
  $text=MT->apply_text_filters($text, ['itexToMML'], $ctx);
 
66
  $text=MT->apply_text_filters($text, ['textile_1'], $ctx);
 
67
 
 
68
  $text;
 
69
}
 
70
 
 
71
sub markdownMML {
 
72
 
 
73
  my $text=shift;
 
74
  my $ctx=shift;
 
75
 
 
76
  # now call apply_text_filters() to do the job
 
77
  $text=MT->apply_text_filters($text, ['itexToMML'], $ctx);
 
78
  $text=MT->apply_text_filters($text, ['markdown'], $ctx);
 
79
 
 
80
  $text;
 
81
}
 
82
1;
 
83