File Coverage

blib/lib/Text/Markup/Markdown.pm
Criterion Covered Total %
statement 29 29 100.0
branch 6 8 75.0
condition n/a
subroutine 8 8 100.0
pod 0 1 0.0
total 43 46 93.4


line stmt bran cond sub pod time code
1             package Text::Markup::Markdown;
2              
3 1     1   5137 use 5.8.1;
  1         3  
4 1     1   4 use strict;
  1         1  
  1         18  
5 1     1   3 use warnings;
  1         1  
  1         58  
6 1     1   4 use Text::Markup;
  1         1  
  1         38  
7 1     1   3 use File::BOM qw(open_bom);
  1         2  
  1         88  
8 1     1   5 use Text::Markdown::Discount;
  1         2  
  1         288  
9              
10             our $VERSION = '0.41';
11              
12             sub import {
13             # Replace the regex if passed one.
14 3 100   3   37 Text::Markup->register( markdown => $_[1] ) if $_[1];
15             }
16              
17             sub parser {
18 2     2 0 7 my ($file, $encoding, $opts) = @_;
19 2         5 my %params = @{ $opts };
  2         6  
20              
21 2 50       7 unless (defined $params{flags}) {
22 2         6 $params{flags} = Text::Markdown::Discount::MKD_NOHEADER
23             | Text::Markdown::Discount::MKD_TOC
24             | Text::Markdown::Discount::MKD_DLEXTRA
25             | Text::Markdown::Discount::MKD_FENCEDCODE
26             | Text::Markdown::Discount::MKD_EXTRA_FOOTNOTE
27             | Text::Markdown::Discount::MKD_IDANCHOR;
28             }
29 2         14 open_bom my $fh, $file, ":encoding($encoding)";
30 2         2320 my $html = Text::Markdown::Discount::markdown(join('', <$fh>), $params{flags});
31 2 100       353 return unless $html =~ /\S/;
32 1         4 utf8::encode($html);
33 1 50       3 return $html if $params{raw};
34 1         27 return qq{
35            
36            
37            
38            
39             $html
40            
41            
42             };
43              
44             }
45              
46             1;
47             __END__