3 # $Id: multimarkdown2XHTML.pl 481 2008-01-12 23:06:15Z fletcher $
5 # Required for using MultiMarkdown
7 # Copyright (c) 2006-2008 Fletcher T. Penney
8 # <http://fletcherpenney.net/>
10 # MultiMarkdown Version 2.0.b5
13 # Combine all the steps necessary to process MultiMarkdown text into XHTML
14 # Not necessary, but might be easier than stringing the commands together
17 # TODO: Add an option to turn SmartyPants off?
19 # Add metadata to guarantee we can transform to a complete XHTML
20 $data = "Format: complete\n";
23 # Parse stdin (MultiMarkdown file)
28 # Find name of XHTML File if specified
29 $xslt_file = _XhtmlXSLT($data);
30 $xslt_file = "" if ($xslt_file eq "");
33 # Decide which flavor of SmartyPants to use
34 $language = _Language($data);
35 $SmartyPants = "SmartyPants.pl";
37 $SmartyPants = "SmartyPantsGerman.pl" if ($language =~ /^\s*german\s*$/i);
39 $SmartyPants = "SmartyPantsFrench.pl" if ($language =~ /^\s*french\s*$/i);
41 $SmartyPants = "SmartyPantsSwedish.pl" if ($language =~ /^\s*(swedish|norwegian|finnish|danish)\s*$/i);
43 $SmartyPants = "SmartyPantsDutch.pl" if ($language =~ /^\s*dutch\s*$/i);
46 # Create a pipe and process
47 $me = $0; # Where am I?
49 # Am I running in Windoze?
53 $me =~ s/\\([^\\]*?)$/\\/; # Get just the directory portion
55 $me =~ s/\/([^\/]*?)$/\//; # Get just the directory portion
59 $xslt = "| xsltproc -nonet -novalid ..\\XSLT\\$xslt_file -" if ($xslt_file ne "");
60 open (MultiMarkdown, "| cd \"$me\"& .\\MultiMarkdown.pl | .\\$SmartyPants $xslt");
62 $xslt = "| xsltproc -nonet -novalid ../XSLT/$xslt_file -" if ($xslt_file ne "");
63 open (MultiMarkdown, "| cd \"$me\"; ./MultiMarkdown.pl | ./$SmartyPants $xslt");
65 print MultiMarkdown $data;
73 my ($inMetaData, $currentKey) = (1,'');
75 foreach my $line ( split /\n/, $text ) {
76 $line =~ /^$/ and $inMetaData = 0 and next;
78 if ($line =~ /^([a-zA-Z0-9][0-9a-zA-Z _-]*?):\s*(.*)$/ ) {
81 $currentKey =~ s/ //g;
82 $g_metadata{$currentKey} = $temp;
83 if (lc($currentKey) eq "xhtmlxslt") {
84 $g_metadata{$currentKey} =~ s/\s*(\.xslt)?\s*$/.xslt/;
85 return $g_metadata{$currentKey};
88 if ($currentKey eq "") {
103 my ($inMetaData, $currentKey) = (1,'');
105 foreach my $line ( split /\n/, $text ) {
106 $line =~ /^$/ and $inMetaData = 0 and next;
108 if ($line =~ /^([a-zA-Z0-9][0-9a-zA-Z _-]*?):\s*(.*)$/ ) {
110 $currentKey =~ s/ / /g;
111 $g_metadata{$currentKey} = $2;
112 if (lc($currentKey) eq "language") {
113 return $g_metadata{$currentKey};
116 if ($currentKey eq "") {
117 # No metadata present