diff --git a/bin/MultiMarkdown.pl b/bin/MultiMarkdown.pl
index 8f36adf..a7bf049 100755
--- a/bin/MultiMarkdown.pl
+++ b/bin/MultiMarkdown.pl
@@ -1,138 +1,26 @@
#!/usr/bin/env perl
-# MultiMarkdown -- A modification of John Gruber's original Markdown
-# that adds new features and an output format that can more readily
-# be converted into other document formats
-#
-# $Id: MultiMarkdown.pl 525 2009-06-15 18:45:44Z fletcher $
-#
-# Original Code Copyright (c) 2004-2007 John Gruber
-#
-#
-# MultiMarkdown changes Copyright (c) 2005-2009 Fletcher T. Penney
-#
-#
-# MultiMarkdown Version 2.0.b6
-#
-# Based on Markdown.pl 1.0.2b8 - Wed 09 May 2007
-#
-#
-# TODO: Change math mode delimiter?
-# TODO: Still need to get the glossary working in non-memoir documents
-# TODO: A mechanism to include arbitrary code (LaTeX, etc) without being "ugly"
-# TODO: Look into discussion re: assigning classes to div's/span's on Markdown list.
-# TODO: Improve support for tables with long items and overall width in LaTeX
-# TODO: Need a syntax for long table cells in MMD, even if no rowspan feature yet
-# TODO: Create utilities to convert MMD tables to/from tab-delimited
-
-
-package MultiMarkdown;
require 5.006_000;
use strict;
use warnings;
use File::Basename;
+use File::Spec;
-eval {require MT}; # Test to see if we're running in MT.
-unless ($@) {
- require Text::ASCIIMathML;
-} else { # Otherwise look for ASCIIMathML.pm next to MultiMarkdown.pl
- my $me = $0; # Where am I?
-
- # Am I running in Windoze?
- my $os = $^O;
-
- # Get just the directory portion
- if ($os =~ /MSWin/) {
- $me = dirname($me) . "\\";
- } else {
- $me = dirname($me) . "/";
- }
- require $me ."ASCIIMathML.pm";
-}
-
+eval {require MultiMarkdown};
+if ($@) {
+ my $me = readlink(__FILE__) || __FILE__;
-use Digest::MD5 qw(md5_hex);
-use vars qw($VERSION $g_use_metadata $g_base_url
- $g_bibliography_title $g_allow_mathml $g_base_header_level $mathParser);
-$VERSION = '2.0.b6';
-
-$mathParser = new Text::ASCIIMathML();
-
-## Disabled; causes problems under Perl 5.6.1:
-# use utf8;
-# binmode( STDOUT, ":utf8" ); # c.f.: http://acis.openlib.org/dev/perl-unicode-struggle.html
-
-#
-# Global default settings:
-#
-my $g_empty_element_suffix = " />"; # Change to ">" for HTML output
-my $g_tab_width = 4;
-my $g_allow_mathml = 1;
-my $g_base_header_level = 1;
-
-#
-# Globals:
-#
-
-# Reusable patterns to match balanced [brackets] and (parens). See
-# Friedl's "Mastering Regular Expressions", 2nd Ed., pp. 328-331.
-my ($g_nested_brackets, $g_nested_parens);
-$g_nested_brackets = qr{
- (?> # Atomic matching
- [^\[\]]+ # Anything other than brackets
- |
- \[
- (??{ $g_nested_brackets }) # Recursive set of nested brackets
- \]
- )*
-}x;
-
-# Doesn't allow for whitespace, because we're using it to match URLs:
-$g_nested_parens = qr{
- (?> # Atomic matching
- [^()\s]+ # Anything other than parens or whitespace
- |
- \(
- (??{ $g_nested_parens }) # Recursive set of nested brackets
- \)
- )*
-}x;
-
-
-# Table of hash values for escaped characters:
-my %g_escape_table;
-foreach my $char (split //, '\\`*_{}[]()>#+-.!') {
- $g_escape_table{$char} = md5_hex($char);
-}
+ my $path = dirname(dirname($me));
+ $path = File::Spec->join($path, 'lib');
-# Global hashes, used by various utility routines
-my %g_urls = ();
-my %g_titles= ();
-my %g_html_blocks = ();
-my %g_metadata = ();
-my %g_metadata_newline = ();
-my %g_crossrefs = ();
-my %g_footnotes = ();
-my %g_attributes = ();
-my @g_used_footnotes = ();
-my $g_footnote_counter = 0;
+ unshift (@INC, $path);
-my $g_citation_counter = 0;
-my @g_used_references = ();
-my %g_references = ();
-$g_bibliography_title = "Bibliography";
-
-$g_use_metadata = 1;
-$g_metadata_newline{default} = "\n";
-$g_metadata_newline{keywords} = ", ";
-my $g_document_format = "";
-
-# Used to track when we're inside an ordered or unordered list
-# (see _ProcessListItems() for details):
-my $g_list_level = 0;
+ require MultiMarkdown;
+}
+import MultiMarkdown qw{markdown};
#### Blosxom plug-in interface ##########################################
@@ -140,7 +28,7 @@ package MultiMarkdown;
# which posts Markdown should process, using a "meta-markup: markdown"
# header. If it's set to 0 (the default), Markdown will process all
# entries.
-my $g_blosxom_use_meta = 0;
+our $g_blosxom_use_meta = 0;
sub start { 1; }
sub story {
@@ -149,7 +37,7 @@ sub story {
if ( (! $g_blosxom_use_meta) or
(defined($meta::markup) and ($meta::markup =~ /^\s*markdown\s*$/i))
){
- $$body_ref = Markdown($$body_ref);
+ $$body_ref = markdown($$body_ref);
}
1;
}
@@ -197,10 +85,11 @@ sub story {
my $text = shift;
my $ctx = shift;
my $raw = 0;
+ my %opts = ();
if (defined $ctx) {
my $output = $ctx->stash('multimarkdown_output');
if (defined $output && $output =~ m/^html/i) {
- $g_empty_element_suffix = ">";
+ $opts{empty_element_suffix} = ">";
$ctx->stash('multimarkdown_output', '');
}
elsif (defined $output && $output eq 'raw') {
@@ -209,10 +98,10 @@ sub story {
}
else {
$raw = 0;
- $g_empty_element_suffix = " />";
+ $opts{empty_element_suffix} = " />";
}
}
- $text = $raw ? $text : Markdown($text);
+ $text = $raw ? $text : markdown($text, %opts);
$text;
},
});
@@ -232,16 +121,17 @@ sub story {
on_format => sub {
my $text = shift;
my $ctx = shift;
+ my %opts = ();
if (defined $ctx) {
my $output = $ctx->stash('multimarkdown_output');
if (defined $output && $output eq 'html') {
- $g_empty_element_suffix = ">";
+ $opts{empty_element_suffix} = ">";
}
else {
- $g_empty_element_suffix = " />";
+ $opts{empty_element_suffix} = " />";
}
}
- $text = Markdown($text);
+ $text = markdown($text, %opts);
$text = $smartypants->($text, '1');
},
});
@@ -256,6 +146,8 @@ sub story {
unless ( defined($blosxom::version) ) {
use warnings;
+ my %opts = ();
+
#### Check for command-line switches: #################
my %cli_opts;
use Getopt::Long;
@@ -264,9 +156,24 @@ sub story {
'version',
'shortversion',
'html4tags',
+ 'markdownonly',
);
+
+ if ($cli_opts{'markdownonly'} || basename($0) eq 'Markdown.pl') {
+ %opts = (
+ allow_mathml => 0,
+ use_metadata => 0,
+ heading_ids => 0,
+ img_ids => 0,
+ codeblocks_newline => "\n",
+ disable_tables => 1,
+ disable_footnotes =>1,
+ disable_bibliography =>1,
+ );
+ }
+
if ($cli_opts{'version'}) { # Version info
- print "\nThis is MultiMarkdown, version $VERSION.\n";
+ print "\nThis is MultiMarkdown, version $MultiMarkdown::VERSION.\n";
print "Original code Copyright 2004 John Gruber\n";
print "MultiMarkdown changes Copyright 2005-2009 Fletcher Penney\n";
print "http://fletcherpenney.net/multimarkdown/\n";
@@ -274,2297 +181,25 @@ sub story {
exit 0;
}
if ($cli_opts{'shortversion'}) { # Just the version number string.
- print $VERSION;
+ print $MultiMarkdown::VERSION;
exit 0;
}
if ($cli_opts{'html4tags'}) { # Use HTML tag style instead of XHTML
- $g_empty_element_suffix = ">";
+ $opts{empty_element_suffix} = ">";
}
-
#### Process incoming text: ###########################
my $text;
{
local $/; # Slurp the whole file
$text = <>;
}
- print Markdown($text);
- }
-}
-
-
-
-sub Markdown {
-#
-# Main function. The order in which other subs are called here is
-# essential. Link and image substitutions need to happen before
-# _EscapeSpecialCharsWithinTagAttributes(), so that any *'s or _'s in the
-# and
tags get encoded.
-#
- my $text = shift;
-
- # Clear the global hashes. If we don't clear these, you get conflicts
- # from other articles when generating a page which contains more than
- # one article (e.g. an index page that shows the N most recent
- # articles):
- %g_urls = ();
- %g_titles = ();
- %g_html_blocks = ();
- %g_metadata = ();
- %g_crossrefs = ();
- %g_footnotes = ();
- @g_used_footnotes = ();
- $g_footnote_counter = 0;
- @g_used_references = ();
- %g_references = ();
- $g_citation_counter = 0;
- %g_attributes = ();
-
-
- # Standardize line endings:
- $text =~ s{\r\n}{\n}g; # DOS to Unix
- $text =~ s{\r}{\n}g; # Mac to Unix
-
- # Make sure $text ends with a couple of newlines:
- $text .= "\n\n";
-
- # Convert all tabs to spaces.
- $text = _Detab($text);
-
- # Strip any lines consisting only of spaces and tabs.
- # This makes subsequent regexen easier to write, because we can
- # match consecutive blank lines with /\n+/ instead of something
- # contorted like /[ \t]*\n+/ .
- $text =~ s/^[ \t]+$//mg;
-
- # Strip out MetaData
- $text = _ParseMetaData($text) if $g_use_metadata;
-
- # And recheck for leading blank lines
- $text =~ s/^\n+//s;
-
- # Turn block-level HTML blocks into hash entries
- $text = _HashHTMLBlocks($text);
-
- # Strip footnote and link definitions, store in hashes.
- $text = _StripFootnoteDefinitions($text);
-
- $text = _StripLinkDefinitions($text);
-
- _GenerateImageCrossRefs($text);
-
- $text = _StripMarkdownReferences($text);
-
- $text = _RunBlockGamut($text);
-
- $text = _DoMarkdownCitations($text);
-
- $text = _DoFootnotes($text);
-
- $text = _UnescapeSpecialChars($text);
-
- # Clean encoding within HTML comments
- $text = _UnescapeComments($text);
-
- $text = _FixFootnoteParagraphs($text);
- $text .= _PrintFootnotes();
-
- $text .= _PrintMarkdownBibliography();
-
- $text = _ConvertCopyright($text);
-
- if (lc($g_document_format) =~ /^complete\s*$/i) {
- return xhtmlMetaData() . "\n\n" . $text . "\n\n