| 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 | | |
|---|
| 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 | |
|---|
| | 68 | require MT; |
|---|
| | 69 | require MT::Plugin; |
|---|
| | 70 | |
|---|
| | 71 | my $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 |
|---|
| 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 | }); |
|---|
| | 150 | MT->add_plugin( $plugin ); |
|---|
| | 151 | |
|---|