MetaMarkup/HTML.pm untested

filter: Statementstmt 0.0% 0 / 26 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 52 CC 5 SCAR 18.2
CC
5
Cov
0%
paragraph
12.0
escape
6.0
link
6.0
CRAP 6.2
1 package Text::MetaMarkup::HTML;
2 use base 'Text::MetaMarkup';
3 use strict;
4  
5 sub escape {
6 my ($self, $text) = @_;
7 return if not defined $text;
8 $text =~ s/([&<>"])/sprintf '&#%d;', ord $1/ge;
9 return $text;
10 }
11  
12 sub paragraph_style {
13 my ($self, $tag, $text) = @_;
14 return "<$tag>$text</$tag>\n\n";
15 }
16  
17 sub paragraph {
18 my ($self, $tag, $text) = @_;
19 $text =~ /^--/ and return '<hr>';
20
21 if ($text =~ /^\*/) {
22 $tag = 'ul';
23 $text =~ s/^\*\s*(.*(?:\n[^*].*)*)/{li:$1}/gm;
24 }
25 $tag ||= 'p';
26 my $r = $self->parse_paragraph_text($text);
27 return $r =~ /\n/
28 ? "<$tag>\n$r\n</$tag>\n\n"
29 : "<$tag>$r</$tag>\n\n";
30 }
31  
32 sub inline {
33 my ($self, $tag, $text) = @_;
34 return "<$tag>" . $self->parse_paragraph_text($text) . "</$tag>";
35 }
36  
37 sub link {
38 my ($self, $href, $text) = @_;
39 $href = $self->escape($href->{href});
40 return sprintf
41 q[<a href="%s">%s</a>],
42 $href,
43 $self->parse_paragraph_text(defined $text ? $text : $href);
44 }
45  
46 1;
47  
48 __END__