Changeset 2799

Show
Ignore:
Timestamp:
07/16/08 17:09:21 (1 month ago)
Author:
bchoate
Message:

Removing non-MT interfaces to eliminate loading Getopt::Long.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/release-41/plugins/Markdown/Markdown.pl

    r1098 r2799  
    1 #!/usr/bin/perl 
    2  
    31# 
    42# Markdown -- A text-to-HTML conversion tool for web writers 
     
    6664 
    6765 
    68 #### Blosxom plug-in interface ########################################## 
    69  
    70 # Set $g_blosxom_use_meta to 1 to use Blosxom's meta plug-in to determine 
    71 # which posts Markdown should process, using a "meta-markup: markdown" 
    72 # header. If it's set to 0 (the default), Markdown will process all 
    73 # entries. 
    74 my $g_blosxom_use_meta = 0; 
    75  
    76 sub start { 1; } 
    77 sub story { 
    78     my($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_; 
    79  
    80     if ( (! $g_blosxom_use_meta) or 
    81          (defined($meta::markup) and ($meta::markup =~ /^\s*markdown\s*$/i)) 
    82          ){ 
    83             $$body_ref  = Markdown($$body_ref); 
    84      } 
    85      1; 
    86 } 
    87  
    88  
    8966#### Movable Type plug-in interface ##################################### 
    90 eval {require MT};  # Test to see if we're running in MT. 
    91 unless ($@) { 
    92     require MT; 
    93     import  MT; 
    94     require MT::Template::Context; 
    95     import  MT::Template::Context; 
    96  
    97     eval {require MT::Plugin};  # Test to see if we're running >= MT 3.0. 
    98     unless ($@) { 
    99         require MT::Plugin; 
    100         import  MT::Plugin; 
    101  
    102         my $plugin = new MT::Plugin({ 
    103             name => "Markdown", 
    104             author_name => "John Gruber", 
    105             author_link => "http://daringfireball.net/", 
    106             plugin_link => "http://daringfireball.net/projects/markdown/", 
    107             version => $VERSION, 
    108             description => '<MT_TRANS phrase="A plain-text-to-HTML formatting plugin.">', 
    109             doc_link => 'http://daringfireball.net/projects/markdown/', 
    110             registry => { 
    111                 tags => { 
    112                     block => { 
    113                         MarkdownOptions => sub { 
    114                             my $ctx  = shift; 
    115                             my $args = shift; 
    116                             my $builder = $ctx->stash('builder'); 
    117                             my $tokens = $ctx->stash('tokens'); 
    118  
    119                             if (defined ($args->{'output'}) ) { 
    120                                 $ctx->stash('markdown_output', lc $args->{'output'}); 
    121                             } 
    122  
    123                             defined (my $str = $builder->build($ctx, $tokens) ) 
    124                                 or return $ctx->error($builder->errstr); 
    125                             $str;       # return value 
    126                         }, 
    127                     }, 
    128                 }, 
    129                 text_filters => { 
    130                     markdown => { 
    131                         label => 'Markdown', 
    132                         docs => 'http://daringfireball.net/projects/markdown/', 
    133                         code => sub { 
    134                             my $text = shift; 
    135                             my $ctx  = shift; 
    136                             my $raw  = 0; 
    137                             if (defined $ctx) { 
    138                                 my $output = $ctx->stash('markdown_output');  
    139                                 if (defined $output  &&  $output =~ m/^html/i) { 
    140                                     $g_empty_element_suffix = ">"; 
    141                                     $ctx->stash('markdown_output', ''); 
    142                                 } 
    143                                 elsif (defined $output  &&  $output eq 'raw') { 
    144                                     $raw = 1; 
    145                                     $ctx->stash('markdown_output', ''); 
    146                                 } 
    147                                 else { 
    148                                     $raw = 0; 
    149                                     $g_empty_element_suffix = " />"; 
    150                                 } 
    151                             } 
    152                             $text = $raw ? $text : Markdown($text); 
    153                             $text; 
    154                         }, 
    155                     }, 
    156                     'markdown_with_smartypants' => { 
    157                         label     => 'Markdown With SmartyPants', 
    158                         docs      => 'http://daringfireball.net/projects/markdown/', 
    159                         code => sub { 
    160                             my $text = shift; 
    161                             my $ctx  = shift; 
    162                             if (defined $ctx) { 
    163                                 my $output = $ctx->stash('markdown_output');  
    164                                 if (defined $output  &&  $output eq 'html') { 
    165                                     $g_empty_element_suffix = ">"; 
    166                                 } 
    167                                 else { 
    168                                     $g_empty_element_suffix = " />"; 
    169                                 } 
    170                             } 
    171                             $text = Markdown($text); 
    172                             if (defined &SmartyPants::SmartyPants) { 
    173                                 $text = SmartyPants::SmartyPants($text, '1'); 
    174                             } 
    175                             return $text; 
    176                         }, 
    177                     }, 
     67 
     68require MT; 
     69require MT::Plugin; 
     70 
     71my $plugin = new MT::Plugin({ 
     72    name => "Markdown", 
     73    author_name => "John Gruber", 
     74    author_link => "http://daringfireball.net/", 
     75    plugin_link => "http://daringfireball.net/projects/markdown/", 
     76    version => $VERSION, 
     77    description => '<MT_TRANS phrase="A plain-text-to-HTML formatting plugin.">', 
     78    doc_link => 'http://daringfireball.net/projects/markdown/', 
     79    registry => { 
     80        tags => { 
     81            block => { 
     82                MarkdownOptions => sub { 
     83                    my $ctx  = shift; 
     84                    my $args = shift; 
     85                    my $builder = $ctx->stash('builder'); 
     86                    my $tokens = $ctx->stash('tokens'); 
     87 
     88                    if (defined ($args->{'output'}) ) { 
     89                        $ctx->stash('markdown_output', lc $args->{'output'}); 
     90                    } 
     91 
     92                    defined (my $str = $builder->build($ctx, $tokens) ) 
     93                        or return $ctx->error($builder->errstr); 
     94                    $str;       # return value 
    17895                }, 
    17996            }, 
    180         }); 
    181         MT->add_plugin( $plugin ); 
    182     } 
    183 
    184 else { 
    185 #### BBEdit/command-line text filter interface ########################## 
    186 # Needs to be hidden from MT (and Blosxom when running in static mode). 
    187  
    188     # We're only using $blosxom::version once; tell Perl not to warn us: 
    189     no warnings 'once'; 
    190     unless ( defined($blosxom::version) ) { 
    191         use warnings; 
    192  
    193         #### Check for command-line switches: ################# 
    194         my %cli_opts; 
    195         use Getopt::Long; 
    196         Getopt::Long::Configure('pass_through'); 
    197         GetOptions(\%cli_opts, 
    198             'version', 
    199             'shortversion', 
    200             'html4tags', 
    201         ); 
    202         if ($cli_opts{'version'}) {     # Version info 
    203             print "\nThis is Markdown, version $VERSION.\n"; 
    204             print "Copyright 2004 John Gruber\n"; 
    205             print "http://daringfireball.net/projects/markdown/\n\n"; 
    206             exit 0; 
    207         } 
    208         if ($cli_opts{'shortversion'}) {        # Just the version number string. 
    209             print $VERSION; 
    210             exit 0; 
    211         } 
    212         if ($cli_opts{'html4tags'}) {           # Use HTML tag style instead of XHTML 
    213             $g_empty_element_suffix = ">"; 
    214         } 
    215  
    216  
    217         #### Process incoming text: ########################### 
    218         my $text; 
    219         { 
    220             local $/;               # Slurp the whole file 
    221             $text = <>; 
    222         } 
    223         print Markdown($text); 
    224     } 
    225 
     97        }, 
     98        text_filters => { 
     99            markdown => { 
     100                label => 'Markdown', 
     101                docs => 'http://daringfireball.net/projects/markdown/', 
     102                code => sub { 
     103                    my $text = shift; 
     104                    my $ctx  = shift; 
     105                    my $raw  = 0; 
     106                    if (defined $ctx) { 
     107                        my $output = $ctx->stash('markdown_output');  
     108                        if (defined $output  &&  $output =~ m/^html/i) { 
     109                            $g_empty_element_suffix = ">"; 
     110                            $ctx->stash('markdown_output', ''); 
     111                        } 
     112                        elsif (defined $output  &&  $output eq 'raw') { 
     113                            $raw = 1; 
     114                            $ctx->stash('markdown_output', ''); 
     115                        } 
     116                        else { 
     117                            $raw = 0; 
     118                            $g_empty_element_suffix = " />"; 
     119                        } 
     120                    } 
     121                    $text = $raw ? $text : Markdown($text); 
     122                    $text; 
     123                }, 
     124            }, 
     125            'markdown_with_smartypants' => { 
     126                label     => 'Markdown With SmartyPants', 
     127                docs      => 'http://daringfireball.net/projects/markdown/', 
     128                code => sub { 
     129                    my $text = shift; 
     130                    my $ctx  = shift; 
     131                    if (defined $ctx) { 
     132                        my $output = $ctx->stash('markdown_output');  
     133                        if (defined $output  &&  $output eq 'html') { 
     134                            $g_empty_element_suffix = ">"; 
     135                        } 
     136                        else { 
     137                            $g_empty_element_suffix = " />"; 
     138                        } 
     139                    } 
     140                    $text = Markdown($text); 
     141                    if (defined &SmartyPants::SmartyPants) { 
     142                        $text = SmartyPants::SmartyPants($text, '1'); 
     143                    } 
     144                    return $text; 
     145                }, 
     146            }, 
     147        }, 
     148    }, 
     149}); 
     150MT->add_plugin( $plugin ); 
     151 
    226152 
    227153sub Markdown { 
  • branches/release-41/plugins/Markdown/SmartyPants.pl

    r1098 r2799  
    1 #!/usr/bin/perl -w 
    2  
    31# 
    42# SmartyPants  -  A Plug-In for Movable Type, Blosxom, and BBEdit 
     
    3129 
    3230 
    33 # Blosxom plug-in interface: 
    34 sub start { 1; } 
    35 sub story { 
    36     my($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_; 
    37  
    38     $$title_ref = SmartyPants($$title_ref, $smartypants_attr, undef); 
    39     $$body_ref  = SmartyPants($$body_ref,  $smartypants_attr, undef); 
    40     1; 
    41 } 
    42  
    43  
    4431# Movable Type plug-in interface: 
    45 eval {require MT::Plugin};  # Test to see if we're running in MT. 
    46 unless ($@) { 
    47     require MT; 
    48     MT->add_plugin({ 
    49         name => "SmartyPants", 
    50         description => q(<MT_TRANS phrase="Easily translates plain punctuation characters into 'smart' typographic punctuation.">), 
    51         version => $VERSION, 
    52         author_name => "John Gruber", 
    53         author_link => "http://daringfireball.net/", 
    54         plugin_link => "http://daringfireball.net/projects/smartypants/", 
    55         registry => { 
    56             tags => { 
    57                 modifier => { 
    58                     smarty_pants => \&SmartyPants, 
    59                     smart_quotes => \&SmartQuotes, 
    60                     smart_dashes => \&SmartDashes, 
    61                     smart_ellipses => \&SmartEllipses, 
    62                 }, 
    63                 function => { 
    64                     SmartyPantsVersion => \&SmartyPantsVersion, 
    65                 }, 
     32 
     33require MT; 
     34MT->add_plugin({ 
     35    name => "SmartyPants", 
     36    description => q(<MT_TRANS phrase="Easily translates plain punctuation characters into 'smart' typographic punctuation.">), 
     37    version => $VERSION, 
     38    author_name => "John Gruber", 
     39    author_link => "http://daringfireball.net/", 
     40    plugin_link => "http://daringfireball.net/projects/smartypants/", 
     41    registry => { 
     42        tags => { 
     43            modifier => { 
     44                smarty_pants => \&SmartyPants, 
     45                smart_quotes => \&SmartQuotes, 
     46                smart_dashes => \&SmartDashes, 
     47                smart_ellipses => \&SmartEllipses, 
     48            }, 
     49            function => { 
     50                SmartyPantsVersion => \&SmartyPantsVersion, 
    6651            }, 
    6752        }, 
    68     }); 
    69  
    70     # # If Markdown is loaded, add a combo Markdown/SmartyPants text filter: 
    71     # my $filters = MT->all_text_filters(); 
    72     # if (exists( $filters->{'markdown'} )) { 
    73     #     my $markdown_ref = $filters->{'markdown'}{on_format}; 
    74     #     if ($markdown_ref) { 
    75     #         MT->add_text_filter('markdown_with_smartypants' => { 
    76     #             label => 'Markdown With SmartyPants', 
    77     #             on_format => sub { 
    78     #                 my $text = shift; 
    79     #                 $text = &$markdown_ref($text); 
    80     #                 $text = SmartyPants($text, $smartypants_attr); 
    81     #             }, 
    82     #             docs => 'http://daringfireball.net/projects/markdown/' 
    83     #         }); 
    84     #     } 
    85     # } 
    86 
    87 else { 
    88     # BBEdit text filter interface; needs to be hidden from MT 
    89     # (and Blosxom when running in static mode). 
    90  
    91     # Set up a do-nothing variable to keep Perl from warning us that 
    92     # we're only using $blosxom::version once. The right way to do this 
    93     # is to use "no warnings", but that doesn't work in Perl 5.005. 
    94     my $in_blosxom = defined($blosxom::version); 
    95  
    96     unless ( defined($blosxom::version) ) { 
    97         #### Check for command-line switches: ########################### 
    98         my %cli_opts; 
    99         use Getopt::Long; 
    100         Getopt::Long::Configure('pass_through'); 
    101         GetOptions(\%cli_opts, 
    102             'version', 
    103             'shortversion', 
    104             '1', 
    105             '2', 
    106             '3', 
    107         ); 
    108         if ($cli_opts{'version'}) {     # Version info 
    109             print "\nThis is Markdown, version $VERSION.\n"; 
    110             print "Copyright 2004 John Gruber\n"; 
    111             print "http://daringfireball.net/projects/markdown/\n"; 
    112             exit 0; 
    113         } 
    114         if ($cli_opts{'shortversion'}) {        # Just the version number string. 
    115             print $VERSION; 
    116             exit 0; 
    117         } 
    118         if ($cli_opts{'1'}) { $smartypants_attr = 1 }; 
    119         if ($cli_opts{'2'}) { $smartypants_attr = 2 }; 
    120         if ($cli_opts{'3'}) { $smartypants_attr = 3 }; 
    121  
    122  
    123         #### Process incoming text: ##################################### 
    124         my $old = $/; 
    125         undef $/;               # slurp the whole file 
    126         my $text = <>; 
    127         $/ = $old; 
    128         print SmartyPants($text, $smartypants_attr, undef); 
    129     } 
    130 
     53    }, 
     54}); 
    13155 
    13256