Markup/CommonMark.pm untested

filter: Statementstmt 0.0% 0 / 30 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 49 CC 3 SCAR 16.1
CC
3
Cov
0%
parser
12.0
import
2.0
BEGIN
2.0
CRAP 5.0
1 package Text::Markup::CommonMark;
2  
3 use 5.8.1;
4 use strict;
5 use warnings;
6 use CommonMark;
7 use Text::Markup;
8 use File::BOM qw(open_bom);
9  
10 our $VERSION = '0.43';
11  
12 sub import {
13 # Replace Text::Markup::Markdown.
14 Text::Markup->register( markdown => $_[1] || qr{m(?:d(?:own)?|kdn?|arkdown)} );
15 }
16  
17 sub parser {
18 my ($file, $encoding, $opts) = @_;
19 open_bom my $fh, $file, ":encoding($encoding)";
20 my %params = @{ $opts };
21 my $html = CommonMark->parse(
22 smart => 1,
23 unsafe => 1,
24 %params,
25 string => join( '', <$fh>),
26 )->render( %params, format => 'html' );
27 return unless $html =~ /\S/;
28 utf8::encode($html);
29 return $html if $params{raw};
30 return qq{<html>
31 <head>
32 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
33 </head>
34 <body>
35 $html
36 </body>
37 </html>
38 };
39  
40 }
41  
42 1;
43 __END__