File Coverage

blib/lib/Text/Layout/Markdown.pm
Criterion Covered Total %
statement 15 43 34.8
branch 0 8 0.0
condition 0 3 0.0
subroutine 5 9 55.5
pod 1 4 25.0
total 21 67 31.3


line stmt bran cond sub pod time code
1             #! perl
2              
3 1     1   825 use strict;
  1         1  
  1         24  
4 1     1   5 use warnings;
  1         1  
  1         20  
5 1     1   4 use utf8;
  1         2  
  1         5  
6 1     1   17 use Carp;
  1         1  
  1         49  
7              
8             package Text::Layout::Markdown;
9              
10 1     1   378 use parent 'Text::Layout';
  1         277  
  1         5  
11              
12             #### API
13             sub new {
14 0     0 1   my ( $pkg, @data ) = @_;
15 0           my $self = $pkg->SUPER::new;
16 0           $self->{_currentfont} = { family => 'default',
17             style => 'normal',
18             weight => 'normal' };
19 0           $self->{_currentcolor} = 'black';
20 0           $self->{_currentsize} = 12;
21 0           $self;
22             }
23              
24             #### API
25             sub render {
26 0     0 0   my ( $self ) = @_;
27 0           my $res = "";
28 0           foreach my $fragment ( @{ $self->{_content} } ) {
  0            
29 0 0         next unless length($fragment->{text});
30 0   0       my $f = $fragment->{font} || $self->{_currentfont};
31 0           my $open = "";
32 0           my $close = "";
33 0 0         if ( $f->{style} eq "italic" ) {
34 0           $open = $close = "_"
35             }
36 0 0         if ( $f->{weight} eq "bold" ) {
37 0           $open = "**$open";
38 0           $close = "$close**";
39             }
40              
41 0 0         if ( $res =~ /(.*)\Q$close\E$/ ) {
42 0           $res = $1;
43 0           $open = "";
44             }
45 0           $res .= $open . $fragment->{text} . $close;
46             }
47 0           $res;
48             }
49              
50             #### API
51             sub bbox {
52 0     0 0   my ( $self ) = @_;
53 0           [ 0, -5, 10, 15 ]; # dummy
54             }
55              
56             #### API
57             sub load_font {
58 0     0 0   my ( $self, $description ) = @_;
59 0           return $description;
60             }
61              
62              
63             1;