File Coverage

script/MultiMarkdown.pl
Criterion Covered Total %
statement 18 24 75.0
branch 1 8 12.5
condition n/a
subroutine 5 5 100.0
pod n/a
total 24 37 64.8


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2 1     1   736 use strict;
  1         2  
  1         30  
3 1     1   10 use warnings;
  1         1  
  1         29  
4 1     1   612 use Text::MultiMarkdown qw(markdown);
  1         3  
  1         87  
5              
6             =head1 NAME
7              
8             MultiMarkdown.pl - Convert MultiMarkdown syntax to (X)HTML
9              
10             =head1 DESCRIPTION
11              
12             This program is distributed as part of Perl's Text::MultiMarkdown module,
13             illustrating sample usage.
14              
15             MultiMarkdown.pl can be invoked on any file containing MultiMarkdown-syntax, and
16             will produce the corresponding (X)HTML on STDOUT:
17              
18             $ cat file.txt
19             [MultiMarkdown][] *extends* the very well-known [Markdown][] syntax.
20              
21             [MultiMarkdown]: http://fletcherpenney.net/What_is_MultiMarkdown
22             [Markdown]: http://daringfireball.net/projects/markdown/
23              
24             $ multimarkdown file.txt
25            

MultiMarkdown extends the very well-known Markdown syntax.

26              
27              
28             If no file is specified, it will expect its input from STDIN:
29              
30             $ echo "A **simple** test" | multimarkdown
31            

A simple test

32              
33             =head1 OPTIONS
34              
35             =over
36              
37             =item version
38              
39             Shows the full information for this version
40              
41             =item shortversion
42              
43             Shows only the version number
44              
45             =item html4tags
46              
47             Produce HTML 4-style tags instead of XHTML - XHTML requires elements
48             that do not wrap a block (i.e. the C
tag) to state they will not
49             be closed, by closing with C>. HTML 4-style will plainly output
50             the tag as it comes:
51              
52             $ echo '---' | multimarkdown
53            
54             $ echo '---' | multimarkdown --html4tags
55            
56              
57             =item help
58              
59             Shows this documentation
60              
61             =back
62              
63             =head1 AUTHOR
64              
65             Copyright 2004 John Gruber
66              
67             Copyright 2006 Fletcher Penny
68              
69             Copyright 2008 Tomas Doran
70              
71             The manpage was written by Gunnar Wolf for its use
72             in Debian systems, but can be freely used elsewhere.
73              
74             For full licensing information, please refer to
75             Text::MultiMarkdown.pm's full documentation.
76              
77             =head1 SEE ALSO
78              
79             L, L
80              
81             =cut
82              
83             #### Check for command-line switches: #################
84             my %cli_opts;
85 1     1   778 use Getopt::Long;
  1         10773  
  1         4  
86             Getopt::Long::Configure('pass_through');
87             GetOptions(\%cli_opts,
88             'version',
89             'shortversion',
90             'html4tags',
91             'help'
92             );
93             if ($cli_opts{'version'}) { # Version info
94             print "\nThis is MultiMarkdown, version $Text::MultiMarkdown::VERSION.\n";
95             print "Copyright 2004 John Gruber\n";
96             print "Copyright 2006 Fletcher Penny\n";
97             print "Copyright 2008 Tomas Doran\n";
98             print "Parts contributed by several other people.";
99             print "http://fletcherpenney.net/MultiMarkdown/\n\n";
100             exit 0;
101             }
102             if ($cli_opts{'shortversion'}) { # Just the version number string.
103             print $Text::MultiMarkdown::VERSION;
104             exit 0;
105             }
106             if ($cli_opts{'help'}) {
107             for my $dir (split m/:/, $ENV{PATH}) {
108             my $cmd = "$dir/perldoc";
109             exec($cmd, $0) if (-f $cmd and -x $cmd);
110             }
111             die "perldoc could not be found in your path - Cannot show help, sorry\n";
112             }
113             my $m;
114             if ($cli_opts{'html4tags'}) { # Use HTML tag style instead of XHTML
115             $m = Text::MultiMarkdown->new(empty_element_suffix => '>');
116             }
117             else {
118             $m = Text::MultiMarkdown->new;
119             }
120              
121             sub main {
122 1     1   553 my (@fns) = @_;
123            
124 1         3 my $f;
125 1 50       3 if (scalar @fns) {
126 0         0 foreach my $fn (@fns) {
127 0 0       0 die("Cannot find file $fn") unless (-r $fn);
128              
129 0         0 my $fh;
130 0 0       0 open($fh, '<', $fn) or die;
131 0         0 $f = join('', <$fh>);
132 0 0       0 close($fh) or die;
133             }
134             }
135             else { # STDIN
136 1         3 local $/; # Slurp the whole file
137 1         145 $f = <>;
138             }
139            
140 1         8 return $m->markdown($f);
141             }
142              
143             print main(@ARGV) unless caller();