| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Text::MultiMarkdown qw(markdown); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 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 | <p><a href="http://fletcherpenney.net/What_is_MultiMarkdown">MultiMarkdown</a> <em>extends</em> the very well-known <a href="http://daringfireball.net/projects/markdown/">Markdown</a> syntax.</p> | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | If no file is specified, it will expect its input from STDIN: | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | $ echo "A **simple** test" | multimarkdown | ||||||||||||||||||||||||||||
| 31 | <p>A <strong>simple</strong> test</p> | ||||||||||||||||||||||||||||
| 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<hr> tag) to state they will not | ||||||||||||||||||||||||||||
| 49 | be closed, by closing with C</E<gt>>. HTML 4-style will plainly output | ||||||||||||||||||||||||||||
| 50 | the tag as it comes: | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | $ echo '---' | multimarkdown | ||||||||||||||||||||||||||||
| 53 | <hr /> | ||||||||||||||||||||||||||||
| 54 | $ echo '---' | multimarkdown --html4tags | ||||||||||||||||||||||||||||
| 55 | <hr> | ||||||||||||||||||||||||||||
| 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 <gwolf@debian.org> 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<Text::MultiMarkdown>, L<http://fletcherpenney.net/What_is_MultiMarkdown> | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =cut | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | #### Check for command-line switches: ################# | ||||||||||||||||||||||||||||
| 84 | 1 | my %cli_opts; | |||||||||||||||||||||||||||
| 85 | 1 | ▶ | use Getopt::Long; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 86 | 1 | Getopt::Long::Configure('pass_through'); | |||||||||||||||||||||||||||
| 87 | 1 | GetOptions(\%cli_opts, | |||||||||||||||||||||||||||
| 88 | 'version', | ||||||||||||||||||||||||||||
| 89 | 'shortversion', | ||||||||||||||||||||||||||||
| 90 | 'html4tags', | ||||||||||||||||||||||||||||
| 91 | 'help' | ||||||||||||||||||||||||||||
| 92 | ); | ||||||||||||||||||||||||||||
| 93 | 1 | ▶ | if ($cli_opts{'version'}) { # Version info | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 0 | print "\nThis is MultiMarkdown, version $Text::MultiMarkdown::VERSION.\n"; | |||||||||||||||||||||||||||
| 95 | 0 | print "Copyright 2004 John Gruber\n"; | |||||||||||||||||||||||||||
| 96 | 0 | print "Copyright 2006 Fletcher Penny\n"; | |||||||||||||||||||||||||||
| 97 | 0 | print "Copyright 2008 Tomas Doran\n"; | |||||||||||||||||||||||||||
| 98 | 0 | print "Parts contributed by several other people."; | |||||||||||||||||||||||||||
| 99 | 0 | print "http://fletcherpenney.net/MultiMarkdown/\n\n"; | |||||||||||||||||||||||||||
| 100 | 0 | exit 0; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | 1 | ▶ | if ($cli_opts{'shortversion'}) { # Just the version number string. | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 0 | print $Text::MultiMarkdown::VERSION; | |||||||||||||||||||||||||||
| 104 | 0 | exit 0; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | 1 | ▶ | if ($cli_opts{'help'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | 0 | for my $dir (split m/:/, $ENV{PATH}) { | |||||||||||||||||||||||||||
| 108 | 0 | my $cmd = "$dir/perldoc"; | |||||||||||||||||||||||||||
| 109 | 0 | ▶ | exec($cmd, $0) if (-f $cmd and -x $cmd); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-f $cmd and -x $cmd
MC/DC0%0/2
-f $cmd and -x $cmd
-f $cmd
-x $cmd
Truth table0%0/3
A and B
A= -f $cmdB= -x $cmd
| |||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | 0 | die "perldoc could not be found in your path - Cannot show help, sorry\n"; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | 1 | my $m; | |||||||||||||||||||||||||||
| 114 | 1 | ▶ | if ($cli_opts{'html4tags'}) { # Use HTML tag style instead of XHTML | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | 0 | $m = Text::MultiMarkdown->new(empty_element_suffix => '>'); | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | else { | ||||||||||||||||||||||||||||
| 118 | 1 | $m = Text::MultiMarkdown->new; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 1 | ▶ | sub main { | ||||||||||||||||||||||||||
|
Subroutine
main: called CC=6 SCAR=27.7
| |||||||||||||||||||||||||||||
| 122 | 1 | my (@fns) = @_; | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 1 | my $f; | |||||||||||||||||||||||||||
| 125 | 1 | ▶ | if (scalar @fns) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 0 | foreach my $fn (@fns) { | |||||||||||||||||||||||||||
| 127 | 0 | ▶ | die("Cannot find file $fn") unless (-r $fn); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 0 | my $fh; | |||||||||||||||||||||||||||
| 130 | 0 | ▶ | open($fh, '<', $fn) or die; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 0 | $f = join('', <$fh>); | |||||||||||||||||||||||||||
| 132 | 0 | ▶ | close($fh) or die; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | else { # STDIN | ||||||||||||||||||||||||||||
| 136 | 1 | local $/; # Slurp the whole file | |||||||||||||||||||||||||||
| 137 | 1 | $f = <>; | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 1 | return $m->markdown($f); | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 1 | ▶ | print main(@ARGV) unless caller(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||