Accept attributes in inline image syntax
[multimarkdown] / bin / xhtml2latex.pl
1 #!/usr/bin/env perl
2 #
3 # $Id: xhtml2latex.pl 481 2008-01-12 23:06:15Z fletcher $
4 #
5 # Required for using MultiMarkdown
6 #
7 # Copyright (c) 2006-2008 Fletcher T. Penney
8 #       <http://fletcherpenney.net/>
9 #
10 # MultiMarkdown Version 2.0.b5
11 #
12
13 # Combine all the steps necessary to process MultiMarkdown generated XHTML
14 # into LaTeX.  Not necessary, but might be easier than stringing the commands 
15 # together manually.
16
17
18 # Parse stdin (XHTML file)
19
20 undef $/;
21 $data .= <>;
22
23
24 # Find name of XSLT File if specified, else use xhtml2memoir.xslt
25 $xslt_file = _LatexXSLT($data);
26 $xslt_file = "memoir.xslt" if ($xslt_file eq "");
27
28
29 # Decide which flavor of SmartyPants to use
30 $language = _Language($data);
31 $SmartyPants = "SmartyPants.pl";
32
33 $SmartyPants = "SmartyPantsGerman.pl" if ($language =~ /^\s*german\s*$/i);
34
35 $SmartyPants = "SmartyPantsFrench.pl" if ($language =~ /^\s*french\s*$/i);
36
37 $SmartyPants = "SmartyPantsSwedish.pl" if ($language =~ /^\s*(swedish|norwegian|finnish|danish)\s*$/i);
38
39 $SmartyPants = "SmartyPantsDutch.pl" if ($language =~ /^\s*dutch\s*$/i);
40
41
42 # Create a pipe and process
43 $me = $0;                               # Where am I?
44
45 # Am I running in Windoze?
46 my $os = $^O;
47
48 if ($os =~ /MSWin/) {
49         $me =~ s/\\([^\\]*?)$/\\/;      # Get just the directory portion
50
51         open (MultiMarkdown, "| cd \"$me\"& .\\$SmartyPants | xsltproc -nonet -novalid ..\\XSLT\$xslt_file - | ..\\Utilities\\cleancites.pl");
52
53 } else {
54         $me =~ s/\/([^\/]*?)$/\//;      # Get just the directory portion
55
56         open (MultiMarkdown, "| cd \"$me\"; ./$SmartyPants | xsltproc -nonet -novalid ../XSLT/$xslt_file - | ../Utilities/cleancites.pl");
57 }
58
59
60 print MultiMarkdown $data;
61
62 close(MultiMarkdown);
63
64
65 sub _LatexXSLT {
66         my $text = shift;
67         
68         $text =~ /^\s*<meta name="latexxslt" content="(.*?)" \/>/mi;
69                 
70         return $1;
71 }
72
73 sub _Language {
74         my $text = shift;
75         
76         $text =~ /^\s*<meta name="language" content="(.*?)" \/>/mi;
77
78         return $1;
79 }