/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 plugins/TextileMarkdownMML.pl

  • Committer: Jacques Distler
  • Date: 2007-01-18 15:08:31 UTC
  • Revision ID: distler@golem.ph.utexas.edu-20070118150831-72tmyxmgpcov01dn
Rename plugin directory to plugins.

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
 
 
32
eval{ require MT::Plugin;};
 
33
unless ($@) {
 
34
   my $plugin = {
 
35
      name => "TextileMarkdownMML",
 
36
      version => $VERSION,
 
37
      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.",
 
38
      doc_link => 'http://golem.ph.utexas.edu/~distler/blog/archives/000374.html',
 
39
   };
 
40
   MT->add_plugin(new MT::Plugin($plugin));
 
41
}
 
42
 
 
43
my $filters = MT->all_text_filters();
 
44
 
 
45
if (exists($filters->{'textile_1'}) && exists($filters->{'itexToMML'})) {
 
46
        MT->add_text_filter('textile_1MML' => {
 
47
                                     label => 'Textile with itex to MathML',
 
48
                                     on_format => sub { &textileMML; },
 
49
                                    });
 
50
}
 
51
if (exists($filters->{'markdown'}) && exists($filters->{'itexToMML'})) {
 
52
        MT->add_text_filter('markdownMML' => {
 
53
                                     label => 'Markdown with itex to MathML',
 
54
                                     on_format => sub { &markdownMML; },
 
55
                                    });
 
56
}
 
57
 
 
58
sub textileMML {
 
59
 
 
60
  my $text=shift;
 
61
  my $ctx=shift;
 
62
 
 
63
  # now call apply_text_filters() to do the job
 
64
  $text=MT->apply_text_filters($text, ['itexToMML'], $ctx);
 
65
  $text=MT->apply_text_filters($text, ['textile_1'], $ctx);
 
66
 
 
67
  $text;
 
68
}
 
69
 
 
70
sub markdownMML {
 
71
 
 
72
  my $text=shift;
 
73
  my $ctx=shift;
 
74
 
 
75
  # now call apply_text_filters() to do the job
 
76
  $text=MT->apply_text_filters($text, ['itexToMML'], $ctx);
 
77
  $text=MT->apply_text_filters($text, ['markdown'], $ctx);
 
78
 
 
79
  $text;
 
80
}
 
81
1;
 
82