File Coverage

blib/lib/Pod/Simple/Role/XHTML/WithHighlightConfig.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1             package Pod::Simple::Role::XHTML::WithHighlightConfig;
2 1     1   492045 use Moo::Role;
  1         3  
  1         8  
3              
4             our $VERSION = '0.004000';
5             $VERSION =~ tr/_//d;
6              
7 1     1   703 use HTML::Entities qw(encode_entities);
  1         4  
  1         100  
8              
9 1     1   543 use namespace::clean;
  1         19687  
  1         9  
10              
11             with 'Pod::Simple::Role::WithHighlightConfig';
12              
13             around start_highlight => sub {
14             my ($orig, $self, $item, $config) = @_;
15             $self->$orig($item, $config);
16             $config ||= {};
17             my $tag = '
18             my @classes;
19             if ($config->{line_numbers}) {
20             push @classes, 'line-numbers';
21             if ($config->{start_line}) {
22             $tag .= ' data-start="' . encode_entities($config->{start_line}) . '"';
23             }
24             }
25             if ($config->{highlight}) {
26             $tag .= ' data-line="' . encode_entities($config->{highlight}) . '"';
27             }
28             if (@classes) {
29             $tag .= ' class="' . join (' ', @classes) . '"';
30             }
31             $tag .= '>
32             if ($config->{language}) {
33             my $lang = lc $config->{language};
34             $lang =~ s/\+/p/g;
35             $lang =~ s/\W//g;
36             $tag .= ' class="language-' . $lang . '"';
37             }
38             $tag .= '>';
39             $self->{scratch} = $tag;
40             };
41              
42             1;
43             __END__