lib/Markdown/Parser.pm

filter: Statementstmt 13.4% 161 / 1199 Branchbran 9.2% 55 / 594 Conditioncond 7.4% 20 / 268 MC/DCmcdc 2.1% 3 / 137 Subroutinesub 46.2% 37 / 80 Podpod 100% 29 / 29 totaltotal 13.2% 305 / 2307 CC 409 SCAR 90.9
CC
409
Cov
11%
parse
24492.0
__ANON__
3925.9
parse_table_row
1260.0
CRAP 8829.5
↑ Summary lib/Markdown/Parser/Document.pm »
1 ##----------------------------------------------------------------------------
2 ## Markdown Parser Only - ~/lib/Markdown/Parser.pm
3 ## Version v0.3.2
4 ## Copyright(c) 2022 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/08/23
7 ## Modified 2023/08/29
8 ## All rights reserved
9 ##
10 ## This program is free software; you can redistribute it and/or modify it
11 ## under the same terms as Perl itself.
12 ##----------------------------------------------------------------------------
13 package Markdown::Parser;
14 BEGIN
15 {
16 2 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶ use vars qw( $ELEMENTS_DICTIONARY $ELEMENTS_DICTIONARY_EXTENDED $VERSION $DEBUG );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶ use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶ use Regexp::Common qw( Markdown );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 ▶ use Nice::Try;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 ▶ use CSS::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 ▶ use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
25 2 ▶ use Devel::Confess;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 2 ▶ our $DEBUG = 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 2 our $VERSION = 'v0.3.2';
28 # Including vertical space like new lines
29 2 our $ELEMENTS_DICTIONARY =
30 {
31 block => [qw( blockquote code_block code_line header html line list paragraph )],
32 inline => [qw( abbr bold code_span emphasis image link_auto line_break link )],
33 };
34 2 $ELEMENTS_DICTIONARY->{all} = [@{$ELEMENTS_DICTIONARY->{block}}, @{$ELEMENTS_DICTIONARY->{inline}}];
35 2 our $ELEMENTS_DICTIONARY_EXTENDED =
36 {
37 block => [qw( code_block header katex )],
38 inline => [qw( abbr checkbox footnote insert katex strikethrough superscript subscript )],
39 };
40 2 $ELEMENTS_DICTIONARY_EXTENDED->{all} = [@{$ELEMENTS_DICTIONARY_EXTENDED->{block}}, @{$ELEMENTS_DICTIONARY_EXTENDED->{inline}}];
41 };
42  
43 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
45  
46 sub init
47 {
48 2 ▶ my $self = shift( @_ );
Subroutine init: called CC=1 SCAR=0.0
Pod documented
49 2 $self->{abbreviation_case_sensitive} = 0;
50 2 $self->{charset} = 'utf8';
51 2 $self->{code_highlight} = 0;
52 2 $self->{css_grid} = 0;
53 2 $self->{debug} = $DEBUG;
54 # See Markdown::Parser::Link
55 2 $self->{default_email} = '';
56 2 $self->{document} = '';
57 2 $self->{email_obfuscate_class} = 'courriel';
58 2 $self->{email_obfuscate_data_host} = 'host';
59 2 $self->{email_obfuscate_data_user} = 'user';
60 2 $self->{encrypt_email} = 0;
61 2 $self->{footnote_ref_sequence} = 0;
62 2 $self->{callback} = undef;
63 2 $self->{katex_delimiter} = ['$$','$$','$','$','\[','\]','\(','\)'];
64 2 $self->{list_level} = 0;
65 2 $self->{mode} = 'all';
66 ## Top scope as specified by the user
67 2 $self->{scope} = '';
68 2 $self->{_init_strict_use_sub} = 1;
69 2 ▶ use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
70 2 $self->{colour_open} = '{';
71 2 $self->{colour_close} = '}';
72 2 $self->SUPER::init( @_ );
73 2 return( $self );
74 }
75  
76 1 ▶sub abbreviation_case_sensitive { return( shift->_set_get_scalar( 'abbreviation_case_sensitive', @_ ) ); }
Subroutine abbreviation_case_sensitive: called CC=1 SCAR=0.0
Pod documented
77  
78 0 ▶sub callback { return( shift->_set_get_code( 'callback', @_ ) ); }
Subroutine callback: not called CC=1 SCAR=6.9
Pod documented
79  
80 0 ▶sub charset { return( shift->_set_get_scalar( 'charset', @_ ) ); }
Subroutine charset: not called CC=1 SCAR=6.9
Pod documented
81  
82 0 ▶sub code_highlight { return( shift->_set_get_boolean( 'code_highlight', @_ ) ); }
Subroutine code_highlight: not called CC=1 SCAR=6.9
Pod documented
83  
84 sub create_document
85 {
86 1 ▶ my $self = shift( @_ );
Subroutine create_document: called CC=3 SCAR=11.8
Pod documented
87 1 ▶ my $class = ref( $self ) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
100
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
88 1 $class .= '::Document';
89 1 ▶ $self->_load_class( $class ) || return;
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class($class) or return 0 1 1
90 1 return( $class->new( @_, debug => $self->debug ) );
91 }
92  
93 sub css
94 {
95 1 ▶ my $self = shift( @_ );
Subroutine css: called CC=2 SCAR=7.0
Pod documented
96 1 my $css = $self->_set_get_object( 'css', 'CSS::Object', @_ );
97 1 ▶ return( $css ) if( $css );
Branch: 1 branch
BranchTrueFalseTotal
if $css 0 1 1
98 1 $css = CSS::Object->new;
99 1 $self->_set_get_object( 'css', 'CSS::Object', $css );
100 1 return( $css );
101 }
102  
103 0 ▶sub css_builder { return( shift->css->builder ); }
Subroutine css_builder: not called CC=1 SCAR=6.9
Pod documented
104  
105 0 ▶sub css_grid { return( shift->_set_get_boolean( 'css_grid', @_ ) ); }
Subroutine css_grid: not called CC=1 SCAR=6.9
Pod documented
106  
107 1 ▶sub default_email { return( shift->_set_get_scalar_as_object( 'default_email', @_ ) ); }
Subroutine default_email: called CC=1 SCAR=0.0
Pod documented
108  
109 2 ▶sub document { return( shift->_set_get_object( 'document', 'Markdown::Parser::Document', @_ ) ); }
Subroutine document: called CC=1 SCAR=0.0
Pod documented
110  
111 1 ▶sub email_obfuscate_class { return( shift->_set_get_scalar_as_object( 'email_obfuscate_class', @_ ) ); }
Subroutine email_obfuscate_class: called CC=1 SCAR=0.0
Pod documented
112  
113 sub email_obfuscate_data_host
114 {
115 1 ▶ my $self = shift( @_ );
Subroutine email_obfuscate_data_host: called CC=3 SCAR=16.0
Pod documented
116 1 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 1 1
117 {
118 0 ▶ if( $_[0] =~ /^[a-zA-Z]\w+$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /^[a-zA-Z]\w+$/) { } 0 0 0
119 {
120 0 return( $self->_set_get_scalar_as_object( 'email_obfuscate_data_host', @_ ) );
121 }
122 else
123 {
124 0 return( $self->error( "Invalid value \"$_[0]\" for the email obfuscation data-host attribute name." ) );
125 }
126 }
127 1 return( $self->_set_get_scalar_as_object( 'email_obfuscate_data_host' ) );
128 }
129  
130 sub email_obfuscate_data_user
131 {
132 1 ▶ my $self = shift( @_ );
Subroutine email_obfuscate_data_user: called CC=3 SCAR=16.0
Pod documented
133 1 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 1 1
134 {
135 0 ▶ if( $_[0] =~ /^[a-zA-Z]\w+$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /^[a-zA-Z]\w+$/) { } 0 0 0
136 {
137 0 return( $self->_set_get_scalar_as_object( 'email_obfuscate_data_user', @_ ) );
138 }
139 else
140 {
141 0 return( $self->error( "Invalid value \"$_[0]\" for the email obfuscation data-user attribute name." ) );
142 }
143 }
144 1 return( $self->_set_get_scalar_as_object( 'email_obfuscate_data_user' ) );
145 }
146  
147 0 ▶sub encrypt_email { return( shift->_set_get_scalar_as_object( 'encrypt_email', @_ ) ); }
Subroutine encrypt_email: not called CC=1 SCAR=6.9
Pod documented
148  
149 0 ▶sub footnote_ref_sequence : lvalue { return( shift->_set_get_lvalue( 'footnote_ref_sequence', @_ ) ); }
Subroutine footnote_ref_sequence: not called CC=1 SCAR=6.9
Pod documented
150  
151 sub from_html
152 {
153 1 ▶ my $self = shift( @_ );
Subroutine from_html: called CC=4 SCAR=21.5
Pod documented
154 1 ▶ my $html = shift( @_ ) || return( $self->error( "No HTML::Object::Document was provided." ) );
Condition50%1/2
shift @_ || (return $self->error('No HTML::Object::Document was provided.'))
l!l
10
MC/DC0%0/1
shift @_ || (return $self->error('No HTML::Object::Document was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
155 1 ▶ if( !$self->_is_a( $html => 'HTML::Object::Document' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_a($html, "HTML::Object::Document")) 0 1 1
156 {
157 0 return( $self->error( "Value provided (", overload::StrVal( $html ), ") is not an HTML::Object::Document object." ) );
158 }
159  
160 1 my $doc = $self->create_document(
161 abbreviation_case_sensitive => $self->abbreviation_case_sensitive,
162 default_email => $self->default_email,
163 email_obfuscate_class => $self->email_obfuscate_class,
164 email_obfuscate_data_host => $self->email_obfuscate_data_host,
165 email_obfuscate_data_user => $self->email_obfuscate_data_user,
166 css => $self->css,
167 debug => $self->debug,
168 tag_name => 'top',
169 );
170 # Sharing the parameter
171 1 $doc->katex_delimiter( $self->katex_delimiter );
172 1 ▶ $self->document( $doc ) if( !$self->document );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->document 1 0 1
173
174 1 my $seen = {};
175 1 my $crawl;
176 $crawl = sub
177 {
178 19 ▶ my $e = shift( @_ );
Subroutine __ANON__: called CC=109 SCAR=82.8
179 # Markdown Element
180 19 my $me = shift( @_ );
181 19 my $addr = Scalar::Util::refaddr( $e );
182 # Duplicate
183 19 ▶ return if( ++$seen->{ $addr } > 1 );
Branch: 1 branch
BranchTrueFalseTotal
if ++$seen->{$addr} > 1 0 19 19
184 19 my $tag = $e->tag;
185 19 my $top;
186 19 ▶ if( $tag eq 'abbr' )
Branch: 27 branches
BranchTrueFalseTotal
if ($tag eq 'abbr') { } 0 19 19
elsif ($tag eq 'blockquote') { } 0 19 19
elsif ($tag eq 'b') { } 0 19 19
elsif ($tag eq 'checkbox') { } 0 19 19
elsif ($tag eq 'code') { } 1 18 19
elsif ($tag eq 'em') { } 0 18 18
elsif ($tag eq 'h1' or $tag eq 'h2' or $tag eq 'h3' or $tag eq 'h4' or $tag eq 'h5' or $tag eq 'h6') { } 0 18 18
elsif ($tag eq 'img') { } 0 18 18
elsif ($tag eq 'ins') { } 1 17 18
elsif ($tag eq 'hr') { } 0 17 17
elsif ($tag eq 'a') { } 1 16 17
elsif ($tag eq 'ul' or $tag eq 'ol') { } 0 16 16
elsif ($tag eq 'li') { } 0 16 16
elsif ($tag eq 'br') { } 0 16 16
elsif ($tag eq 'p') { } 1 15 16
elsif ($tag eq 's' or $tag eq 'del') { } 1 14 15
elsif ($tag eq 'sub') { } 0 14 14
elsif ($tag eq 'sup') { } 0 14 14
elsif ($tag eq 'table') { } 0 14 14
elsif ($tag eq 'tbody') { } 0 14 14
elsif ($tag eq 'thead') { } 0 14 14
elsif ($tag eq 'tr') { } 0 14 14
elsif ($tag eq 'td') { } 0 14 14
elsif ($tag eq 'th') { } 0 14 14
elsif ($tag eq 'caption') { } 0 14 14
elsif ($tag eq '_text' or $tag eq '_space') { } 12 2 14
elsif ($tag eq '_document') { } 1 1 2
187 {
188 0 my $name = $e->content->map( $_->as_string )->scalar;
189 0 my $val = $e->attr( 'title' );
190 0 ▶ my $elem = $doc->create_abbreviation({
Condition0%0/2
$doc->create_abbreviation({'name', $name, 'value', $val}) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$doc->create_abbreviation({'name', $name, 'value', $val}) || (return $self->pass_error)
$doc->create_abbreviation({'name', $name, 'value', $val})
Truth table0%0/2
A
A= $doc->create_abbreviation({'name', $name, 'value', $val})
Aresult
11
00
191 name => $name,
192 value => $val,
193 }) || return( $self->pass_error );
194 0 ▶ $me->add_element( $elem ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$me->add_element($elem) or return $self->pass_error 0 0 0
195 }
196 elsif( $tag eq 'blockquote' )
197 {
198 0 ▶ $top = $doc->create_blockquote || return( $self->pass_error );
Condition0%0/2
$doc->create_blockquote || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$doc->create_blockquote || (return $self->pass_error)
$doc->create_blockquote
Truth table0%0/2
A
A= $doc->create_blockquote
Aresult
11
00
199 0 ▶ $me->add_element( $top ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$me->add_element($top) or return $self->pass_error 0 0 0
200 }
201 elsif( $tag eq 'b' )
202 {
203 0 ▶ $top = $doc->create_bold || return( $self->pass_error );
Condition0%0/2
$doc->create_bold || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$doc->create_bold || (return $self->pass_error)
$doc->create_bold
Truth table0%0/2
A
A= $doc->create_bold
Aresult
11
00
204 0 ▶ $me->add_element( $top ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$me->add_element($top) or return $self->pass_error 0 0 0
205 }
206 elsif( $tag eq 'checkbox' )
207 {
208 0 ▶ $top = $doc->create_checkbox({
Condition0%0/2
$doc->create_checkbox({'checked', $e->attributes->exists('checked'), 'disabled', $e->attributes->exists('disabled')}) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$doc->create_checkbox({'checked', $e->attributes->exists('checked'), 'disabled', $e->attributes->exists('disabled')}) || (return $self->pass_error)
$doc->create_checkbox({'checked', $e->attributes->exists('checked'), 'disabled', $e->attributes->exists('disabled')})
Truth table0%0/2
A
A= $doc->create_checkbox({'checked', $e->attributes->exists('checked'), 'disabled', $e->attributes->exists('disabled')})
Aresult
11
00
209 checked => $e->attributes->exists( 'checked' ),
210 disabled => $e->attributes->exists( 'disabled' ),
211 }) || return( $self->pass_error );
212 0 ▶ $me->add_element( $top ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$me->add_element($top) or return $self->pass_error 0 0 0
213 }
214 elsif( $tag eq 'code' )
215 {
216 1 ▶ my $test_str = $e->children->map(sub{ $_->as_string })->join( '' )->scalar;
Subroutine __ANON__: called CC=1 SCAR=0.0
217 1 ▶ my $is_fenced = ( CORE::index( $test_str, "\n" ) != -1 ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
(index($test_str, "\n") != -1) ? : 0 1 1
218 1 ▶ $top = $doc->create_code({
Condition50%1/2
$doc->create_code({'fenced', $is_fenced, 'inline', !$is_fenced}) || (return $self->pass_error)
l!l
10
MC/DC0%0/1
$doc->create_code({'fenced', $is_fenced, 'inline', !$is_fenced}) || (return $self->pass_error)
$doc->create_code({'fenced', $is_fenced, 'inline', !$is_fenced})
Truth table50%1/2
A
A= $doc->create_code({'fenced', $is_fenced, 'inline', !$is_fenced})
Aresult
11
00
219 fenced => $is_fenced,
220 inline => !$is_fenced,
221 }) || return( $self->pass_error );
222 1 ▶ $me->add_element( $top ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$me->add_element($top) or return $self->pass_error 0 1 1
223 }
224 elsif( $tag eq 'em' )
225 {
226 0 ▶ $top = $doc->create_em || return( $self->pass_error );
Condition0%0/2
$doc->create_em || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$doc->create_em || (return $self->pass_error)
$doc->create_em
Truth table0%0/2
A
A= $doc->create_em
Aresult
11
00
227 0 ▶ $me->add_element( $top ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$me->add_element($top) or return $self->pass_error 0 0 0
228 }
229 ▶ elsif( $tag eq 'h1' ||
Condition33%5/15
$tag eq "h1" or $tag eq "h2" or $tag eq "h3" or $tag eq "h4" or $tag eq "h5" or $tag eq "h6"
l!l&&r!l&&!r
0018
$tag eq "h1" or $tag eq "h2" or $tag eq "h3" or $tag eq "h4" or $tag eq "h5"
l!l&&r!l&&!r
0018
$tag eq "h1" or $tag eq "h2" or $tag eq "h3" or $tag eq "h4"
l!l&&r!l&&!r
0018
$tag eq "h1" or $tag eq "h2" or $tag eq "h3"
l!l&&r!l&&!r
0018
$tag eq "h1" or $tag eq "h2"
l!l&&r!l&&!r
0018
MC/DC0%0/6
$tag eq "h1" or $tag eq "h2" or $tag eq "h3" or $tag eq "h4" or $tag eq "h5" or $tag eq "h6"
$tag eq "h1" $tag eq "h2" $tag eq "h3" $tag eq "h4" $tag eq "h5" $tag eq "h6"
Truth table14%1/7
A or B or C or D or E or F
A= $tag eq "h1"B= $tag eq "h2"C= $tag eq "h3"D= $tag eq "h4"E= $tag eq "h5"F= $tag eq "h6"
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
00001X1
0000011
0000000
230 $tag eq 'h2' ||
231 $tag eq 'h3' ||
232 $tag eq 'h4' ||
233 $tag eq 'h5' ||
234 $tag eq 'h6' )
235 {
236 0 my $level = int( substr( $tag, -1, 1 ) );
237 0 ▶ $top = $doc->create_header({ level => $level }) || return( $self->pass_error );
Condition0%0/2
$doc->create_header({'level', $level}) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$doc->create_header({'level', $level}) || (return $self->pass_error)
$doc->create_header({'level', $level})
Truth table0%0/2
A
A= $doc->create_header({'level', $level})
Aresult
11
00
238 0 ▶ $me->add_element( $top ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$me->add_element($top) or return $self->pass_error 0 0 0
239 }
240 elsif( $tag eq 'img' )
241 {
242 0 ▶ $top = $doc->create_image({
Branch: 4 branches
BranchTrueFalseTotal
$e->attr('alt') ? : 0 0 0
$e->attr('id') ? : 0 0 0
$e->attr('title') ? : 0 0 0
$e->attr('src') ? : 0 0 0
Condition0%0/2
$doc->create_image({$e->attr('alt') ? ('alt', $e->attr('alt')) : (), $e->attr('id') ? ('id', $e->attr('id')) : (), $e->attr('title') ? ('title', $e->attr('title')) : (), $e->attr('src') ? ('url', $e->attr('src')) : ()}) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$doc->create_image({$e->attr('alt') ? ('alt', $e->attr('alt')) : (), $e->attr('id') ? ('id', $e->attr('id')) : (), $e->attr('title') ? ('title', $e->attr('title')) : (), $e->attr('src') ? ('url', $e->attr('src')) : ()}) || (return $self->pass_error)
$doc->create_image({$e->attr('alt') ? ('alt', $e->attr('alt')) : (), $e->attr('id') ? ('id', $e->attr('id')) : (), $e->attr('title') ? ('title', $e->attr('title')) : (), $e->attr('src') ? ('url', $e->attr('src')) : ()})
Truth table0%0/2
A
A= $doc->create_image({$e->attr('alt') ? ('alt', $e->attr('alt')) : (), $e->attr('id') ? ('id', $e->attr('id')) : (), $e->attr('title') ? ('title', $e->attr('title')) : (), $e->attr('src') ? ('url', $e->attr('src')) : ()})
Aresult
11
00
243 ( $e->attr( 'alt' ) ? ( alt => $e->attr( 'alt' ) ) : () ),
244 ( $e->attr( 'id' ) ? ( id => $e->attr( 'id' ) ) : () ),
245 ( $e->attr( 'title' ) ? ( title => $e->attr( 'title' ) ) : () ),
246 ( $e->attr( 'src' ) ? ( url => $e->attr( 'src' ) ) : () ),
247 }) || return( $self->pass_error );
248 0 ▶ $me->add_element( $top ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$me->add_element($top) or return $self->pass_error 0 0 0
249 }
250 elsif( $tag eq 'ins' )
251 {
252 1 ▶ $top = $doc->create_insertion || return( $self->pass_error );
Condition50%1/2
$doc->create_insertion || (return $self->pass_error)
l!l
10
MC/DC0%0/1
$doc->create_insertion || (return $self->pass_error)
$doc->create_insertion
Truth table50%1/2
A
A= $doc->create_insertion
Aresult
11
00
253 1 ▶ $me->add_element( $top ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$me->add_element($top) or return $self->pass_error 0 1 1
254 }
255 elsif( $tag eq 'hr' )
256 {
257 # <hr> cannot have children so use $elem instead of $top
258 0 ▶ my $elem = $doc->create_line || return( $self->pass_error );
Condition0%0/2
$doc->create_line || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$doc->create_line || (return $self->pass_error)
$doc->create_line
Truth table0%0/2
A
A= $doc->create_line
Aresult
11
00
259 0 ▶ $me->add_element( $elem ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$me->add_element($elem) or return $self->pass_error 0 0 0
260 }
261 elsif( $tag eq 'a' )
262 {
263 1 ▶ if( $e->attr( 'href' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($e->attr("href")) 1 0 1
264 {
265 1 ▶ $top = $doc->create_link({
Branch: 3 branches
BranchTrueFalseTotal
$e->attr('name') ? : 0 1 1
$e->attr('id') ? : 0 1 1
$e->attr('title') ? : 0 1 1
Condition50%1/2
$doc->create_link({$e->attr('name') ? ('name', $e->attr('name')) : (), $e->attr('id') ? ('id', $e->attr('id')) : (), $e->attr('title') ? ('title', $e->attr('title')) : (), 'url', $e->attr('href')}) || (return $self->pass_error)
l!l
10
MC/DC0%0/1
$doc->create_link({$e->attr('name') ? ('name', $e->attr('name')) : (), $e->attr('id') ? ('id', $e->attr('id')) : (), $e->attr('title') ? ('title', $e->attr('title')) : (), 'url', $e->attr('href')}) || (return $self->pass_error)
$doc->create_link({$e->attr('name') ? ('name', $e->attr('name')) : (), $e->attr('id') ? ('id', $e->attr('id')) : (), $e->attr('title') ? ('title', $e->attr('title')) : (), 'url', $e->attr('href')})
Truth table50%1/2
A
A= $doc->create_link({$e->attr('name') ? ('name', $e->attr('name')) : (), $e->attr('id') ? ('id', $e->attr('id')) : (), $e->attr('title') ? ('title', $e->attr('title')) : (), 'url', $e->attr('href')})
Aresult
11
00
266 ( $e->attr( 'name' ) ? ( name => $e->attr( 'name' ) ) : () ),
267 ( $e->attr( 'id' ) ? ( id => $e->attr( 'id' ) ) : () ),
268 ( $e->attr( 'title' ) ? ( title => $e->attr( 'title' ) ) : () ),
269 url => $e->attr( 'href' ),
270 }) || return( $self->pass_error );
271 1 ▶ $me->add_element( $top ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$me->add_element($top) or return $self->pass_error 0 1 1
272 }
273 # else, an anchor, and we ignore it, and move on to add it possible children directly here at the same level
274 }
275 ▶ elsif( $tag eq 'ul' ||
Condition33%1/3
$tag eq "ul" or $tag eq "ol"
l!l&&r!l&&!r
0016
MC/DC0%0/2
$tag eq "ul" or $tag eq "ol"
$tag eq "ul" $tag eq "ol"
Truth table33%1/3
A or B
A= $tag eq "ul"B= $tag eq "ol"
ABresult
1X1
011
000
276 $tag eq 'ol' )
277 {
278 0 my $indent = 0;
279 0 ▶ my $is_ordered = ( $tag eq 'ol' ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$tag eq 'ol' ? : 0 0 0
280 0 ▶ if( $me->tag_name eq 'list_item' )
Branch: 1 branch
BranchTrueFalseTotal
if ($me->tag_name eq "list_item") 0 0 0
281 {
282 0 $indent = $me->indent + 1;
283 }
284 0 ▶ $top = $doc->create_list({
Condition0%0/2
$doc->create_list({'indent', $indent, 'order', $is_ordered}) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$doc->create_list({'indent', $indent, 'order', $is_ordered}) || (return $self->pass_error)
$doc->create_list({'indent', $indent, 'order', $is_ordered})
Truth table0%0/2
A
A= $doc->create_list({'indent', $indent, 'order', $is_ordered})
Aresult
11
00
285 indent => $indent,
286 order => $is_ordered,
287 }) || return( $self->pass_error );
288 0 ▶ $me->add_element( $top ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$me->add_element($top) or return $self->pass_error 0 0 0
289 }
290 elsif( $tag eq 'li' )
291 {
292 0 my $indent = 0;
293 0 my $is_ordered = 0;
294 0 ▶ if( $me->tag_name eq 'list' )
Branch: 1 branch
BranchTrueFalseTotal
if ($me->tag_name eq "list") 0 0 0
295 {
296 0 $indent = $me->indent + 1;
297 0 ▶ $is_ordered = $me->order ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$me->order ? : 0 0 0
298 }
299 0 ▶ $top = $doc->create_list_item({
Condition0%0/2
$doc->create_list_item({'indent', $indent}) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$doc->create_list_item({'indent', $indent}) || (return $self->pass_error)
$doc->create_list_item({'indent', $indent})
Truth table0%0/2
A
A= $doc->create_list_item({'indent', $indent})
Aresult
11
00
300 indent => $indent,
301 }) || return( $self->pass_error );
302 0 ▶ $me->add_element( $top ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$me->add_element($top) or return $self->pass_error 0 0 0
303 }
304 elsif( $tag eq 'br' )
305 {
306 # <br> cannot have children so use $elem instead of $top
307 0 ▶ my $elem = $doc->create_new_line || return( $self->pass_error );
Condition0%0/2
$doc->create_new_line || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$doc->create_new_line || (return $self->pass_error)
$doc->create_new_line
Truth table0%0/2
A
A= $doc->create_new_line
Aresult
11
00
308 0 ▶ $me->add_element( $elem ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$me->add_element($elem) or return $self->pass_error 0 0 0
309 }
310 elsif( $tag eq 'p' )
311 {
312 1 ▶ $top = $doc->create_paragraph || return( $self->pass_error );
Condition50%1/2
$doc->create_paragraph || (return $self->pass_error)
l!l
10
MC/DC0%0/1
$doc->create_paragraph || (return $self->pass_error)
$doc->create_paragraph
Truth table50%1/2
A
A= $doc->create_paragraph
Aresult
11
00
313 1 ▶ $me->add_element( $top ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$me->add_element($top) or return $self->pass_error 0 1 1
314 }
315 ▶ elsif( $tag eq 's' || $tag eq 'del' )
Condition66%2/3
$tag eq "s" or $tag eq "del"
l!l&&r!l&&!r
0114
MC/DC50%1/2
$tag eq "s" or $tag eq "del"
$tag eq "s" $tag eq "del"
Truth table66%2/3
A or B
A= $tag eq "s"B= $tag eq "del"
ABresult
1X1
011
000
316 {
317 1 ▶ $top = $doc->create_strikethrough || return( $self->pass_error );
Condition50%1/2
$doc->create_strikethrough || (return $self->pass_error)
l!l
10
MC/DC0%0/1
$doc->create_strikethrough || (return $self->pass_error)
$doc->create_strikethrough
Truth table50%1/2
A
A= $doc->create_strikethrough
Aresult
11
00
318 1 ▶ $me->add_element( $top ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$me->add_element($top) or return $self->pass_error 0 1 1
319 }
320 elsif( $tag eq 'sub' )
321 {
322 0 ▶ $top = $doc->create_subscript || return( $self->pass_error );
Condition0%0/2
$doc->create_subscript || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$doc->create_subscript || (return $self->pass_error)
$doc->create_subscript
Truth table0%0/2
A
A= $doc->create_subscript
Aresult
11
00
323 0 ▶ $me->add_element( $top ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$me->add_element($top) or return $self->pass_error 0 0 0
324 }
325 elsif( $tag eq 'sup' )
326 {
327 0 ▶ $top = $doc->create_superscript || return( $self->pass_error );
Condition0%0/2
$doc->create_superscript || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$doc->create_superscript || (return $self->pass_error)
$doc->create_superscript
Truth table0%0/2
A
A= $doc->create_superscript
Aresult
11
00
328 0 ▶ $me->add_element( $top ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$me->add_element($top) or return $self->pass_error 0 0 0
329 }
330 elsif( $tag eq 'table' )
331 {
332 0 ▶ $top = $doc->create_table || return( $self->pass_error );
Condition0%0/2
$doc->create_table || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$doc->create_table || (return $self->pass_error)
$doc->create_table
Truth table0%0/2
A
A= $doc->create_table
Aresult
11
00
333 0 ▶ $me->add_element( $top ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$me->add_element($top) or return $self->pass_error 0 0 0
334 }
335 elsif( $tag eq 'tbody' )
336 {
337 0 ▶ $top = $doc->create_table_body || return( $self->pass_error );
Condition0%0/2
$doc->create_table_body || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$doc->create_table_body || (return $self->pass_error)
$doc->create_table_body
Truth table0%0/2
A
A= $doc->create_table_body
Aresult
11
00
338 0 ▶ if( $me->tag_name eq 'table' )
Branch: 1 branch
BranchTrueFalseTotal
if ($me->tag_name eq 'table') { } 0 0 0
339 {
340 0 ▶ $me->add_body( $top ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$me->add_body($top) or return $self->pass_error 0 0 0
341 }
342 else
343 {
344 0 ▶ $me->add_element( $top ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$me->add_element($top) or return $self->pass_error 0 0 0
345 }
346 }
347 elsif( $tag eq 'thead' )
348 {
349 0 ▶ $top = $doc->create_table_header || return( $self->pass_error );
Condition0%0/2
$doc->create_table_header || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$doc->create_table_header || (return $self->pass_error)
$doc->create_table_header
Truth table0%0/2
A
A= $doc->create_table_header
Aresult
11
00
350 0 ▶ if( $me->tag_name eq 'table' )
Branch: 1 branch
BranchTrueFalseTotal
if ($me->tag_name eq 'table') { } 0 0 0
351 {
352 0 ▶ $me->add_header( $top ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$me->add_header($top) or return $self->pass_error 0 0 0
353 }
354 else
355 {
356 0 ▶ $me->add_element( $top ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$me->add_element($top) or return $self->pass_error 0 0 0
357 }
358 }
359 elsif( $tag eq 'tr' )
360 {
361 0 ▶ $top = $doc->create_table_row || return( $self->pass_error );
Condition0%0/2
$doc->create_table_row || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$doc->create_table_row || (return $self->pass_error)
$doc->create_table_row
Truth table0%0/2
A
A= $doc->create_table_row
Aresult
11
00
362 0 ▶ $me->add_element( $top ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$me->add_element($top) or return $self->pass_error 0 0 0
363 }
364 elsif( $tag eq 'td' )
365 {
366 0 ▶ $top = $doc->create_table_cell || return( $self->pass_error );
Condition0%0/2
$doc->create_table_cell || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$doc->create_table_cell || (return $self->pass_error)
$doc->create_table_cell
Truth table0%0/2
A
A= $doc->create_table_cell
Aresult
11
00
367 0 ▶ $me->add_element( $top ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$me->add_element($top) or return $self->pass_error 0 0 0
368 }
369 elsif( $tag eq 'th' )
370 {
371 0 ▶ $top = $doc->create_table_cell({
Condition0%0/2
$doc->create_table_cell({'tag_name', 'th'}) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$doc->create_table_cell({'tag_name', 'th'}) || (return $self->pass_error)
$doc->create_table_cell({'tag_name', 'th'})
Truth table0%0/2
A
A= $doc->create_table_cell({'tag_name', 'th'})
Aresult
11
00
372 tag_name => 'th',
373 }) || return( $self->pass_error );
374 0 ▶ $me->add_element( $top ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$me->add_element($top) or return $self->pass_error 0 0 0
375 }
376 elsif( $tag eq 'caption' )
377 {
378 0 ▶ $top = $doc->create_table_caption || return( $self->pass_error );
Condition0%0/2
$doc->create_table_caption || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$doc->create_table_caption || (return $self->pass_error)
$doc->create_table_caption
Truth table0%0/2
A
A= $doc->create_table_caption
Aresult
11
00
379 0 ▶ $me->add_element( $top ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$me->add_element($top) or return $self->pass_error 0 0 0
380 }
381 ▶ elsif( $tag eq '_text' || $tag eq '_space' )
Condition100%3/3
$tag eq "_text" or $tag eq "_space"
l!l&&r!l&&!r
1022
MC/DC100%2/2
$tag eq "_text" or $tag eq "_space"
$tag eq "_text" $tag eq "_space"
Truth table100%3/3
A or B
A= $tag eq "_text"B= $tag eq "_space"
ABresult
1X1
011
000
382 {
383 # text chunk cannot have children so use $elem instead of $top
384 12 ▶ my $elem = $doc->create_text({
Condition50%1/2
$doc->create_text({'text', $e->value}) || (return $self->pass_error)
l!l
120
MC/DC0%0/1
$doc->create_text({'text', $e->value}) || (return $self->pass_error)
$doc->create_text({'text', $e->value})
Truth table50%1/2
A
A= $doc->create_text({'text', $e->value})
Aresult
11
00
385 text => $e->value,
386 }) || return( $self->pass_error );
387 12 ▶ $me->add_element( $elem ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$me->add_element($elem) or return $self->pass_error 0 12 12
388 }
389 elsif( $tag eq '_document' )
390 {
391 $e->children->foreach(sub
392 {
393 5 ▶ $crawl->( $_[0] => $me );
Subroutine __ANON__: called CC=1 SCAR=0.0
394 1 });
395 }
396 # Anything else, and we save it as raw HTML, and we do not delve deeper
397 else
398 {
399 1 my $raw = $e->as_string;
400 1 ▶ my $elem = $doc->create_html({
Condition50%1/2
$doc->create_html({'object', $e, 'raw', $raw}) || (return $self->pass_error)
l!l
10
MC/DC0%0/1
$doc->create_html({'object', $e, 'raw', $raw}) || (return $self->pass_error)
$doc->create_html({'object', $e, 'raw', $raw})
Truth table50%1/2
A
A= $doc->create_html({'object', $e, 'raw', $raw})
Aresult
11
00
401 object => $e,
402 raw => $raw,
403 }) || return( $self->pass_error );
404 1 ▶ $me->add_element( $elem ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$me->add_element($elem) or return $self->pass_error 0 1 1
405 }
406
407 19 ▶ if( defined( $top ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $top) 5 14 19
408 {
409 $e->children->foreach(sub
410 {
411 13 ▶ $crawl->( $_[0] => $top );
Subroutine __ANON__: called CC=1 SCAR=0.0
412 5 });
413 }
414 1 };
415 1 $crawl->( $html => $doc );
416 1 return( $doc );
417 }
418  
419 1 ▶sub katex_delimiter { return( shift->_set_get_array_as_object( 'katex_delimiter', @_ ) ); }
Subroutine katex_delimiter: called CC=1 SCAR=0.0
Pod documented
420  
421 # Nothing fancy, and used internally so no chaining or anything
422 # We use it like $p->list_level++ or $p->list_level--;
423 0 ▶sub list_level : lvalue { return( shift->_set_get_lvalue( 'list_level', @_ ) ); }
Subroutine list_level: not called CC=1 SCAR=6.9
Pod documented
424  
425 sub mode
426 {
427 0 ▶ my $self = shift( @_ );
Subroutine mode: not called CC=4 SCAR=30.0
Pod documented
428 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
429 {
430 0 my $mode = shift( @_ );
431 0 my $curr = $self->_set_get_scalar( 'mode' );
432 0 ▶ if( substr( $mode, 0, 1 ) eq '+' )
Branch: 1 branch
BranchTrueFalseTotal
if (substr($mode, 0, 1) eq "+") 0 0 0
433 {
434 0 ▶ if( length( $curr ) )
Branch: 1 branch
BranchTrueFalseTotal
if (length $curr) { } 0 0 0
435 {
436 0 $curr .= ' ' . substr( $mode, 1 );
437 }
438 else
439 {
440 0 $curr = $mode;
441 }
442 }
443 0 $self->_set_get_scalar( 'mode', $curr );
444 }
445 0 return( $self->_set_get_scalar( 'mode' ) );
446 }
447  
448 sub parse
449 {
450 0 ▶ my $self = shift( @_ );
Subroutine parse: not called CC=156 SCAR=101.1
Pod documented
451 # We accept empty data and we return empty elements array then
452 0 my $data = shift( @_ );
453 0 my $opts = $self->_get_args_as_hash( @_ );
454 0 my $cb = $self->callback;
455 0 ▶ if( !defined( $cb ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $cb) { } 0 0 0
elsif (ref $cb) { } 0 0 0
456 {
457 0 ▶ $cb = sub{1};
Subroutine __ANON__: not called CC=1 SCAR=6.9
458 }
459 elsif( ref( $cb ) )
460 {
461 0 return( $self->error( "Callback set (${cb}) is not a code reference." ) );
462 }
463
464 0 ▶ unless( $opts->{element} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts->{"element"}) 0 0 0
465 {
466 # Standardise the new lines characters
467 # $data =~ s/\cM/\n/gs;
468 # $data =~ s/\c@//g;
469 0 $data =~ s/\r\n/\n/gs;
470 0 $data =~ s/\r//gs;
471 # Clean up the empty lines as they do not matter
472 0 $data =~ s/^[[:blank:]\h]+$//gm;
473 # Detab
474 # Cribbed from a post by Bart Lateur:
475 # <http://www.nntp.perl.org/group/perl.macperl.anyperl/154>
476 0 my $tab_width = 4;
477 0 $data =~ s{(.*?)\t}{$1 . ( ' ' x ( $tab_width - length( $1 ) % $tab_width ) )}ge;
478 # Make sure $text ends with a couple of newlines, unless this is sub parsing
479 0 my $trailing_nl = ( $data =~ /(\n+)$/ )[0];
480 0 ▶ my $nth_nl = defined( $trailing_nl ) ? length( $trailing_nl ) : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $trailing_nl ? : 0 0 0
481 0 ▶ unless( $nth_nl > 1 )
Branch: 1 branch
BranchTrueFalseTotal
unless ($nth_nl > 1) 0 0 0
482 {
483 0 $data .= ( "\n" x ( 2 - $nth_nl ) );
484 }
485 }
486
487 0 pos( $data ) = 0;
488 # all excludes extended markdowns
489 0 ▶ my $mode = $self->mode || 'all';
Condition0%0/2
$self->mode || 'all'
l!l
00
MC/DC0%0/1
$self->mode || 'all'
$self->mode
Truth table0%0/2
A
A= $self->mode
Aresult
11
00
490 0 my $space_re = qr/[[:blank:]\h]{1,3}/;
491 0 my $PH_PREFIX = 'OBJ{';
492 0 my $PH_SUFFIX = '}';
493 0 my $top;
494 0 ▶ if( !( $top = $opts->{element} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($top = $opts->{"element"}) 0 0 0
495 {
496 0 my $doc = $self->create_document(
497 abbreviation_case_sensitive => $self->abbreviation_case_sensitive,
498 default_email => $self->default_email,
499 email_obfuscate_class => $self->email_obfuscate_class,
500 email_obfuscate_data_host => $self->email_obfuscate_data_host,
501 email_obfuscate_data_user => $self->email_obfuscate_data_user,
502 css => $self->css,
503 debug => $self->debug,
504 tag_name => 'top',
505 );
506 # Sharing the parameter
507 0 $doc->katex_delimiter( $self->katex_delimiter );
508 # First time called, we reset the top document, so the same parser can be called several times
509 0 $self->document( $doc );
510 0 $top = $doc;
511 };
512 0 ▶ $self->messagef_colour( 3, "%s %d bytes of data with mode set to '{green}%s{/}' with container being '{green}%s{/}'.", ( $opts->{element} ? "Sub-parsing" : "Parsing" ), length( $data ), $mode, $top->tag_name );
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'element'} ? : 0 0 0
513
514 # Previous element added. We store it here to keep track of context
515 0 my $context;
516 # pos( $data ) = 0;
517 0 ▶ pos( $data ) = $opts->{pos} if( length( $opts->{pos} ) && $opts->{pos} =~ /^\d+$/ );
Branch: 1 branch
BranchTrueFalseTotal
if length $opts->{"pos"} and $opts->{"pos"} =~ /^\d+$/ 0 0 0
Condition0%0/3
length $opts->{"pos"} and $opts->{"pos"} =~ /^\d+$/
!ll&&!rl&&r
000
MC/DC0%0/2
length $opts->{"pos"} and $opts->{"pos"} =~ /^\d+$/
length $opts->{"pos"} $opts->{"pos"} =~ /^\d+$/
Truth table0%0/3
A and B
A= length $opts->{"pos"}B= $opts->{"pos"} =~ /^\d+$/
ABresult
0X0
100
111
518 0 $opts->{scope_cond} = 'any';
519 0 ▶ if( !$self->_is_array( $opts->{scope} ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not $self->_is_array($opts->{'scope'})) { } 0 0 0
elsif ($self->_is_array($opts->{'scope'}) and not $self->_to_array_object($opts->{'scope'})->length) { } 0 0 0
520 {
521 0 ▶ $opts->{scope} = length( $opts->{scope} ) ? [split( /\s+/, $opts->{scope} )] : [split( /\s+/, $mode )];
Branch: 1 branch
BranchTrueFalseTotal
length $opts->{'scope'} ? : 0 0 0
522 }
523 ▶ elsif( $self->_is_array( $opts->{scope} ) && !$self->_to_array_object( $opts->{scope} )->length )
Condition0%0/3
$self->_is_array($opts->{"scope"}) and not $self->_to_array_object($opts->{"scope"})->length
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_array($opts->{"scope"}) and not $self->_to_array_object($opts->{"scope"})->length
$self->_is_array($opts->{"scope"}) not $self->_to_array_object($opts->{"scope"})->length
Truth table0%0/3
A and not(B)
A= $self->_is_array($opts->{"scope"})B= not $self->_to_array_object($opts->{"scope"})->length
ABresult
0X0
100
111
524 {
525 0 $opts->{scope} = [$mode];
526 }
527
528 0 ▶ if( length( $opts->{scope} ) && $self->_is_array( $opts->{scope} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (length $opts->{"scope"} and $self->_is_array($opts->{"scope"})) 0 0 0
Condition0%0/3
length $opts->{"scope"} and $self->_is_array($opts->{"scope"})
!ll&&!rl&&r
000
MC/DC0%0/2
length $opts->{"scope"} and $self->_is_array($opts->{"scope"})
length $opts->{"scope"} $self->_is_array($opts->{"scope"})
Truth table0%0/3
A and B
A= length $opts->{"scope"}B= $self->_is_array($opts->{"scope"})
ABresult
0X0
100
111
529 {
530 0 my $scopes = $self->new_array;
531 $self->_to_array_object( $opts->{scope} )->foreach(sub
532 {
533 0 ▶ if( s/\|{1,2}/ /g )
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 2 branches
BranchTrueFalseTotal
if (s/\|{1,2}/ /g) { } 0 0 0
elsif (s/(?:\&{1,2}|\+)/ /g) { } 0 0 0
534 {
535 0 $scopes->push( split( /\s+/, $_ ) );
536 0 $opts->{scope_cond} = 'any';
537 }
538 elsif( s/(?:\&{1,2}|\+)/ /g )
539 {
540 0 $scopes->push( split( /\s+/, $_ ) );
541 0 $opts->{scope_cond} = 'all';
542 }
543 else
544 {
545 0 $scopes->push( $_ );
546 }
547 0 });
548 0 $opts->{scope} = $scopes;
549 }
550
551 0 my $scope = Markdown::Parser::Scope->new( $opts->{scope}, debug => $self->debug, condition => $opts->{scope_cond} );
552 0 ▶ $self->scope( $scope ) if( $top->tag_name eq 'top' && !$self->scope );
Branch: 1 branch
BranchTrueFalseTotal
if $top->tag_name eq "top" and not $self->scope 0 0 0
Condition0%0/3
$top->tag_name eq "top" and not $self->scope
!ll&&!rl&&r
000
MC/DC0%0/2
$top->tag_name eq "top" and not $self->scope
$top->tag_name eq "top" not $self->scope
Truth table0%0/3
A and not(B)
A= $top->tag_name eq "top"B= not $self->scope
ABresult
0X0
100
111
553
554 0 my $katex_re;
555 # We check for link definitions, but only if we are in the top element, since sub elements would not hold any of them and it would thus be pointless to process them
556 # Need to remove the link definition from the document
557 0 ▶ if( $top->tag_name eq 'top' )
Branch: 1 branch
BranchTrueFalseTotal
if ($top->tag_name eq "top") 0 0 0
558 {
559 # Need to isolate html code blocks, because their indentation can be mistaken for code blocks.
560 # Then, we parsing for code block, we re-instate the html block found and isolated.
561 0 ▶ if( $scope->has( [qw( html )]) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has(["html"])) 0 0 0
562 {
563 0 $data =~ s{$RE{Markdown}{Html}}
564 {
565 0 my $re = { %+ };
566 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
567 0 my $pos = pos( $data );
568 # my $html = $re->{tag_all};
569 # We save exactly what we caught
570 0 my $html = substr( $data, $-[0], $+[0] - $-[0] );
571 0 ▶ my $elem = $top->create_html({
Condition0%0/2
$top->create_html({'pos', $pos, 'raw', $html}) || die($top->error)
l!l
00
MC/DC0%0/1
$top->create_html({'pos', $pos, 'raw', $html}) || die($top->error)
$top->create_html({'pos', $pos, 'raw', $html})
Truth table0%0/2
A
A= $top->create_html({'pos', $pos, 'raw', $html})
Aresult
11
00
572 pos => $pos,
573 raw => $html,
574 }) || die( $top->error );
575 0 ▶ my $id = $self->document->add_object( $elem ) || die( $top->error );
Condition0%0/2
$self->document->add_object($elem) || die($top->error)
l!l
00
MC/DC0%0/1
$self->document->add_object($elem) || die($top->error)
$self->document->add_object($elem)
Truth table0%0/2
A
A= $self->document->add_object($elem)
Aresult
11
00
576 0 "!!HTML[$id]!!";
577 }xgems;
578 }
579
580 # Code blocks trumps everything else, so they come first
581 # First, check the parts that are surrounded by backticks or equivalents
582 0 ▶ $self->message_colour( 3, "Does scope have '{green}extended code_block{/}' ? ", $scope->has( [qw( extended code_block )] ) ? '{green}yes{/}' : '{red}no{/}' );
Branch: 1 branch
BranchTrueFalseTotal
$scope->has(['extended', 'code_block']) ? : 0 0 0
583 0 ▶ if( $scope->has( [qw( extended code_block )] ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($scope->has(['extended', 'code_block'])) { } 0 0 0
elsif ($self->message_colour(3, q[Does scope have '{green}code_block{/}' ? ], $scope->has('code_block') ? '{green}yes{/}' : '{red}no{/}') and $scope->has('code_block')) { } 0 0 0
584 {
585 0 $data =~ s{$RE{Markdown}{ExtCodeBlock}}
586 {
587 0 my $re = { %+ };
588 0 $re->{capture} = substr( $data, $-[0], $+[0] - $-[0] );
589 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
590 0 my $pos = pos( $data );
591 0 my $code_def = $re->{code_attr};
592 0 my $code_class = $re->{code_class};
593 0 my $raw = $re->{code_all};
594 0 my $content = $re->{code_content};
595
596 # Restore any html that got caught previously
597 0 $content =~ s{\!{2}HTML\[(?<obj_id>\d+)\]\!{2}}
598 {
599 0 my $obj_id = $+{obj_id};
600 0 my $obj = $self->document->objects->get( $obj_id );
601 0 ▶ if( $obj )
Branch: 1 branch
BranchTrueFalseTotal
if ($obj) { } 0 0 0
602 {
603 0 $obj->raw->scalar;
604 }
605 else
606 {
607 0 "!!HTML[${obj_id}]!!";
608 }
609 }xgems;
610
611 0 $code_def =~ s/^[[:blank:]\h]+|[[:blank:]\h]+$//gs;
612 0 $code_class =~ s/^[\.[:blank:]\h]+//gs;
613
614 0 my $code = $top->create_code({
615 class => [split( /\./, $code_class )],
616 pos => $pos,
617 raw => $raw,
618 });
619 0 ▶ $code->add_element( $top->create_text({
Branch: 1 branch
BranchTrueFalseTotal
$code->add_element($top->create_text({"text", $content, "pos", $pos})) or return $self->pass_error($code->error) 0 0 0
620 text => $content,
621 pos => $pos,
622 }) ) || return( $self->pass_error( $code->error ) );
623 0 ▶ $code->add_attributes( $code_def ) if( length( $code_def ) );
Branch: 1 branch
BranchTrueFalseTotal
if length $code_def 0 0 0
624 0 my $id = $top->add_object( $code );
625 0 "${PH_PREFIX}${id}${PH_SUFFIX}\n";
626 }xgems;
627 }
628 ▶ elsif( $self->message_colour( 3, "Does scope have '{green}code_block{/}' ? ", $scope->has( 'code_block' ) ? '{green}yes{/}' : '{red}no{/}' ) && $scope->has( 'code_block' ) )
Branch: 1 branch
BranchTrueFalseTotal
$scope->has('code_block') ? : 0 0 0
Condition0%0/3
$self->message_colour(3, "Does scope have '{green}code_block{/}' ? ", $scope->has("code_block") ? "{green}yes{/}" : "{red}no{/}") and $scope->has("code_block")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->message_colour(3, "Does scope have '{green}code_block{/}' ? ", $scope->has("code_block") ? "{green}yes{/}" : "{red}no{/}") and $scope->has("code_block")
$self->message_colour(3, "Does scope have '{green}code_block{/}' ? ", $scope->has("code_block") ? "{green}yes{/}" : "{red}no{/}") $scope->has("code_block")
Truth table0%0/3
A and B
A= $self->message_colour(3, "Does scope have '{green}code_block{/}' ? ", $scope->has("code_block") ? "{green}yes{/}" : "{red}no{/}")B= $scope->has("code_block")
ABresult
0X0
100
111
629 {
630 0 $data =~ s{$RE{Markdown}{CodeBlock}}
631 {
632 0 my $re = { %+ };
633 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
634 0 my $pos = pos( $data );
635 0 my $raw = $re->{code_all};
636 0 my $content = $re->{code_content};
637 # my $new_lines = $re->{code_trailing_new_line};
638
639 # Restore any html that got caught previously
640 0 $content =~ s{\!{2}HTML\[(?<obj_id>\d+)\]\!{2}}
641 {
642 0 my $obj_id = $+{obj_id};
643 0 my $obj = $self->document->objects->get( $obj_id );
644 0 ▶ if( $obj )
Branch: 1 branch
BranchTrueFalseTotal
if ($obj) { } 0 0 0
645 {
646 0 $obj->raw->scalar;
647 }
648 else
649 {
650 0 "!!HTML[${obj_id}]!!";
651 }
652 }xgems;
653
654 0 my $code = $top->create_code({
655 pos => $pos,
656 raw => $raw,
657 });
658 0 ▶ $code->add_element( $top->create_text({
Branch: 1 branch
BranchTrueFalseTotal
$code->add_element($top->create_text({"text", $content, "pos", $pos})) or return $self->pass_error($code->error) 0 0 0
659 text => $content,
660 pos => $pos,
661 }) ) || return( $self->pass_error( $code->error ) );
662 0 my $id = $top->add_object( $code );
663 0 "${PH_PREFIX}${id}${PH_SUFFIX}\n";
664 }xgems;
665 }
666
667 0 ▶ $self->message_colour( 3, "Does scope have '{green}code_line{/}' ? ", $scope->has( 'code_line' ) ? '{green}yes{/}' : '{red}no{/}' );
Branch: 1 branch
BranchTrueFalseTotal
$scope->has('code_line') ? : 0 0 0
668 # Code single line. If it is a series of them treat them as a block
669 0 ▶ if( $scope->has( 'code_line' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has("code_line")) 0 0 0
670 {
671 0 $data =~ s{$RE{Markdown}{CodeLine}}
672 {
673 0 my $re = { %+ };
674 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
675 0 my $pos = pos( $data );
676 0 my $raw = $re->{code_all};
677 0 my $content = $re->{code_all};
678
679 ## Restore any html that got caught previously
680 0 $content =~ s{\!{2}HTML\[(?<obj_id>\d+)\]\!{2}}
681 {
682 0 my $obj_id = $+{obj_id};
683 0 my $obj = $self->document->objects->get( $obj_id );
684 0 ▶ if( $obj )
Branch: 1 branch
BranchTrueFalseTotal
if ($obj) { } 0 0 0
685 {
686 0 $obj->raw->scalar;
687 }
688 else
689 {
690 0 "!!HTML[${obj_id}]!!";
691 }
692 }xgems;
693
694 # trim leading newlines
695 0 $content =~ s/\A\n+//;
696 # trim trailing whitespace
697 0 $content =~ s/\s+\z//;
698 0 my $trailing_nl = $self->_total_trailing_new_lines( $raw );
699 my $code = $top->create_code({
700 # Setting this to true will have the leading 4 spaces or tab removed
701 fenced => 1,
702 pos => $pos,
703 raw => $re->{code_all},
704 0 });
705 0 ▶ $code->add_element( $top->create_text({
Branch: 1 branch
BranchTrueFalseTotal
$code->add_element($top->create_text({"text", $content, "pos", $pos})) or return $self->pass_error($code->error) 0 0 0
706 text => $content,
707 pos => $pos,
708 }) ) || return( $self->pass_error( $code->error ) );
709 0 my $id = $top->add_object( $code );
710 # Move back before the trailing new lines as they may be important for the next check
711 0 "${PH_PREFIX}${id}${PH_SUFFIX}\n";
712 }xgems;
713 }
714
715 # Restore any html blocks if any
716 0 $data =~ s{\!{2}HTML\[(?<obj_id>\d+)\]\!{2}}
717 {
718 0 my $obj_id = $+{obj_id};
719 0 my $obj = $self->document->objects->get( $obj_id );
720 0 ▶ if( $obj )
Branch: 1 branch
BranchTrueFalseTotal
if ($obj) { } 0 0 0
721 {
722 0 $obj->raw->scalar;
723 }
724 else
725 {
726 0 "!!HTML[${obj_id}]!!";
727 }
728 }xgems;
729  
730
731 0 pos( $data ) = 0;
732 # Inline code `some thing`
733 0 ▶ if( $scope->has( 'code_span' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has("code_span")) 0 0 0
734 {
735 0 $data =~ s{$RE{Markdown}{CodeSpan}}
736 {
737 0 my $re = { %+ };
738 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
739 0 my $pos = pos( $data );
740 0 my $raw = $re->{code_all};
741 0 my $content = $re->{code_content};
742 0 $self->message_colour( 3, $self->whereami( \$data, $pos, { text => "Found an inline code '$raw' at pos '$pos' with content:\n'{green}" . $content . "{/}' and with capture: " . $self->dump( $re ), return => 1 } ) );
743 # leading whitespace
744 0 $content =~ s/^[ \t]*//g;
745 # trailing whitespace
746 0 $content =~ s/[ \t]*$//g;
747 0 my $code = $top->create_code({
748 inline => 1,
749 pos => $pos,
750 raw => $raw,
751 });
752 0 $code->add_element( $top->create_text({
753 text => $content,
754 pos => $pos,
755 }) );
756 0 my $id = $top->add_object( $code );
757 0 "${PH_PREFIX}${id}${PH_SUFFIX}";
758 }xgems;
759 }
760
761 0 $self->messagef_colour( 3, "%d objects found so far.", $top->objects->length );
762
763 0 $self->message_colour( 3, "Processing possible {green}link{/} definitions." );
764 0 $data =~ s{$RE{Markdown}{ExtLinkDefinition}}
765 {
766 0 my $re = { %+ };
767 0 my $id = $re->{link_id};
768 0 my $url = $re->{link_url};
769 0 my $title = $re->{link_title};
770 0 my $link_def = $re->{link_attr};
771 0 my $raw = $re->{link_all};
772 0 my $end = pos( $data );
773 0 my $start = $end - length( $re->{link_all} );
774 0 $self->message_colour( 3, $self->whereami( \$data, pos( $data ), { text => "Found link definition with id '{green}" . $re->{link_id} . "{/}', url '{green}" . $re->{link_url} . "{/}', title '{green}" . $re->{link_title} . "{/}', all '{green}" . $re->{link_all} . "{/}' at position '" . $start . "' until position '" . $end . "'.", return => 1 } ) );
775 0 my $lnk = $top->create_link_definition({
776 link_id => $id,
777 pos => pos( $data ),
778 raw => $raw,
779 title => $title,
780 url => $url,
781 });
782 0 $link_def =~ s/^[[:blank:]\h]+|[[:blank:]\h]+$//gs;
783 0 ▶ $lnk->add_attributes( $link_def ) if( length( $link_def ) );
Branch: 1 branch
BranchTrueFalseTotal
if length $link_def 0 0 0
784 ## Just register the link definition, but do not add it to the document
785 0 $top->register_link_definition( $lnk );
786 0 '';
787 }gme;
788
789 0 $data =~ s{$RE{Markdown}{LinkDefinition}}
790 {
791 0 my $re = { %+ };
792 0 my $id = $re->{link_id};
793 0 my $url = $re->{link_url};
794 0 my $title = $re->{link_title};
795 0 my $raw = $re->{link_all};
796 0 my $end = pos( $data );
797 0 my $start = $end - length( $re->{link_all} );
798 0 $self->message_colour( 3, $self->whereami( \$data, pos( $data ), { text => "Found link definition with id '{green}" . $re->{link_id} . "{/}', url '{green}" . $re->{link_url} . "{/}', title '{green}" . $re->{link_title} . "{/}', all '{green}" . $re->{link_all} . "{/}' at position '" . $start . "' until position '" . $end . "'.", return => 1 } ) );
799 0 my $lnk = $top->create_link_definition({
800 link_id => $id,
801 pos => pos( $data ),
802 raw => $raw,
803 title => $title,
804 url => $url,
805 });
806 # Just register the link definition, but do not add it to the document
807 0 $top->register_link_definition( $lnk );
808 0 '';
809 }gme;
810
811 0 pos( $data ) = 0;
812 0 ▶ $self->message_colour( 3, "Does scope have '{green}abbr{/}' ? ", $scope->has( [qw( extended abbr )] ) ? '{green}yes{/}' : '{red}no{/}' );
Branch: 1 branch
BranchTrueFalseTotal
$scope->has(['extended', 'abbr']) ? : 0 0 0
813 0 ▶ if( $scope->has( [qw( extended abbr )] ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has(["extended", "abbr"])) 0 0 0
814 {
815 0 $data =~ s{^[[:blank:]\h]{0,3}$RE{Markdown}{ExtAbbr}}
816 {
817 0 my $re = { %+ };
818 0 my $end = pos( $data );
819 0 my $start = $end - length( $re->{abbr_all} );
820 0 $self->message_colour( 3, $self->whereami( \$data, pos( $data ), { text => "Found abbreviation \"{green}" . $re->{abbr_all} . "{/}\" with name '{green}" . $re->{abbr_name} . "{/}' with capture: " . $self->dump( $re ), return => 1 } ) );
821 my $abbr = $top->create_abbreviation({
822 name => $re->{abbr_name},
823 value => $re->{abbr_value},
824 parent => $top,
825 pos => pos( $data ),
826 raw => $re->{abbr_all},
827 0 });
828 0 $top->register_abbreviation( $abbr, { case_sensitive => $self->abbreviation_case_sensitive } );
829 0 '';
830 }gme;
831 }
832
833 0 ▶ $self->message_colour( 3, "Does scope have '{green}footnote{/}' ? ", $scope->has( [qw( extended footnote )] ) ? '{green}yes{/}' : '{red}no{/}' );
Branch: 1 branch
BranchTrueFalseTotal
$scope->has(['extended', 'footnote']) ? : 0 0 0
834 0 ▶ if( $scope->has( [qw( extended footnote )] ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has(["extended", "footnote"])) 0 0 0
835 {
836 0 $data =~ s{$RE{Markdown}{ExtFootnote}}
837 {
838 0 my $re = { %+ };
839 0 my $end = pos( $data );
840 0 my $start = $end - length( $re->{footnote_all} );
841 0 $self->message_colour( 3, $self->whereami( \$data, pos( $data ), { text => "Found footnote \"{green}" . $re->{footnote_all} . "{/}\" with id '{green}" . $re->{footnote_id} . "{/}' with capture: " . $self->dump( $re ), return => 1 } ) );
842 0 my $content = $re->{footnote_text} . ' !!FN!!';
843 my $footnote = $top->create_footnote({
844 id => $re->{footnote_id},
845 unparsed => $content,
846 parent => $top,
847 pos => pos( $data ),
848 raw => $re->{footnote_all},
849 0 ▶ }) || die( "Unable to create footnote object: ", $top->error, "\n" );
Condition0%0/2
$top->create_footnote({'id', $re->{'footnote_id'}, 'unparsed', $content, 'parent', $top, 'pos', pos $data, 'raw', $re->{'footnote_all'}}) || die('Unable to create footnote object: ', $top->error, "\n")
l!l
00
MC/DC0%0/1
$top->create_footnote({'id', $re->{'footnote_id'}, 'unparsed', $content, 'parent', $top, 'pos', pos $data, 'raw', $re->{'footnote_all'}}) || die('Unable to create footnote object: ', $top->error, "\n")
$top->create_footnote({'id', $re->{'footnote_id'}, 'unparsed', $content, 'parent', $top, 'pos', pos $data, 'raw', $re->{'footnote_all'}})
Truth table0%0/2
A
A= $top->create_footnote({'id', $re->{'footnote_id'}, 'unparsed', $content, 'parent', $top, 'pos', pos $data, 'raw', $re->{'footnote_all'}})
Aresult
11
00
850 0 $top->register_footnote( $footnote );
851 0 '';
852 }gme;
853 }
854
855 0 ▶ $self->message_colour( 3, "Does scope have '{green}footnote{/}' ? ", $scope->has( [qw( footnote extended )] ) ? '{green}yes{/}' : '{red}no{/}' );
Branch: 1 branch
BranchTrueFalseTotal
$scope->has(['footnote', 'extended']) ? : 0 0 0
856 0 ▶ if( $scope->has( [qw( footnote extended )] ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has(["footnote", "extended"])) 0 0 0
857 {
858 0 $data =~ s{$RE{Markdown}{ExtFootnoteReference}}
859 {
860 0 my $re = { %+ };
861 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
862 0 my $pos = pos( $data );
863 0 my $id = $re->{footnote_id};
864 0 my $text = $re->{footnote_text};
865 0 my $footnote;
866 # Auto-generated id for inline footnote
867 # Example:
868 # I met Jack [^](Co-founder of Angels, Inc) at the meet-up.
869 # Here is an inline note.^[Inlines notes are easier to write]
870 # Inline footnote, i.e. text provided
871 # We cannot just do if( !$id ) because a valid id could be '0'
872 my $object_id;
873 0 ▶ if( !length( $id ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (length $id) 0 0 0
874 {
875 0 $id = $self->document->footnotes->length + 1;
876 }
877
878 0 ▶ if( length( $text ) )
Branch: 2 branches
BranchTrueFalseTotal
if (length $text) { } 0 0 0
elsif (not $footnote = $self->document->get_footnote($id)) { } 0 0 0
879 {
880 $footnote = $top->create_footnote({
881 id => $id,
882 text => $text,
883 parent => $top,
884 pos => $pos,
885 raw => $re->{footnote_all},
886 0 });
887 0 $top->register_footnote( $footnote );
888 }
889 # Cannot find an id matching this footnote, so we just add this footnote reference as a text
890 elsif( !( $footnote = $self->document->get_footnote( $id ) ) )
891 {
892 0 ▶ warn( "Unable to find a matching footnote with the footnote id \"$id\".\nAvailable footnotes ids are: '", $self->document->footnotes->map(sub{ $_->id })->join( "', '" ), "'." );
Subroutine __ANON__: not called CC=1 SCAR=6.9
893 $object_id = $self->document->add_object( $top->create_text(
894 {
895 text => $re->{footnote_all},
896 0 pos => $pos,
897 }) );
898 }
899
900 0 ▶ if( $footnote )
Branch: 1 branch
BranchTrueFalseTotal
if ($footnote) 0 0 0
901 {
902 # Create a footnote reference and associate this footnote id with this reference
903 # The footnote reference id will be set by add_reference()
904 my $ref = $top->create_footnote_ref({
905 footnote => $footnote,
906 raw => $re->{footnote_all},
907 0 sequence => ++$self->footnote_ref_sequence,
908 pos => $pos,
909 });
910 ## add_reference will take care of setting the id used for backlink for this footnote reference
911 0 $footnote->add_reference( $ref );
912 0 $object_id = $self->document->add_object( $ref );
913 }
914 0 "${PH_PREFIX}${object_id}${PH_SUFFIX}";
915 }xgems;
916 }
917
918 0 $self->message_colour( 3, "After processing {green}link{/} definition, {green}abbreviations{/} and {green}footnotes{/}, data is now '$data'." );
919 }
920
921 # NOTE: extended katex
922 0 ▶ if( $scope->has( [qw( extended katex )] ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has(["extended", "katex"])) 0 0 0
923 {
924 0 ▶ if( $self->katex_delimiter->length > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->katex_delimiter->length > 0) { } 0 0 0
925 {
926 0 $katex_re = $RE{Markdown}{ExtKatex}{-delimiter => $self->katex_delimiter->join( ',' )};
927 }
928 else
929 {
930 0 $katex_re = $RE{Markdown}{ExtKatex};
931 }
932 }
933
934 0 my $abbr_re;
935 0 ▶ if( $self->document->dict->length > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->document->dict->length > 0) 0 0 0
936 {
937 0 ▶ $abbr_re = '(?' . ( $self->abbreviation_case_sensitive ? '' : 'i' ) . ':' . $self->document->dict->keys->join( '|' )->scalar . ')';
Branch: 1 branch
BranchTrueFalseTotal
$self->abbreviation_case_sensitive ? : 0 0 0
938 0 $abbr_re = qr/$abbr_re/;
939 }
940 0 pos( $data ) = 0;
941
942
943 0 ▶ if( $top->tag_name ne 'top' )
Branch: 1 branch
BranchTrueFalseTotal
if ($top->tag_name ne "top") 0 0 0
944 {
945 # NOTE: extended code block
946 0 ▶ $self->message_colour( 3, "Does scope have '{green}extended code_block{/}' ? ", $scope->has( [qw( extended code_block )] ) ? '{green}yes{/}' : '{red}no{/}' );
Branch: 1 branch
BranchTrueFalseTotal
$scope->has(['extended', 'code_block']) ? : 0 0 0
947 0 ▶ if( $scope->has( [qw( extended code_block )] ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has(["extended", "code_block"])) 0 0 0
948 {
949 0 $data =~ s{$RE{Markdown}{ExtCodeBlock}}
950 {
951 0 my $re = { %+ };
952 0 $re->{capture} = substr( $data, $-[0], $+[0] - $-[0] );
953 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
954 0 my $pos = pos( $data );
955 0 my $code_def = $re->{code_attr};
956 0 my $code_class = $re->{code_class};
957 0 my $raw = $re->{code_all};
958 0 my $content = $re->{code_content};
959
960 0 $code_def =~ s/^[[:blank:]\h]+|[[:blank:]\h]+$//gs;
961 0 $code_class =~ s/^[\.[:blank:]\h]+//gs;
962
963 0 my $code = $top->create_code({
964 class => [split( /\./, $code_class )],
965 pos => $pos,
966 raw => $raw,
967 });
968 0 ▶ $code->add_element( $top->create_text({
Branch: 1 branch
BranchTrueFalseTotal
$code->add_element($top->create_text({"text", $content, "pos", $pos})) or return $self->pass_error($code->error) 0 0 0
969 text => $content,
970 pos => $pos,
971 }) ) || return( $self->pass_error( $code->error ) );
972 0 ▶ $code->add_attributes( $code_def ) if( length( $code_def ) );
Branch: 1 branch
BranchTrueFalseTotal
if length $code_def 0 0 0
973 0 my $id = $self->document->add_object( $code );
974 0 "${PH_PREFIX}${id}${PH_SUFFIX}\n";
975 }xgems;
976 }
977
978 # NOTE: code block
979 0 ▶ $self->message_colour( 3, "Does scope have '{green}code_block{/}' ? ", $scope->has( 'code_block' ) ? '{green}yes{/}' : '{red}no{/}' );
Branch: 1 branch
BranchTrueFalseTotal
$scope->has('code_block') ? : 0 0 0
980 # Code blocks trumps everything else, so they come first
981 0 ▶ if( $scope->has( 'code_block' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has("code_block")) 0 0 0
982 {
983 0 $data =~ s{$RE{Markdown}{CodeBlock}}
984 {
985 0 my $re = { %+ };
986 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
987 0 my $pos = pos( $data );
988 0 my $raw = $re->{code_all};
989 0 my $content = $re->{code_content};
990 # my $new_lines = $re->{code_trailing_new_line};
991 0 my $code = $top->create_code({
992 pos => $pos,
993 raw => $raw,
994 });
995 0 ▶ $code->add_element( $top->create_text({
Branch: 1 branch
BranchTrueFalseTotal
$code->add_element($top->create_text({"text", $content, "pos", $pos})) or return $self->pass_error($code->error) 0 0 0
996 text => $content,
997 pos => $pos,
998 }) ) || return( $self->pass_error( $code->error ) );
999 0 my $id = $self->document->add_object( $code );
1000 0 "${PH_PREFIX}${id}${PH_SUFFIX}\n";
1001 }xgems;
1002 }
1003
1004 # NOTE: code line
1005 0 ▶ $self->message_colour( 3, "Does scope have '{green}code_line{/}' ? ", $scope->has( 'code_line' ) ? '{green}yes{/}' : '{red}no{/}' );
Branch: 1 branch
BranchTrueFalseTotal
$scope->has('code_line') ? : 0 0 0
1006 # Code single line. If it is a series of them treat them as a block
1007 0 ▶ if( $scope->has( 'code_line' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has("code_line")) 0 0 0
1008 {
1009 0 $data =~ s{$RE{Markdown}{CodeLine}}
1010 {
1011 0 my $re = { %+ };
1012 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
1013 0 my $pos = pos( $data );
1014 0 my $raw = $re->{code_all};
1015 0 my $content = $re->{code_all};
1016 # trim leading newlines
1017 0 $content =~ s/\A\n+//;
1018 # trim trailing whitespace
1019 0 $content =~ s/\s+\z//;
1020 0 my $trailing_nl = $self->_total_trailing_new_lines( $raw );
1021 my $code = $top->create_code({
1022 ## Setting this to true will have the leading 4 spaces or tab removed
1023 fenced => 1,
1024 pos => $pos,
1025 raw => $re->{code_all},
1026 0 });
1027 0 ▶ $code->add_element( $top->create_text({
Branch: 1 branch
BranchTrueFalseTotal
$code->add_element($top->create_text({"text", $content, "pos", $pos})) or return $self->pass_error($code->error) 0 0 0
1028 text => $content,
1029 pos => $pos,
1030 }) ) || return( $self->pass_error( $code->error ) );
1031 0 my $id = $self->document->add_object( $code );
1032 # Move back before the trailing new lines as they may be important for the next check
1033 0 "${PH_PREFIX}${id}${PH_SUFFIX}\n";
1034 }xgems;
1035 }
1036 }
1037  
1038 # NOTE: table extended
1039 0 ▶ $self->message_colour( 3, "Does scope have '{green}table extended{/}' ? ", $scope->has( [qw( table extended )] ) ? '{green}yes{/}' : '{red}no{/}' );
Branch: 1 branch
BranchTrueFalseTotal
$scope->has(['table', 'extended']) ? : 0 0 0
1040 0 ▶ if( $scope->has( 'table extended' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has("table extended")) 0 0 0
1041 {
1042 0 $data =~ s{$RE{Markdown}{ExtTable}}
1043 {
1044 0 my $re = { %+ };
1045 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
1046 0 my $pos = pos( $data );
1047 0 my $tbl = $self->parse_table( $re, { doc => $top } );
1048 0 my $id = $tbl->object_id;
1049 # pos( $data ) = $pos + length( $re->{table} );
1050 0 "${PH_PREFIX}${id}${PH_SUFFIX}\n";
1051 }xgems;
1052 }
1053  
1054 # NOTE: html
1055 0 ▶ $self->message_colour( 3, "Does scope have '{green}html{/}' ? ", $scope->has( 'html' ) ? '{green}yes{/}' : '{red}no{/}' );
Branch: 1 branch
BranchTrueFalseTotal
$scope->has('html') ? : 0 0 0
1056 # HTML blocks MUST be start and end on their own lines
1057 0 ▶ if( $scope->has( 'html' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has("html")) 0 0 0
1058 {
1059 0 $data =~ s{$RE{Markdown}{Html}}
1060 {
1061 0 my $re = { %+ };
1062 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
1063 0 my $pos = pos( $data );
1064 0 my $html = $re->{tag_all};
1065 0 $html =~ s{$RE{Markdown}{ExtHtmlMarkdown}}
1066 {
1067 0 my $ct = $+{content};
1068 0 my $open = $+{div_open};
1069 0 my $close = $+{div_close};
1070 0 my $tag_name = $+{tag_name};
1071 0 my $leading_space = $+{leading_space};
1072 ## Remove the markdown attribute
1073 0 $open =~ s/[[:blank:]\h]+markdown[[:blank:]\h]*\=[[:blank:]\h]*(?<quote>["']?)1\g{quote}//;
1074 ## Need to remove indentation at begining of line
1075 0 ▶ if( length( $leading_space ) )
Branch: 1 branch
BranchTrueFalseTotal
if (length $leading_space) 0 0 0
1076 {
1077 0 $ct =~ s/^$leading_space//gm;
1078 }
1079 0 my $p = $top->create_paragraph({
1080 parent => $top,
1081 pos => $pos,
1082 });
1083 0 $self->parse( $ct, { element => $p });
1084 0 ▶ my $res = $p->children->map(sub{ $_->as_string })->join( '' )->scalar;
Subroutine __ANON__: not called CC=1 SCAR=6.9
1085 0 "${open}${res}\n${close}\n";
1086 }xgems;
1087
1088 0 ▶ my $elem = $top->create_html({
Condition0%0/2
$top->create_html({'pos', $pos, 'raw', $html}) || die($top->error)
l!l
00
MC/DC0%0/1
$top->create_html({'pos', $pos, 'raw', $html}) || die($top->error)
$top->create_html({'pos', $pos, 'raw', $html})
Truth table0%0/2
A
A= $top->create_html({'pos', $pos, 'raw', $html})
Aresult
11
00
1089 pos => $pos,
1090 raw => $html,
1091 }) || die( $top->error );
1092 0 ▶ my $id = $self->document->add_object( $elem ) || die( $top->error );
Condition0%0/2
$self->document->add_object($elem) || die($top->error)
l!l
00
MC/DC0%0/1
$self->document->add_object($elem) || die($top->error)
$self->document->add_object($elem)
Truth table0%0/2
A
A= $self->document->add_object($elem)
Aresult
11
00
1093 0 "${PH_PREFIX}${id}${PH_SUFFIX}\n";
1094 }xgemsi;
1095 }
1096  
1097 # NOTE: blockquote
1098 0 ▶ $self->message_colour( 3, "Does scope have '{green}blockquote{/}' ? ", $scope->has( 'blockquote' ) ? '{green}yes{/}' : '{red}no{/}' );
Branch: 1 branch
BranchTrueFalseTotal
$scope->has('blockquote') ? : 0 0 0
1099 # Blockquote
1100 0 ▶ if( $scope->has( 'blockquote' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has("blockquote")) 0 0 0
1101 {
1102 0 $data =~ s{$RE{Markdown}{Blockquote}}
1103 {
1104 0 my $re = { %+ };
1105 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
1106 0 my $pos = pos( $data );
1107 0 $self->message_colour( 3, $self->whereami( \$data, $pos, { text => "Found a blockquote '{green}" . $re->{bquote_all} . "{/}' at pos '$pos' with capture: " . $self->dump( $re ), return => 1 } ) );
1108 0 my $raw = $re->{bquote_all};
1109 0 my $bq = $raw;
1110 0 $bq =~ s/^[ \t]*>[ \t]?//gm; # trim one level of quoting
1111 0 $bq =~ s/^[ \t]+$//mg; # trim whitespace-only lines
1112 0 my $block = $top->create_blockquote({
1113 pos => $pos,
1114 raw => $raw,
1115 });
1116 0 my $id = $self->document->add_object( $block );
1117 0 $self->parse( $bq, { scope => $self->scope_block, element => $block } );
1118 0 "${PH_PREFIX}${id}${PH_SUFFIX}\n";
1119 }xgems;
1120 }
1121  
1122 # NOTE: line
1123 # Now, the line elements
1124  
1125 # Setext-style headers:
1126 # Header 1 {.main .shine #the-site lang=fr}
1127 # ========
1128 #
1129 # Header 2 {.main .shine #the-site lang=fr}
1130 # --------
1131 #
1132 # This is to be on a single line of its own
1133 0 ▶ $self->message_colour( 3, "Does scope have '{green}header extended{/}' ? ", $scope->has( 'header extended' ) ? '{green}yes{/}' : '{red}no{/}' );
Branch: 1 branch
BranchTrueFalseTotal
$scope->has('header extended') ? : 0 0 0
1134 0 ▶ if( $scope->has( 'header extended' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has("header extended")) 0 0 0
1135 {
1136 0 $data =~ s{$RE{Markdown}{ExtHeader}}
1137 {
1138 0 my $re = { %+ };
1139 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
1140 0 my $pos = pos( $data );
1141 0 $self->message_colour( 3, $self->whereami( \$data, $pos, { text => "Found an extended header '{green}" . $re->{header_all} . "{/}' with header level '{green}" . length( $re->{header_level} ) . "{/}' and attributes '{green}" . $re->{header_attr} . "{/}' at pos '$pos' with capture: " . $self->dump( $re ), return => 1 } ) );
1142 0 my $text = $re->{header_content};
1143 0 my $attr = $re->{header_attr};
1144 my $header = $top->create_header({
1145 level => length( $re->{header_level} ),
1146 pos => $pos,
1147 raw => $re->{header_all},
1148 0 });
1149 # Further process the text capture
1150 # If there are any elements, they will be placed inside the header element as children
1151 0 my $id = $self->document->add_object( $header );
1152 0 $self->parse( $text, { scope => 'inline extended', element => $header } );
1153 0 $header->add_attributes( $attr );
1154 0 "${PH_PREFIX}${id}${PH_SUFFIX}\n";
1155 }xgem;
1156 }
1157  
1158 # NOTE: header
1159 # Checking for headers
1160 # atx-style headers:
1161 # # Header 1
1162 # ## Header 2
1163 # ## Header 2 with closing hashes ##
1164 # ...
1165 # ###### Header 6
1166 0 ▶ $self->message_colour( 3, "Does scope have '{green}header{/}' ? ", $scope->has( 'header' ) ? '{green}yes{/}' : '{red}no{/}' );
Branch: 1 branch
BranchTrueFalseTotal
$scope->has('header') ? : 0 0 0
1167 0 ▶ if( $scope->has( 'header' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has("header")) 0 0 0
1168 {
1169 0 $data =~ s{$RE{Markdown}{Header}}
1170 {
1171 0 my $re = { %+ };
1172 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
1173 0 my $pos = pos( $data );
1174 0 $self->message_colour( 3, $self->whereami( \$data, $pos, { text => "Found a vanilla header '{green}" . $re->{header_all} . "{/}' with header level '{green}" . length( $re->{header_level} ) . "{/}' at pos '$pos' with capture: " . $self->dump( $re ), return => 1 } ) );
1175 0 my $text = $re->{header_content};
1176 my $header = $top->create_header({
1177 level => length( $re->{header_level} ),
1178 pos => $pos,
1179 raw => $re->{header_all},
1180 0 });
1181 # Further process the text capture
1182 # If there are any elements, they will be placed inside the header element as children
1183 0 my $id = $self->document->add_object( $header );
1184 0 $self->parse( $text, { scope => $self->scope_inline, element => $header } );
1185 0 "${PH_PREFIX}${id}${PH_SUFFIX}\n";
1186 }xgem;
1187 }
1188  
1189 # NOTE: list
1190 # List goes before header line because a list with a 2nd empty element could be confused as an header line.
1191 # For example:
1192 # - HIJ
1193 # -
1194  
1195 # List
1196 0 ▶ my $list_re = $self->list_level ? $RE{Markdown}{ListNthLevel} : $RE{Markdown}{ListFirstLevel};
Branch: 1 branch
BranchTrueFalseTotal
$self->list_level ? : 0 0 0
1197 0 ▶ $self->message_colour( 3, "Does scope have '{bold green}list{/}' ? ", $scope->has( 'list' ) ? '{green}yes{/}' : '{red}no{/}', " for scope '", $opts->{scope}->as_string, "'." );
Branch: 1 branch
BranchTrueFalseTotal
$scope->has('list') ? : 0 0 0
1198 0 $self->message_colour( 3, "List level is '{green}", $self->list_level, "{/}'." );
1199 # If I do the following it does not work witht he regexp, but if I do substr( $data, $pos ) it works.
1200 # I am puzzled as to why, and I give up.
1201 # if( $scope->has( 'list' ) && $data =~ /\G$list_re/gmcs )
1202 # if( $scope->has( 'list' ) && substr( $data, $pos ) =~ /\G$list_re/gmcs )
1203 0 ▶ if( $scope->has( 'list' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has("list")) 0 0 0
1204 {
1205 0 $data =~ s{$list_re}
1206 {
1207 0 my $re = { %+ };
1208 0 my $list = $re->{list_all};
1209 # my $list = $re->{list_content};
1210 # my $trailing_nl = ( $list =~ s/(\n+)$// )[0];
1211 # my $nth_nl = length( $trailing_nl );
1212 0 my $nth_nl = $self->_total_trailing_new_lines( $re->{list_all} );
1213 0 my $content = $re->{list_prefix} . $re->{list_content};
1214 0 my $post_nl_id;
1215 0 ▶ if( $nth_nl )
Branch: 1 branch
BranchTrueFalseTotal
if ($nth_nl) 0 0 0
1216 {
1217 0 my $post_nl = $top->create_text({ text => "\n" x $nth_nl });
1218 0 $post_nl_id = $self->document->add_object( $post_nl );
1219 }
1220
1221 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
1222 0 my $pos = pos( $data );
1223 0 ▶ my $list_type = $re->{list_type_ordered} ? 'ol' : 'ul';
Branch: 1 branch
BranchTrueFalseTotal
$re->{'list_type_ordered'} ? : 0 0 0
1224 # Corollary from using substr( $daata, $pos ). We ned to update the position in the string manually
1225 # pos( $data ) = $pos + length( substr( $data, $-[0], $+[0]-$-[0] ) );
1226 # TODO With this new way of processing list, I do not know the indent level anymore. Might want to look into that.
1227 0 my $indent_level = 0;
1228 # Turn double returns into triple returns, so that we can make a
1229 # paragraph for the last item in a list, if necessary:
1230 0 $self->message_colour( 3, $self->whereami( \$data, $pos, { text => "Found a list of type '" . $list_type . "' and {green}${nth_nl}{/} trailing new lines at pos '" . $pos . "':\n'{bold orange}" . $list . "{/}' with capture: " . $self->dump( $re ), return => 1 } ) );
1231 0 ▶ my $new_list = $top->create_list({
Branch: 1 branch
BranchTrueFalseTotal
$list_type eq 'ol' ? : 0 0 0
1232 indent => $indent_level,
1233 pos => $pos,
1234 raw => "${content}\n",
1235 order => $list_type eq 'ol' ? 1 : 0,
1236 });
1237 0 my $id = $self->document->add_object( $new_list );
1238 # $list =~ s/\n{2,}/\n\n\n/g;
1239 0 $self->parse_list_item( $list, { doc => $new_list, pos => pos( $data ) } );
1240 # $nth_nl-- if( $nth_nl > 1 );
1241 # Trailing new lines are also preceding new lines for the next element if more than 1
1242 0 ▶ "${PH_PREFIX}${id}${PH_SUFFIX}" . ( defined( $post_nl_id ) ? "${PH_PREFIX}${post_nl_id}${PH_SUFFIX}" : '' );
Branch: 1 branch
BranchTrueFalseTotal
defined $post_nl_id ? : 0 0 0
1243 }xgems;
1244 }
1245
1246 # NOTE: header line extended
1247 # Ex: Some thing\n
1248 # ==========\n
1249 0 ▶ $self->message_colour( 3, "Does scope have '{green}header line extended{/}' ? ", $scope->has( 'header extended' ) ? '{green}yes{/}' : '{red}no{/}' );
Branch: 1 branch
BranchTrueFalseTotal
$scope->has('header extended') ? : 0 0 0
1250 0 ▶ if( $scope->has( 'header extended' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has("header extended")) 0 0 0
1251 {
1252 0 $data =~ s{$RE{Markdown}{ExtHeaderLine}}
1253 {
1254 0 my $re = { %+ };
1255 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
1256 0 my $pos = pos( $data );
1257 0 $self->message_colour( 3, $self->whereami( \$data, $pos, { text => "Found an extended header line '{green}" . $re->{header_all} . "{/}' with text '{green}" . $re->{header_content} . "{/}' at pos '$pos' with capture: " . $self->dump( $re ), return => 1 } ) );
1258 0 my $text = $re->{header_content};
1259 0 my $raw = $re->{header_all};
1260 0 my $attr = $re->{header_attr};
1261 0 my $levels =
1262 {
1263 '=' => 1,
1264 '-' => 2,
1265 };
1266 my $header = $top->create_header({
1267 0 level => $levels->{ substr( $re->{header_type}, 0, 1 ) },
1268 parent => $top,
1269 pos => $pos,
1270 raw => $raw,
1271 });
1272 0 $header->add_attributes( $attr );
1273
1274 # Further process the text capture
1275 # If there are any elements, they will be placed inside the header element as children
1276 0 my $id = $self->document->add_object( $header );
1277 0 $self->parse( $text, { scope => 'inline extended', element => $header } );
1278 0 "${PH_PREFIX}${id}${PH_SUFFIX}\n";
1279 }xgems;
1280 }
1281  
1282 # NOTE: header line
1283 # Ex: Some thing\n
1284 # ==========\n
1285 0 ▶ $self->message_colour( 3, "Does scope have '{green}header line{/}' ? ", $scope->has( 'header' ) ? '{green}yes{/}' : '{red}no{/}' );
Branch: 1 branch
BranchTrueFalseTotal
$scope->has('header') ? : 0 0 0
1286 0 ▶ if( $scope->has( 'header' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has("header")) 0 0 0
1287 {
1288 0 $data =~ s{$RE{Markdown}{HeaderLine}}
1289 {
1290 0 my $re = { %+ };
1291 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
1292 0 my $pos = pos( $data );
1293 0 $self->message_colour( 3, $self->whereami( \$data, $pos, { text => "Found a vanilla header line '{green}" . $re->{header_all} . "{/}' with text '{green}" . $re->{header_content} . "{/}' at pos '$pos' with capture: " . $self->dump( $re ), return => 1 } ) );
1294 0 my $text = $re->{header_content};
1295 0 my $raw = $re->{header_all};
1296 0 my $levels =
1297 {
1298 '=' => 1,
1299 '-' => 2,
1300 };
1301 my $header = $top->create_header({
1302 0 level => $levels->{ substr( $re->{header_type}, 0, 1 ) },
1303 parent => $top,
1304 pos => $pos,
1305 raw => $raw,
1306 });
1307 # Further process the text capture
1308 # If there are any elements, they will be placed inside the header element as children
1309 0 $self->parse( $text, { scope => $self->scope_inline, element => $header } );
1310 0 my $id = $self->document->add_object( $header );
1311 0 "${PH_PREFIX}${id}${PH_SUFFIX}\n";
1312 }xgems;
1313 }
1314  
1315 # NOTE: line
1316 # Horizontal lines
1317 # * * *
1318 #
1319 # ***
1320 #
1321 # *****
1322 #
1323 # - - -
1324 #
1325 # ---------------------------------------
1326 0 ▶ $self->message_colour( 3, "Does scope have '{green}line{/}' ? ", $scope->has( 'line' ) ? '{green}yes{/}' : '{red}no{/}' );
Branch: 1 branch
BranchTrueFalseTotal
$scope->has('line') ? : 0 0 0
1327 0 ▶ if( $scope->has( 'line' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has("line")) 0 0 0
1328 {
1329 0 $data =~ s{$RE{Markdown}{Line}}
1330 {
1331 0 my $re = { %+ };
1332 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
1333 0 my $pos = pos( $data );
1334 0 $self->message_colour( 3, $self->whereami( \$data, $pos, { text => "Found new horizontal line at pos '$pos': '{green}" . $re->{line_all} . "'{/} with capture: " . $self->dump( $re ), return => 1 } ) );
1335 my $id = $self->document->add_object( $top->create_line({
1336 pos => $pos,
1337 raw => $re->{line_all},
1338 0 }) );
1339 0 "${PH_PREFIX}${id}${PH_SUFFIX}";
1340 }xgem;
1341 }
1342  
1343 # NOTE: paragraph
1344 0 ▶ $self->message_colour( 3, "Does scope have '{green}paragraph{/}' ? ", $scope->has( 'paragraph' ) ? '{green}yes{/}' : '{red}no{/}' );
Branch: 1 branch
BranchTrueFalseTotal
$scope->has('paragraph') ? : 0 0 0
1345 0 ▶ if( $scope->has( 'paragraph' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has("paragraph")) 0 0 0
1346 {
1347 0 $data =~ s{$RE{Markdown}{Paragraph}}
1348 {
1349 0 my $re = { %+ };
1350 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
1351 0 my $pos = pos( $data );
1352 0 my $text = $re->{para_all};
1353 0 my $raw = $re->{para_all};
1354 0 my $nth_nl = $self->_total_trailing_new_lines( $text );
1355 0 my $post_nl_id;
1356 0 ▶ if( $nth_nl )
Branch: 1 branch
BranchTrueFalseTotal
if ($nth_nl) 0 0 0
1357 {
1358 0 my $post_nl = $top->create_text({ text => "\n" x $nth_nl });
1359 0 $post_nl_id = $self->document->add_object( $post_nl );
1360 }
1361 0 $text =~ s/^\n+|\n+$//gs;
1362 # Replace new lines that are not preceded by 2 space or more with 1 space.
1363 0 $text =~ s/(?<![ ]{2})\n/ /gs;
1364 0 $self->message_colour( 3, "Found {green}${nth_nl}{/} trailing new lines." );
1365 0 my $p = $top->create_paragraph({
1366 pos => $pos,
1367 raw => $raw,
1368 });
1369 # Position ourself before the trailing new lines
1370 0 my $id = $self->document->add_object( $p );
1371 0 $self->message_colour( 3, "Sub parsing paragraph content '{green}", $text, "{/}'" );
1372 0 $self->parse( $text, { scope => $self->scope_inline, element => $p } );
1373 # We remove one new line to account for the new line added by as_markdown() method
1374 # $trailing_nl-- if( $trailing_nl > 1 );
1375 # "${PH_PREFIX}${id}${PH_SUFFIX}";
1376 0 ▶ "${PH_PREFIX}${id}${PH_SUFFIX}" . ( defined( $post_nl_id ) ? "${PH_PREFIX}${post_nl_id}${PH_SUFFIX}" : '' );
Branch: 1 branch
BranchTrueFalseTotal
defined $post_nl_id ? : 0 0 0
1377 }xgems;
1378 }
1379 # End of block elements parsing
1380
1381 # NOTE: link extended
1382 # Now the inline elements
1383 0 ▶ $self->message_colour( 3, "Does scope have '{green}link extended{/}' ? ", $scope->has( [qw( link extended )] ) ? '{green}yes{/}' : '{red}no{/}' );
Branch: 1 branch
BranchTrueFalseTotal
$scope->has(['link', 'extended']) ? : 0 0 0
1384 0 ▶ if( $scope->has( [qw( link extended )] ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has(["link", "extended"])) 0 0 0
1385 {
1386 0 $data =~ s{$RE{Markdown}{ExtLink}}
1387 {
1388 0 my $re = { %+ };
1389 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
1390 0 my $pos = pos( $data );
1391 0 my $raw = $re->{link_all};
1392 0 my $id = $re->{link_id};
1393 0 my $name = $re->{link_name};
1394 0 my $title = $re->{link_title};
1395 0 my $url = $re->{link_url};
1396 0 my $def = $re->{link_attr};
1397 0 my $link = $top->create_link({
1398 pos => $pos,
1399 raw => $raw,
1400 });
1401 0 ▶ if( length( $def ) )
Branch: 1 branch
BranchTrueFalseTotal
if (length $def) 0 0 0
1402 {
1403 0 $def =~ s/^[[:blank:]\h]+|[[:blank:]\h]+$//gs;
1404 0 ▶ $link->add_attributes( $def ) if( length( $def ) );
Branch: 1 branch
BranchTrueFalseTotal
if length $def 0 0 0
1405 }
1406 0 my $object_id = $self->document->add_object( $link );
1407 ## An url has been provided, we sub-parse the link name for inline markdown, and especially abbreviations
1408 0 ▶ if( $url )
Branch: 1 branch
BranchTrueFalseTotal
if ($url) { } 0 0 0
1409 {
1410 0 $link->url( $url );
1411 }
1412 ## as in [Example][] instead of [Example][site_id]
1413 else
1414 {
1415 0 ▶ $id = $name if( !length( $id ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $id 0 0 0
1416 0 $link->link_id( $id );
1417 0 my $link_def = $self->document->get_link_by_id( $id );
1418 0 ▶ if( $link_def )
Branch: 1 branch
BranchTrueFalseTotal
if ($link_def) { } 0 0 0
1419 {
1420 0 $title = $link_def->title->scalar;
1421 0 $url = $link_def->url;
1422 0 $link->copy_from( $link_def );
1423 }
1424 else
1425 {
1426 }
1427 0 $link->url( $url );
1428 }
1429 0 $link->title( $title );
1430 0 $self->parse( $name, { element => $link, scope => $self->scope_inline });
1431 0 "${PH_PREFIX}${object_id}${PH_SUFFIX}";
1432 }xgems;
1433 }
1434
1435 # NOTE: link
1436 0 ▶ $self->message_colour( 3, "Does scope have '{green}link{/}' ? ", $scope->has( [qw( link )] ) ? '{green}yes{/}' : '{red}no{/}' );
Branch: 1 branch
BranchTrueFalseTotal
$scope->has(['link']) ? : 0 0 0
1437 0 ▶ if( $scope->has( 'link' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has("link")) 0 0 0
1438 {
1439 0 $data =~ s{$RE{Markdown}{Link}}
1440 {
1441 0 my $re = { %+ };
1442 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
1443 0 my $pos = pos( $data );
1444 0 my $raw = $re->{link_all};
1445 0 my $id = $re->{link_id};
1446 0 my $name = $re->{link_name};
1447 0 my $title = $re->{link_title};
1448 0 my $url = $re->{link_url};
1449 0 my $link = $top->create_link({
1450 pos => $pos,
1451 raw => $raw,
1452 });
1453 0 my $object_id = $self->document->add_object( $link );
1454 # An url has been provided, we sub-parse the link name for inline markdown, and especially abbreviations
1455 0 ▶ if( $url )
Branch: 1 branch
BranchTrueFalseTotal
if ($url) { } 0 0 0
1456 {
1457 0 $link->url( $url );
1458 }
1459 # as in [Example][] instead of [Example][site_id]
1460 else
1461 {
1462 0 ▶ $id = $name if( !length( $id ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $id 0 0 0
1463 0 $link->link_id( $id );
1464 0 my $link_def = $self->document->get_link_by_id( $id );
1465 0 ▶ if( $link_def )
Branch: 1 branch
BranchTrueFalseTotal
if ($link_def) { } 0 0 0
1466 {
1467 0 $title = $link_def->title;
1468 0 $url = $link_def->url;
1469 0 $link->copy_from( $link_def );
1470 }
1471 else
1472 {
1473 }
1474 0 $link->url( $url );
1475 }
1476 0 $link->title( $title );
1477 0 $self->parse( $name, { element => $link, scope => $self->scope_inline });
1478 0 "${PH_PREFIX}${object_id}${PH_SUFFIX}";
1479 }xgems;
1480 }
1481  
1482 # NOTE: auto-link
1483 # Automatic link like <https://example.com> or <news://news.example.com> or <mailto://john@example.com> or <john@example.com>, etc...
1484 0 ▶ $self->message_colour( 3, "Does scope have '{green}auto-link{/}' ? ", $scope->has( [qw( link )] ) ? '{green}yes{/}' : '{red}no{/}' );
Branch: 1 branch
BranchTrueFalseTotal
$scope->has(['link']) ? : 0 0 0
1485 0 ▶ if( $scope->has( 'link' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has("link")) 0 0 0
1486 {
1487 0 $data =~ s{$RE{Markdown}{LinkAuto}}
1488 {
1489 0 my $re = { %+ };
1490 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
1491 0 my $pos = pos( $data );
1492 0 my $raw = $re->{link_all};
1493 0 my $url = $re->{link_url};
1494 # Add the mailto: scheme if it's an e-mail address and the scheme is missing
1495 0 ▶ substr( $url, 0, 0 ) = 'mailto:' if( length( $re->{link_mailto} ) && substr( $re->{link_mailto}, 0, 7 ) ne 'mailto:' );
Branch: 1 branch
BranchTrueFalseTotal
if length $re->{"link_mailto"} and substr($re->{"link_mailto"}, 0, 7) ne "mailto:" 0 0 0
Condition0%0/3
length $re->{"link_mailto"} and substr($re->{"link_mailto"}, 0, 7) ne "mailto:"
!ll&&!rl&&r
000
MC/DC0%0/2
length $re->{"link_mailto"} and substr($re->{"link_mailto"}, 0, 7) ne "mailto:"
length $re->{"link_mailto"} substr($re->{"link_mailto"}, 0, 7) ne "mailto:"
Truth table0%0/3
A and B
A= length $re->{"link_mailto"}B= substr($re->{"link_mailto"}, 0, 7) ne "mailto:"
ABresult
0X0
100
111
1496 my $link = $top->create_link({
1497 encrypt => $self->encrypt_email,
1498 ## We save the original as URI may alter it by url-encoding characters
1499 original => $re->{link_url},
1500 0 pos => $pos,
1501 raw => $raw,
1502 url => $url,
1503 });
1504 # $link->add_element( $link->create_text({
1505 # pos => $pos,
1506 # text => $re->{link_url},
1507 # }) );
1508 0 my $id = $self->document->add_object( $link );
1509 0 "${PH_PREFIX}${id}${PH_SUFFIX}";
1510 }xgems;
1511 }
1512  
1513 # NOTE: image extended
1514 0 ▶ $self->message_colour( 3, "Does scope have '{green}image extended{/}' ? ", $scope->has( [qw( image extended )] ) ? '{green}yes{/}' : '{red}no{/}' );
Branch: 1 branch
BranchTrueFalseTotal
$scope->has(['image', 'extended']) ? : 0 0 0
1515 0 ▶ if( $scope->has( [qw( image extended )] ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has(["image", "extended"])) 0 0 0
1516 {
1517 0 $data =~ s{$RE{Markdown}{ExtImage}}
1518 {
1519 0 my $re = { %+ };
1520 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
1521 0 my $pos = pos( $data );
1522 0 my $raw = $re->{img_all};
1523 0 my $url = $re->{img_url};
1524 0 my $id = $re->{img_id};
1525 0 my $alt = $re->{img_alt};
1526 0 my $attr = $re->{img_attr};
1527 0 my $title = $re->{img_title};
1528 0 my $img = $top->create_image({
1529 alt => $alt,
1530 pos => $pos,
1531 raw => $raw,
1532 });
1533 0 ▶ if( !$url )
Branch: 1 branch
BranchTrueFalseTotal
unless ($url) 0 0 0
1534 {
1535 0 ▶ $id = $alt if( !length( $id ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $id 0 0 0
1536 0 my $img_def = $self->document->get_link_by_id( $id );
1537 0 ▶ if( $img_def )
Branch: 1 branch
BranchTrueFalseTotal
if ($img_def) 0 0 0
1538 {
1539 0 $title = $img_def->title;
1540 0 $url = $img_def->url;
1541 0 $img->copy_from( $img_def );
1542 }
1543 }
1544 0 $img->url( $url );
1545 0 $img->title( $title );
1546 0 ▶ $img->link_id( $id ) if( length( $id ) );
Branch: 1 branch
BranchTrueFalseTotal
if length $id 0 0 0
1547 0 $img->add_attributes( $attr );
1548 0 my $object_id = $self->document->add_object( $img );
1549 0 "${PH_PREFIX}${object_id}${PH_SUFFIX}";
1550 }xgems;
1551 }
1552  
1553 # NOTE: image
1554 0 ▶ $self->message_colour( 3, "Does scope have '{green}image{/}' ? ", $scope->has( [qw( image )] ) ? '{green}yes{/}' : '{red}no{/}' );
Branch: 1 branch
BranchTrueFalseTotal
$scope->has(['image']) ? : 0 0 0
1555 0 ▶ if( $scope->has( 'image' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has("image")) 0 0 0
1556 {
1557 0 $data =~ s{$RE{Markdown}{Image}}
1558 {
1559 0 my $re = { %+ };
1560 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
1561 0 my $pos = pos( $data );
1562 0 my $raw = $re->{img_all};
1563 0 my $url = $re->{img_url};
1564 0 my $id = $re->{img_id};
1565 0 my $alt = $re->{img_alt};
1566 0 my $title = $re->{img_title};
1567 0 my $img = $top->create_image({
1568 alt => $alt,
1569 pos => $pos,
1570 raw => $raw,
1571 });
1572 0 ▶ if( !$url )
Branch: 1 branch
BranchTrueFalseTotal
unless ($url) 0 0 0
1573 {
1574 0 ▶ $id = $alt if( !length( $id ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $id 0 0 0
1575 0 my $img_def = $self->document->get_link_by_id( $id );
1576 0 ▶ if( $img_def )
Branch: 1 branch
BranchTrueFalseTotal
if ($img_def) 0 0 0
1577 {
1578 0 $title = $img_def->title;
1579 0 $url = $img_def->url;
1580 0 $img->copy_from( $img_def );
1581 }
1582 }
1583 0 $img->url( $url );
1584 0 $img->title( $title );
1585 0 ▶ $img->link_id( $id ) if( length( $id ) );
Branch: 1 branch
BranchTrueFalseTotal
if length $id 0 0 0
1586 0 my $object_id = $self->document->add_object( $img );
1587 0 "${PH_PREFIX}${object_id}${PH_SUFFIX}";
1588 }xgems;
1589 }
1590  
1591 # NOTE: bold
1592 # Bold check comes before emphasis one
1593 0 ▶ $self->message_colour( 3, "Does scope have '{green}bold{/}' ? ", $scope->has( 'bold' ) ? '{green}yes{/}' : '{red}no{/}' );
Branch: 1 branch
BranchTrueFalseTotal
$scope->has('bold') ? : 0 0 0
1594 0 ▶ if( $scope->has( 'bold' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has("bold")) 0 0 0
1595 {
1596 0 $data =~ s{$RE{Markdown}{Bold}}
1597 {
1598 0 my $re = { %+ };
1599 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
1600 0 my $pos = pos( $data );
1601 0 my $content = $re->{bold_text};
1602 my $bold = $top->create_bold({
1603 pos => pos( $data ),
1604 raw => $re->{bold_all},
1605 type => $re->{bold_type},
1606 0 });
1607 0 $self->parse( $content, { element => $bold, scope => $self->scope_inline });
1608 0 my $id = $self->document->add_object( $bold );
1609 0 "${PH_PREFIX}${id}${PH_SUFFIX}";
1610 }xgems;
1611 }
1612  
1613 # NOTE: emphasis
1614 0 ▶ $self->message_colour( 3, "Does scope have '{green}emphasis{/}' ? ", $scope->has( 'emphasis' ) ? '{green}yes{/}' : '{red}no{/}' );
Branch: 1 branch
BranchTrueFalseTotal
$scope->has('emphasis') ? : 0 0 0
1615 0 ▶ if( $scope->has( 'emphasis' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has("emphasis")) 0 0 0
1616 {
1617 0 $data =~ s{$RE{Markdown}{Em}}
1618 {
1619 0 my $re = { %+ };
1620 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
1621 0 my $pos = pos( $data );
1622 my $em = $top->create_em({
1623 pos => $pos,
1624 raw => $re->{em_all},
1625 type => $re->{em_type},
1626 0 });
1627 0 my $content = $re->{em_text};
1628 0 $self->parse( $content, { element => $em, scope => $self->scope_inline });
1629 0 my $id = $self->document->add_object( $em );
1630 0 "${PH_PREFIX}${id}${PH_SUFFIX}";
1631 }gexms;
1632 }
1633
1634 # NOTE: code span
1635 # Inline code `some thing`
1636 0 ▶ $self->message_colour( 3, "Does scope have '{green}code span{/}' ? ", $scope->has( [qw( code_span )] ) ? '{green}yes{/}' : '{red}no{/}' );
Branch: 1 branch
BranchTrueFalseTotal
$scope->has(['code_span']) ? : 0 0 0
1637 0 ▶ if( $scope->has( 'code_span' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has("code_span")) 0 0 0
1638 {
1639 0 $data =~ s{$RE{Markdown}{CodeSpan}}
1640 {
1641 0 my $re = { %+ };
1642 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
1643 0 my $pos = pos( $data );
1644 0 my $raw = $re->{code_all};
1645 0 my $content = $re->{code_content};
1646 0 $self->message_colour( 3, $self->whereami( \$data, $pos, { text => "Found an inline code '$raw' at pos '$pos' with content:\n'{green}" . $content . "{/}' and with capture: " . $self->dump( $re ), return => 1 } ) );
1647 ## leading whitespace
1648 0 $content =~ s/^[ \t]*//g;
1649 ## trailing whitespace
1650 0 $content =~ s/[ \t]*$//g;
1651 0 my $code = $top->create_code({
1652 inline => 1,
1653 pos => $pos,
1654 raw => $raw,
1655 });
1656 0 $code->add_element( $top->create_text({
1657 text => $content,
1658 pos => $pos,
1659 }) );
1660 0 my $id = $top->add_object( $code );
1661 0 "${PH_PREFIX}${id}${PH_SUFFIX}";
1662 }xgems;
1663 }
1664
1665 # NOTE: checkbox extended
1666 0 ▶ $self->message_colour( 3, "Does scope have '{green}checkbox{/}' ? ", $scope->has( [qw( checkbox extended )] ) ? '{green}yes{/}' : '{red}no{/}' );
Branch: 1 branch
BranchTrueFalseTotal
$scope->has(['checkbox', 'extended']) ? : 0 0 0
1667 0 ▶ if( $scope->has( [qw( checkbox extended )] ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has(["checkbox", "extended"])) 0 0 0
1668 {
1669 0 $data =~ s{$RE{Markdown}{ExtCheckbox}}
1670 {
1671 0 my $re = { %+ };
1672 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
1673 0 my $pos = pos( $data );
1674 my $check = $top->create_checkbox({
1675 checked => lc( $re->{check_content} ) eq 'x',
1676 raw => $re->{check_all},
1677 0 pos => $pos,
1678 });
1679 0 my $id = $self->document->add_object( $check );
1680 0 "${PH_PREFIX}${id}${PH_SUFFIX}";
1681 }xgems;
1682 }
1683
1684 # NOTE: katex
1685 0 ▶ $self->message_colour( 3, "Does scope have '{green}katex{/}' ? ", ( $scope->has( [qw( katex extended )] ) ? '{green}yes{/}' : '{red}no{/}' ) );
Branch: 1 branch
BranchTrueFalseTotal
$scope->has(['katex', 'extended']) ? : 0 0 0
1686 0 ▶ if( length( $katex_re ) && $scope->has( [qw( katex extended )] ) )
Branch: 1 branch
BranchTrueFalseTotal
if (length $katex_re and $scope->has(["katex", "extended"])) 0 0 0
Condition0%0/3
length $katex_re and $scope->has(["katex", "extended"])
!ll&&!rl&&r
000
MC/DC0%0/2
length $katex_re and $scope->has(["katex", "extended"])
length $katex_re $scope->has(["katex", "extended"])
Truth table0%0/3
A and B
A= length $katex_reB= $scope->has(["katex", "extended"])
ABresult
0X0
100
111
1687 {
1688 0 $data =~ s{$katex_re}
1689 {
1690 0 my $re = { %+ };
1691 0 my $raw = $re->{katex_all};
1692 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
1693 0 my $pos = pos( $data );
1694 ## There is at least one new line, so this is a block, we use paragraph
1695 0 my $id;
1696 0 ▶ if( index( $raw, "\n" ) != -1 )
Branch: 1 branch
BranchTrueFalseTotal
if (index($raw, "\n") != -1) { } 0 0 0
1697 {
1698 0 my $p = $top->create_paragraph({
1699 pos => $pos,
1700 raw => $raw,
1701 });
1702 $p->add_element( $p->create_text({
1703 pos => $pos,
1704 text => $re->{katex_all},
1705 0 }) );
1706 0 $id = $self->document->add_object( $p );
1707 }
1708 ## Inline style
1709 else
1710 {
1711 $id = $self->document->add_object( $top->create_text({
1712 pos => $pos,
1713 text => $re->{katex_all},
1714 0 }) );
1715 }
1716 0 $self->document->setup_katex;
1717 0 "${PH_PREFIX}${id}${PH_SUFFIX}";
1718 }xgems;
1719 }
1720
1721 # NOTE: strikethrough
1722 0 ▶ $self->message_colour( 3, "Does scope have '{green}strikethrough{/}' ? ", $scope->has( [qw( strikethrough extended )] ) ? '{green}yes{/}' : '{red}no{/}' );
Branch: 1 branch
BranchTrueFalseTotal
$scope->has(['strikethrough', 'extended']) ? : 0 0 0
1723 0 ▶ if( $scope->has( [qw( strikethrough extended )] ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has(["strikethrough", "extended"])) 0 0 0
1724 {
1725 0 $data =~ s{$RE{Markdown}{ExtStrikeThrough}}
1726 {
1727 0 my $re = { %+ };
1728 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
1729 0 my $pos = pos( $data );
1730 0 my $text = $re->{strike_content};
1731 my $strike = $top->create_strikethrough({
1732 raw => $re->{strike_all},
1733 0 pos => $pos,
1734 });
1735 0 $strike->add_element( $strike->create_text({
1736 pos => $pos,
1737 text => $text,
1738 }) );
1739 0 my $id = $self->document->add_object( $strike );
1740 0 "${PH_PREFIX}${id}${PH_SUFFIX}";
1741 }xgems;
1742 }
1743
1744 # NOTE: insertion
1745 0 ▶ $self->message_colour( 3, "Does scope have '{green}insertion{/}' ? ", $scope->has( [qw( insertion extended )] ) ? '{green}yes{/}' : '{red}no{/}' );
Branch: 1 branch
BranchTrueFalseTotal
$scope->has(['insertion', 'extended']) ? : 0 0 0
1746 0 ▶ if( $scope->has( [qw( insertion extended )] ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has(["insertion", "extended"])) 0 0 0
1747 {
1748 0 $data =~ s{$RE{Markdown}{ExtInsertion}}
1749 {
1750 0 my $re = { %+ };
1751 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
1752 0 my $pos = pos( $data );
1753 0 my $text = $re->{ins_content};
1754 my $ins = $top->create_insertion({
1755 raw => $re->{ins_all},
1756 0 pos => $pos,
1757 });
1758 0 $ins->add_element( $ins->create_text({
1759 pos => $pos,
1760 text => $text,
1761 }) );
1762 0 my $id = $self->document->add_element( $ins );
1763 0 "${PH_PREFIX}${id}${PH_SUFFIX}";
1764 }xgems;
1765 }
1766
1767 # NOTE: subscript
1768 0 ▶ $self->message_colour( 3, "Does scope have '{green}subscript{/}' ? ", $scope->has( [qw( subscript extended )] ) ? '{green}yes{/}' : '{red}no{/}' );
Branch: 1 branch
BranchTrueFalseTotal
$scope->has(['subscript', 'extended']) ? : 0 0 0
1769 0 ▶ if( $scope->has( [qw( subscript extended )] ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has(["subscript", "extended"])) 0 0 0
1770 {
1771 0 $data =~ s{$RE{Markdown}{ExtSubscript}}
1772 {
1773 0 my $re = { %+ };
1774 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
1775 0 my $pos = pos( $data );
1776 0 my $text = $re->{sub_text};
1777 my $sub = $top->create_subscript({
1778 raw => $re->{sub_all},
1779 0 pos => $pos,
1780 });
1781 0 $sub->add_element( $sub->create_text({
1782 pos => $pos,
1783 text => $text,
1784 }) );
1785 0 my $id = $self->document->add_object( $sub );
1786 0 "${PH_PREFIX}${id}${PH_SUFFIX}";
1787 }xgems;
1788 }
1789
1790 # NOTE: superscript
1791 0 ▶ $self->message_colour( 3, "Does scope have '{green}superscript{/}' ? ", $scope->has( [qw( superscript extended )] ) ? '{green}yes{/}' : '{red}no{/}' );
Branch: 1 branch
BranchTrueFalseTotal
$scope->has(['superscript', 'extended']) ? : 0 0 0
1792 0 ▶ if( $scope->has( [qw( superscript extended )] ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has(["superscript", "extended"])) 0 0 0
1793 {
1794 0 $data =~ s{$RE{Markdown}{ExtSuperscript}}
1795 {
1796 0 my $re = { %+ };
1797 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
1798 0 my $pos = pos( $data );
1799 0 my $text = $re->{sup_text};
1800 my $sup = $top->create_superscript({
1801 raw => $re->{sup_all},
1802 0 pos => $pos,
1803 });
1804 0 $sup->add_element( $sup->create_text({
1805 pos => $pos,
1806 text => $text,
1807 }) );
1808 0 my $id = $self->document->add_object( $sup );
1809 0 "${PH_PREFIX}${id}${PH_SUFFIX}";
1810 }xgems;
1811 }
1812
1813 # $self->message_colour( 3, "Does scope have '{green}line break extended{/}' ? ", $scope->has( [qw( line_break extended )] ) ? '{green}yes{/}' : '{red}no{/}' );
1814 # if( $scope->has( [qw( line_break extended )] ) )
1815 # {
1816 # $data =~ s{$RE{Markdown}{ExtLineBreak}}
1817 # {
1818 # my $re = { %+ };
1819 # # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
1820 # my $pos = pos( $data );
1821 # $self->message_colour( 3, $self->whereami( \$data, $pos, { text => "Found an extended {green}line break{/} (end of line possibly prepended by 2 or more spaces) at pos '" . $pos . "' with capture: " . $self->dump( $re ), return => 1 } ) );
1822 # my $id = $self->document->add_object( $top->create_new_line({
1823 # break => 1,
1824 # pos => $pos,
1825 # }) );
1826 # "${PH_PREFIX}${id}${PH_SUFFIX}";
1827 # }xgems;
1828 # }
1829
1830 # NOTE: line break
1831 0 ▶ $self->message_colour( 3, "Does scope have '{green}line break{/}' ? ", $scope->has( [qw( line_break )] ) ? '{green}yes{/}' : '{red}no{/}' );
Branch: 1 branch
BranchTrueFalseTotal
$scope->has(['line_break']) ? : 0 0 0
1832 0 ▶ if( $scope->has( 'line_break' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has("line_break")) 0 0 0
1833 {
1834 0 $data =~ s{$RE{Markdown}{LineBreak}}
1835 {
1836 0 my $re = { %+ };
1837 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
1838 0 my $pos = pos( $data );
1839 0 $self->message_colour( 3, $self->whereami( \$data, $pos, { text => "Found a {green}line break{/} (end of line prepended by 2 or more spaces) at pos '" . $pos . "' with capture: " . $self->dump( $re ), return => 1 } ) );
1840 0 my $id = $self->document->add_object( $top->create_new_line({
1841 break => 1,
1842 pos => $pos,
1843 }) );
1844 0 "${PH_PREFIX}${id}${PH_SUFFIX}";
1845 }xgems;
1846 }
1847  
1848 # NOTE: footnote backreference
1849 # This is a placeholder added at the end of the footnote text where we will insert a back reference link
1850 0 $data =~ s{(?<fn_backref>[ ]+\!{2}FN\!{2})}
1851 {
1852 0 my $re = { %+ };
1853 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
1854 0 my $pos = pos( $data );
1855 my $id = $self->document->add_object( $top->create_text({
1856 pos => $pos,
1857 text => $re->{fn_backref},
1858 0 }) );
1859 0 "${PH_PREFIX}${id}${PH_SUFFIX}";
1860 }xgems;
1861
1862 # NOTE: abbreviation
1863 0 ▶ $self->message_colour( 3, "Does scope have '{green}abbr{/}' ? ", $scope->has( [qw( extended abbr )] ) ? '{green}yes{/}' : '{red}no{/}' );
Branch: 1 branch
BranchTrueFalseTotal
$scope->has(['extended', 'abbr']) ? : 0 0 0
1864 # Now find and replace any match with its corresponding expanded name
1865 0 ▶ if( length( $abbr_re ) && $scope->has( [qw( extended abbr )] ) )
Branch: 1 branch
BranchTrueFalseTotal
if (length $abbr_re and $scope->has(["extended", "abbr"])) 0 0 0
Condition0%0/3
length $abbr_re and $scope->has(["extended", "abbr"])
!ll&&!rl&&r
000
MC/DC0%0/2
length $abbr_re and $scope->has(["extended", "abbr"])
length $abbr_re $scope->has(["extended", "abbr"])
Truth table0%0/3
A and B
A= length $abbr_reB= $scope->has(["extended", "abbr"])
ABresult
0X0
100
111
1866 {
1867 0 $data =~ s{\b(?<abbr_name>$abbr_re)\b}
1868 {
1869 0 my $re = { %+ };
1870 # my $pos = pos( $data ) - length( substr( $data, $-[0], $+[0] - $-[0] ) );
1871 0 my $pos = pos( $data );
1872 ## We save what we caught to put it back in case the abbreviation lookup failed
1873 0 my $catch = substr( $data, $-[0], $+[0] - $-[0] );
1874 0 ▶ if( defined( my $abbr = $self->document->get_abbreviation( $re->{abbr_name} ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $abbr = $self->document->get_abbreviation($re->{'abbr_name'}))) { } 0 0 0
1875 {
1876 0 my $id = $self->document->add_object( $abbr->clone );
1877 0 "${PH_PREFIX}${id}${PH_SUFFIX}";
1878 }
1879 # Failed somehow
1880 else
1881 {
1882 0 "$catch";
1883 }
1884 }xge;
1885 }
1886
1887 0 ▶ $self->message_colour( 3, "{orange}", ( $top->tag_name eq 'top' ? 'Parsing' : 'Sub-parsing' ), " done.{/}" );
Branch: 1 branch
BranchTrueFalseTotal
$top->tag_name eq 'top' ? : 0 0 0
1888
1889 0 ▶ if( $top->tag_name eq 'top' )
Branch: 1 branch
BranchTrueFalseTotal
if ($top->tag_name eq "top") 0 0 0
1890 {
1891 # We need to separate parsing of footnotes' text in a second step, so we do this here
1892 $top->footnotes->foreach(sub
1893 {
1894 0 ▶ $_->parse( $self );
Subroutine __ANON__: not called CC=1 SCAR=6.9
1895 0 });
1896 }
1897
1898 # NOTE: ultra fast parsing
1899 0 my $parts = [ split( m/\Q${PH_PREFIX}\E(?<object_id>\d+)\Q${PH_SUFFIX}\E\n?/, $data ) ];
1900 0 $self->message( 3, "Parts are: '", join( "', '", @$parts ), "'." );
1901 0 my $objects = $self->document->objects;
1902 0 ▶ for( my $n = 0; $n <= scalar( @$parts ); $n++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($n <= scalar @$parts) 0 0 0
1903 {
1904 # When $n is an even number, it means this is a text, otherwise it is an object id
1905 # If this is a text, we create a text object and add it to the tree
1906 0 ▶ if( $n % 2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($n % 2) { } 0 0 0
1907 {
1908 0 my $id = $parts->[ $n ];
1909 0 ▶ next if( !length( $id ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $id 0 0 0
1910 0 my $obj = $objects->get( $id );
1911 0 ▶ if( ref( $obj ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $obj) { } 0 0 0
1912 {
1913 0 $cb->( $obj );
1914 0 $top->add_element( $obj );
1915 }
1916 else
1917 {
1918 0 $self->message_colour( 3, "{bold red}No object found for id \"", $id, "\"!{/}" );
1919 }
1920 }
1921 else
1922 {
1923 0 my $obj = $top->create_text({
1924 text => $parts->[ $n ],
1925 });
1926 0 $cb->( $obj );
1927 0 $top->add_element( $obj );
1928 }
1929 }
1930 0 return( $top );
1931 }
1932  
1933 sub parse_file
1934 {
1935 0 ▶ my $self = shift( @_ );
Subroutine parse_file: not called CC=8 SCAR=42.8
Pod documented
1936 0 ▶ my $file = shift( @_ ) || return( $self->error( "No file to parse was provided." ) );
Condition0%0/2
shift @_ || (return $self->error('No file to parse was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No file to parse was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
1937 0 ▶ return( $self->error( "Markdown file provided \"$file\" does not exist." ) ) if( !-e( $file ) );
Branch: 1 branch
BranchTrueFalseTotal
unless -e $file 0 0 0
1938 0 ▶ return( $self->error( "Markdown file provided \"$file\" is actually a directory." ) ) if( -d( $file ) );
Branch: 1 branch
BranchTrueFalseTotal
if -d $file 0 0 0
1939 0 ▶ return( $self->error( "Markdown file provided \"$file\" is empty." ) ) if( -z( $file ) );
Branch: 1 branch
BranchTrueFalseTotal
if -z $file 0 0 0
1940 0 ▶ return( $self->error( "Markdown file provided \"$file\" does not have read permission." ) ) if( !-r( $file ) );
Branch: 1 branch
BranchTrueFalseTotal
unless -r $file 0 0 0
1941 0 ▶ my $io = IO::File->new( "<$file" ) || return( $self->error( "Unable to open markdown file \"$file\": $!" ) );
Condition0%0/2
'IO::File'->new("<$file") || (return $self->error(qq[Unable to open markdown file "$file": $!]))
l!l
00
MC/DC0%0/1
'IO::File'->new("<$file") || (return $self->error(qq[Unable to open markdown file "$file": $!]))
'IO::File'->new("<$file")
Truth table0%0/2
A
A= 'IO::File'->new("<$file")
Aresult
11
00
1942 0 my $charset = $self->charset;
1943 0 ▶ $io->binmode( ":encode(${charset})" ) if( length( $charset ) );
Branch: 1 branch
BranchTrueFalseTotal
if length $charset 0 0 0
1944 0 my $data = join( '', $io->getlines );
1945 0 $io->close;
1946 0 return( $self->parse( $data ) );
1947 }
1948  
1949 sub parse_list_item
1950 {
1951 0 ▶ my $self = shift( @_ );
Subroutine parse_list_item: not called CC=6 SCAR=37.4
Pod documented
1952 0 ▶ my $text = shift( @_ ) || '';
Condition0%0/2
shift @_ || ''
l!l
00
MC/DC0%0/1
shift @_ || ''
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
1953 0 my $opts = {};
1954 0 ▶ $opts = shift( @_ ) if( $self->_is_hash( $opts ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_hash($opts) 0 0 0
1955 my $top = $opts->{doc} || do
1956 0 ▶ {
Condition0%0/3
$opts->{'doc'} || do { warn "No element object provided as a container.\n"; return $self->error('No element object provided as a container.') }
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{'doc'} || do { warn "No element object provided as a container.\n"; return $self->error('No element object provided as a container.') }
$opts->{'doc'} do { warn "No element object provided as a container.\n"; return $self->error('No element object provided as a container.') }
Truth table0%0/3
A || B
A= $opts->{'doc'}B= do { warn "No element object provided as a container.\n"; return $self->error('No element object provided as a container.') }
ABresult
1X1
011
000
1957 0 warn( "No element object provided as a container.\n" );
1958 0 return( $self->error( "No element object provided as a container." ) );
1959 };
1960 0 $opts->{pos} = int( $opts->{pos} );
1961 $self->message_colour( 3, "Parsing list item '{bold green}", $text, "{/}' with options: ", sub{ $self->dump( $opts, {
1962 filter => sub
1963 {
1964 0 ▶ my( $ctx, $ref ) = @_;
Subroutine __ANON__: not called CC=4 SCAR=30.0
1965 0 ▶ if( $ctx->class eq 'Markdown::Parser::Document' )
Branch: 2 branches
BranchTrueFalseTotal
if ($ctx->class eq 'Markdown::Parser::Document') { } 0 0 0
elsif ($ctx->is_blessed and $ref->isa('Markdown::Parser::Element')) { } 0 0 0
1966 {
1967 0 return({ dump => overload::StrVal( $ref ) });
1968 }
1969 ▶ elsif( $ctx->is_blessed && $ref->isa( 'Markdown::Parser::Element' ) )
Condition0%0/3
$ctx->is_blessed and $ref->isa("Markdown::Parser::Element")
!ll&&!rl&&r
000
MC/DC0%0/2
$ctx->is_blessed and $ref->isa("Markdown::Parser::Element")
$ctx->is_blessed $ref->isa("Markdown::Parser::Element")
Truth table0%0/3
A and B
A= $ctx->is_blessedB= $ref->isa("Markdown::Parser::Element")
ABresult
0X0
100
111
1970 {
1971 0 return({ dump => overload::StrVal( $ref ) });
1972 }
1973 }
1974 0 ▶ }) } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
1975 # If more than 1 trailing new lines, our caller should hae dealt with it be putting back any excess of 1, because those are the preceding new lines for the next element and it is important for parsing.
1976 0 $text =~ s/\n{2,}\z/\n/;
1977 # my @post_nl = ();
1978 # $text =~ s{(\n{2,})\z}
1979 # {
1980 # my $n = length( $1 );
1981 # $n--;
1982 # $self->message_colour( 4, "Adding {green}${n}{/} new lines at end of list." );
1983 # if( $n > 0 )
1984 # {
1985 # for( my $i = 0; $i < $n; $i++ )
1986 # {
1987 # my $nl = $top->create_new_line({ break => 1 });
1988 # push( @post_nl, $nl );
1989 # }
1990 # }
1991 # "\n";
1992 # }xgems;
1993 0 $self->list_level++;
1994 0 $text =~ s{$RE{Markdown}{ListItem}}
1995 {
1996 0 my $re = { %+ };
1997 0 my $item = $re->{li_content};
1998 0 my $leading_line = $re->{li_lead_line};
1999 0 my $leading_space = $re->{li_lead_space};
2000 0 my $list_type = $re->{list_type_any};
2001 0 my $list_line = $re->{li_all};
2002
2003 0 my $indent = $leading_space;
2004 0 $indent =~ s/\t/ /gs;
2005 # int() because length on undef produces undef
2006 0 my $total_spaces = int( length( $indent ) );
2007 0 my $indent_level = POSIX::ceil( $total_spaces / 4 );
2008 0 $self->message_colour( 3, "Found a list item of type '{green}", $list_type, "{/}' with indent level '{green}", $indent_level, "{/}' (total spaces found = '", $total_spaces, "') and list item line '{green}", $re->{list_line}, "{/}' list item '{green}", $item, "{/}'. List indentation is '", $indent, "'" );
2009
2010 my $li = $top->create_list_item({
2011 indent => ( $indent_level + 1 ),
2012 0 pos => $opts->{pos} + pos( $text ),
2013 raw => $list_line,
2014 type => $list_type,
2015 # Alternatively
2016 # order => 1, # or 0
2017 });
2018 0 $top->add_element( $li );
2019  
2020 0 ▶ if( $leading_line || ( $item =~ m/\n{2,}/) )
Branch: 1 branch
BranchTrueFalseTotal
if ($leading_line or $item =~ /\n{2,}/) { } 0 0 0
Condition0%0/3
$leading_line or $item =~ /\n{2,}/
l!l&&r!l&&!r
000
MC/DC0%0/2
$leading_line or $item =~ /\n{2,}/
$leading_line $item =~ /\n{2,}/
Truth table0%0/3
A or B
A= $leading_lineB= $item =~ /\n{2,}/
ABresult
1X1
011
000
2021 {
2022 0 $item =~ s/^(\t|[ ]{1,4})//gm;
2023 0 $self->message_colour( 3, "{white on blue}Processing list content: '$item'{/} with list level '", $self->list_level, "'" );
2024 0 $self->parse( $item, { scope => $self->scope_block, element => $li } );
2025 }
2026 else
2027 {
2028 # Recursion for sub-lists:
2029 0 $item =~ s/^(\t|[ ]{1,4})//gm;
2030 0 $self->message_colour( 3, "{white on orange}Processing sub list with content: '$item'{/} with list level '", $self->list_level, "'" );
2031 0 $self->parse( $item, { scope => [qw( extended list||inline )], element => $li } );
2032 }
2033 }xgems;
2034 # for( @post_nl )
2035 # {
2036 # $top->add_element( $_ );
2037 # }
2038 0 $self->list_level++;
2039 0 return( $self );
2040 }
2041  
2042 sub parse_table
2043 {
2044 0 ▶ my $self = shift( @_ );
Subroutine parse_table: not called CC=18 SCAR=58.3
Pod documented
2045 # Hash reference of capture groups: %-
2046 # See perlvar for more information
2047 0 my $re = shift( @_ );
2048 0 my $opts = {};
2049 0 ▶ $opts = shift( @_ ) if( $self->_is_hash( $opts ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_hash($opts) 0 0 0
2050 my $top = $opts->{doc} || do
2051 0 ▶ {
Condition0%0/3
$opts->{'doc'} || do { warn "No element object provided as a container.\n"; return $self->error('No element object provided as a container.') }
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{'doc'} || do { warn "No element object provided as a container.\n"; return $self->error('No element object provided as a container.') }
$opts->{'doc'} do { warn "No element object provided as a container.\n"; return $self->error('No element object provided as a container.') }
Truth table0%0/3
A || B
A= $opts->{'doc'}B= do { warn "No element object provided as a container.\n"; return $self->error('No element object provided as a container.') }
ABresult
1X1
011
000
2052 0 warn( "No element object provided as a container.\n" );
2053 0 return( $self->error( "No element object provided as a container." ) );
2054 };
2055 0 my $tbl = $top->create_table(
2056 use_css_grid => $self->css_grid,
2057 ## shared css object
2058 css => $self->css,
2059 );
2060 0 $self->document->add_object( $tbl );
2061 0 my $info =
2062 {
2063 cols => {},
2064 rows => {},
2065 };
2066 0 my $seps = $self->new_array;
2067 0 my $headers = [split( /\n/, $re->{table_headers}->[0] )];
2068 0 for my $i ( 0..$#$headers )
2069 {
2070 ## This is a separator, store our data to the array $headers
2071 0 ▶ if( $headers->[$i] =~ /^[\|\-\+\: ]+$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($headers->[$i] =~ /^[\|\-\+\: ]+$/) 0 0 0
2072 {
2073 0 splice( @$headers, $i, 1 );
2074 0 $i--;
2075 }
2076 }
2077 # We check for leading space (up to 3), otherwise this would be code
2078 # and we use this leading space when parsing rows to factor in leading empty cells, i.e.
2079 # -------
2080 # | # <- this is an empty cell, but
2081 # ----
2082 # | A | # <- the space before the leading pipe is not
2083 0 my $leading_space = 0;
2084 # Check the space at the beginning of separator line as reference
2085 0 ▶ if( $re->{table_header_sep}->[0] =~ /^([[:blank:]\h]+)/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($re->{"table_header_sep"}[0] =~ /^([[:blank:]\h]+)/) 0 0 0
2086 {
2087 0 $leading_space = length( $leading_space );
2088 }
2089
2090 # Process the separator(s) in the header to find
2091 0 for my $i ( 0..1 )
2092 {
2093 0 ▶ $seps->push( $re->{table_header_sep}->[$i] ) if( length( $re->{table_header_sep}->[$i] ) );
Branch: 1 branch
BranchTrueFalseTotal
if length $re->{"table_header_sep"}[$i] 0 0 0
2094 }
2095 0 my $cell_align = $self->new_array;
2096 $seps->for(sub
2097 {
2098 0 ▶ my( $n, $s ) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
2099 0 $s =~ s/^[\+\|\-][[:blank:]\h]+|[[:blank:]\h]+[\+\|\-]$//g;
2100 0 ▶ return if( index( $s, ':' ) == -1 );
Branch: 1 branch
BranchTrueFalseTotal
if (index($s, ":") == -1) 0 0 0
2101 0 my $cells = $self->new_array( [split( /[\+\|]/, $s )] );
2102 $cells->for(sub
2103 {
2104 0 ▶ my( $i, $c ) = @_;
Subroutine __ANON__: not called CC=6 SCAR=37.4
2105 0 $c =~ s/^[[:blank:]\h\v]+|[[:blank:]\h\v]+$//g;
2106 0 ▶ return if( !length( $c ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $c 0 0 0
2107 0 my( $left, $right );
2108 0 ▶ $left = 1 if( substr( $c, 0, 1 ) eq ':' );
Branch: 1 branch
BranchTrueFalseTotal
if substr($c, 0, 1) eq ":" 0 0 0
2109 0 ▶ $right = 1 if( substr( $c, -1, 1 ) eq ':' );
Branch: 1 branch
BranchTrueFalseTotal
if substr($c, -1, 1) eq ":" 0 0 0
2110 ## First row, so we just assign the value
2111 0 ▶ if( $n == 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($n == 0) { } 0 0 0
2112 {
2113 0 $cell_align->push({ left => $left, right => $right });
2114 }
2115 else
2116 {
2117 0 my $prev = $cell_align->index( $i );
2118 0 ▶ if( !defined( $prev ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $prev) 0 0 0
2119 {
2120 0 $cell_align->[ $i ] = { left => $left, right => $right };
2121 }
2122 }
2123 0 });
2124 0 });
2125
2126 0 my $caption;
2127 0 ▶ if( $re->{table_caption}->[0] || $re->{table_caption}->[1] )
Branch: 1 branch
BranchTrueFalseTotal
if ($re->{"table_caption"}[0] or $re->{"table_caption"}[1]) 0 0 0
Condition0%0/3
$re->{"table_caption"}[0] or $re->{"table_caption"}[1]
l!l&&r!l&&!r
000
MC/DC0%0/2
$re->{"table_caption"}[0] or $re->{"table_caption"}[1]
$re->{"table_caption"}[0] $re->{"table_caption"}[1]
Truth table0%0/3
A or B
A= $re->{"table_caption"}[0]B= $re->{"table_caption"}[1]
ABresult
1X1
011
000
2128 {
2129 0 ▶ $caption = $re->{table_caption}->[0] // $re->{table_caption}->[1];
Condition0%0/3
$re->{"table_caption"}[0] // $re->{"table_caption"}[1]
l!l&&r!l&&!r
000
MC/DC0%0/2
$re->{"table_caption"}[0] // $re->{"table_caption"}[1]
$re->{"table_caption"}[0] $re->{"table_caption"}[1]
Truth table0%0/3
A // B
A= $re->{"table_caption"}[0]B= $re->{"table_caption"}[1]
ABresult
1X1
011
000
2130 0 $caption =~ s/^[[:blank:]\h]*\[|\][[:blank:]\h\v]*$//gs;
2131 0 ▶ if( length( $caption ) )
Branch: 1 branch
BranchTrueFalseTotal
if (length $caption) 0 0 0
2132 {
2133 0 my $cap = $tbl->create_table_caption;
2134 0 $self->parse( $caption, { element => $cap, scope => 'inline' });
2135 # $cap->add_element( $cap->create_text({ text => $caption }) );
2136 0 $tbl->caption( $cap );
2137 0 ▶ $cap->position( $re->{table_caption_bottom}->[0] ? 'bottom' : 'top' );
Branch: 1 branch
BranchTrueFalseTotal
$re->{'table_caption_bottom'}[0] ? : 0 0 0
2138 }
2139 }
2140
2141 ## Getting an array ref of array ref containing row objects
2142 0 my $hdrs_rows = $self->parse_table_row( $headers, { doc => $top, alignment => $cell_align, leading_space => $leading_space });
2143 0 my $header = $top->create_table_header;
2144 ## Possibly multiple rows in the header, but only one table header
2145 0 foreach my $rows ( @$hdrs_rows )
2146 {
2147 0 $header->children->push( @$rows );
2148 }
2149 0 $tbl->header( $header );
2150
2151 0 my $body_rows = $self->parse_table_row( $re->{table_rows}->[0], { doc => $top, alignment => $cell_align });
2152 ## Possibly multiple table body
2153 0 foreach my $rows ( @$body_rows )
2154 {
2155 0 my $body = $top->create_table_body;
2156 0 $body->children->push( @$rows );
2157 0 ▶ $tbl->add_body( $body ) || return( $self->error( "Could not add body: ", $tbl->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$tbl->add_body($body) or return $self->error("Could not add body: ", $tbl->error) 0 0 0
2158 }
2159
2160 0 foreach my $this ( $hdrs_rows, $body_rows )
2161 {
2162 0 for my $i ( 0..$#$this )
2163 {
2164 0 $info->{rows}->{total} += scalar( @{$this->[$i]} );
2165 }
2166 }
2167 0 $info->{cols}->{total} = scalar( keys( %{$info->{cols}} ) );
2168 0 $tbl->stat( $info );
2169 0 return( $tbl );
2170 }
2171  
2172 sub parse_table_row
2173 {
2174 0 ▶ my $self = shift( @_ );
Subroutine parse_table_row: not called CC=35 SCAR=71.4
Pod documented
2175 0 my $str = shift( @_ );
2176 0 my $opts = {};
2177 0 ▶ $opts = shift( @_ ) if( $self->_is_hash( $opts ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_hash($opts) 0 0 0
2178 my $top = $opts->{doc} || do
2179 0 ▶ {
Condition0%0/3
$opts->{'doc'} || do { warn "No element object provided as a container.\n"; return $self->error('No element object provided as a container.') }
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{'doc'} || do { warn "No element object provided as a container.\n"; return $self->error('No element object provided as a container.') }
$opts->{'doc'} do { warn "No element object provided as a container.\n"; return $self->error('No element object provided as a container.') }
Truth table0%0/3
A || B
A= $opts->{'doc'}B= do { warn "No element object provided as a container.\n"; return $self->error('No element object provided as a container.') }
ABresult
1X1
011
000
2180 0 warn( "No element object provided as a container.\n" );
2181 0 return( $self->error( "No element object provided as a container." ) );
2182 };
2183 ## Leading space in length
2184 0 my $lead_space = int( $opts->{leading_space} );
2185 ## my $cols = [];
2186 0 my $body = [];
2187 0 my $rows = [];
2188 0 my $info =
2189 {
2190 cols => {},
2191 rows => {},
2192 };
2193 # A Module::Generic::Array object containing hash references with left and right keys
2194 0 my $al = $opts->{alignment};
2195 # Removing trailing new lines
2196 0 $str =~ s/\n+$//gs;
2197 0 my $row_n = 0;
2198 0 ▶ my $lines = ref( $str ) eq 'ARRAY' ? $str : [split( /\n/, $str )];
Branch: 1 branch
BranchTrueFalseTotal
ref $str eq 'ARRAY' ? : 0 0 0
2199 0 foreach my $l ( @$lines )
2200 {
2201 ## Get rid of leading (up to 3) and trailing spaces
2202 ## If there are remaining leading space to the pipe, we use it to determine this is an empty cell
2203 0 $l =~ s/^[[:blank:]\h]{$lead_space}|[[:blank:]\h]+$//gs;
2204 0 ▶ if( $l =~ /^[[:blank:]\h]*$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /^[[:blank:]\h]*$/) 0 0 0
2205 {
2206 0 push( @$body, $rows );
2207 0 $rows = [];
2208 0 next;
2209 }
2210
2211 0 my $row = $top->create_table_row;
2212 # Make sure there is a leading and trailing | to standardise our parsing
2213 0 ▶ substr( $l, 0, 0 ) = '|' if( $l !~ /^[\|\:]/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $l =~ /^[\|\:]/ 0 0 0
2214 0 ▶ $l .= '|' if( $l !~ /[\|\:]$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $l =~ /[\|\:]$/ 0 0 0
2215 0 ▶ my $is_prev_row = substr( $l, 0, 1 ) eq ':' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
substr($l, 0, 1) eq ':' ? : 0 0 0
2216 # Skip the leading pipe
2217 0 $l = substr( $l, 1 );
2218 0 my $col_n = 0;
2219 0 ▶ while( $l =~ s/^(?<col_content>[^\|\:]+)(?<sep>[\|\:]+)// )
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ s/^(?<col_content>[^\|\:]+)(?<sep>[\|\:]+)//) 0 0 0
2220 {
2221 0 my $re = { %+ };
2222 0 my $cell = $top->create_table_cell;
2223 # print( "Regexp: ", dump( $re ), "\n" );
2224 0 ▶ $is_prev_row = 1 if( substr( $re->{sep}, 0, 1 ) eq ':' );
Branch: 1 branch
BranchTrueFalseTotal
if substr($re->{"sep"}, 0, 1) eq ":" 0 0 0
2225 0 my $content = $re->{col_content};
2226 # If we do not have information about this column and this is not a colspan
2227 # then, store the column width
2228 0 ▶ if( !length( $info->{cols}->{ $col_n + 1 } ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (not length $info->{"cols"}{$col_n + 1} and length $re->{"sep"} == 1) 0 0 0
Condition0%0/3
not length $info->{"cols"}{$col_n + 1} and length $re->{"sep"} == 1
!ll&&!rl&&r
000
MC/DC0%0/2
not length $info->{"cols"}{$col_n + 1} and length $re->{"sep"} == 1
not length $info->{"cols"}{$col_n + 1} length $re->{"sep"} == 1
Truth table0%0/3
not(A) and B
A= not length $info->{"cols"}{$col_n + 1}B= length $re->{"sep"} == 1
ABresult
0X0
100
111
2229 length( $re->{sep} ) == 1 )
2230 {
2231 0 $info->{cols}->{ $col_n + 1 } = length( $content );
2232 }
2233 # In the cell width we include the additional pipes on the right, if any, that represent spawned columns
2234 0 ▶ $cell->width( length( $content ) + ( length( $re->{sep} ) > 1 ? ( length( $re->{sep} ) - 1 ) : 0 ) );
Branch: 1 branch
BranchTrueFalseTotal
length $re->{'sep'} > 1 ? : 0 0 0
2235 0 $cell->colspan( length( $re->{sep} ) );
2236 0 $content =~ s/^([[:blank:]\h]*)(.*?)([[:blank:]\h]*)$/$2/gs;
2237 0 my $left = $+[1];
2238 0 my $right = $+[3] - $-[3];
2239 ## $cell->add_element( $cell->create_text( $content ) );
2240 0 $self->parse( $content, { element => $cell });
2241 0 my $al_def = $al->[ $col_n ];
2242 ## Alignment was provided for this table using ":"
2243 0 ▶ if( $self->_is_hash( $al_def ) &&
Branch: 4 branches
BranchTrueFalseTotal
if ($self->_is_hash($al_def) and length $al_def->{'left'} || length $al_def->{'right'}) { } 0 0 0
elsif ($left <= 1) { } 0 0 0
elsif ($right <= 1) { } 0 0 0
elsif ($left == $right or $left and $right and int(($left + $right) / 2) == $left || int(($left + $right) / 2) == $right or $left >= 2 and $right >= 2) { } 0 0 0
Condition0%0/6
$self->_is_hash($al_def) and length $al_def->{"left"} || length $al_def->{"right"}
!ll&&!rl&&r
000
length $al_def->{"left"} or length $al_def->{"right"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->_is_hash($al_def) and length $al_def->{"left"} || length $al_def->{"right"}
$self->_is_hash($al_def) length $al_def->{"left"} length $al_def->{"right"}
Truth table0%0/4
A and B or C
A= $self->_is_hash($al_def)B= length $al_def->{"left"}C= length $al_def->{"right"}
ABCresult
0XX0
1000
11X1
1011
2244 ( length( $al_def->{left} ) || length( $al_def->{right} ) ) )
2245 {
2246 0 ▶ if( $al_def->{left} && $al_def->{right} )
Branch: 3 branches
BranchTrueFalseTotal
if ($al_def->{'left'} and $al_def->{'right'}) { } 0 0 0
elsif ($al_def->{'left'}) { } 0 0 0
elsif ($al_def->{'right'}) { } 0 0 0
Condition0%0/3
$al_def->{"left"} and $al_def->{"right"}
!ll&&!rl&&r
000
MC/DC0%0/2
$al_def->{"left"} and $al_def->{"right"}
$al_def->{"left"} $al_def->{"right"}
Truth table0%0/3
A and B
A= $al_def->{"left"}B= $al_def->{"right"}
ABresult
0X0
100
111
2247 {
2248 0 $cell->align( 'center' );
2249 }
2250 elsif( $al_def->{left} )
2251 {
2252 0 $cell->align( 'left' );
2253 }
2254 elsif( $al_def->{right} )
2255 {
2256 0 $cell->align( 'right' );
2257 }
2258 }
2259 elsif( $left <= 1 )
2260 {
2261 0 $cell->align( 'left' );
2262 }
2263 elsif( $right <= 1 )
2264 {
2265 0 $cell->align( 'right' );
2266 }
2267 ▶ elsif( $left == $right ||
Condition0%0/18
$left == $right or $left and $right and int(($left + $right) / 2) == $left || int(($left + $right) / 2) == $right or $left >= 2 and $right >= 2
l!l&&r!l&&!r
000
$left == $right or $left and $right and int(($left + $right) / 2) == $left || int(($left + $right) / 2) == $right
l!l&&r!l&&!r
000
$left and $right and int(($left + $right) / 2) == $left || int(($left + $right) / 2) == $right
!ll&&!rl&&r
000
$left and $right
!ll&&!rl&&r
000
int(($left + $right) / 2) == $left or int(($left + $right) / 2) == $right
l!l&&r!l&&!r
000
$left >= 2 and $right >= 2
!ll&&!rl&&r
000
MC/DC0%0/7
$left == $right or $left and $right and int(($left + $right) / 2) == $left || int(($left + $right) / 2) == $right or $left >= 2 and $right >= 2
$left == $right $left $right int(($left + $right) / 2) == $left int(($left + $right) / 2) == $right $left >= 2 $right >= 2
Truth table0%0/12
A or B and C and D or E or F and G
A= $left == $rightB= $leftC= $rightD= int(($left + $right) / 2) == $leftE= int(($left + $right) / 2) == $rightF= $left >= 2G= $right >= 2
ABCDEFGresult
1XXXXXX1
0111XXX1
01101XX1
00XXX111
010XX111
01100111
00XXX0X0
00XXX100
010XX0X0
010XX100
011000X0
01100100
2268 ( $left && $right &&
2269 ( int( ( $left + $right ) / 2 ) == $left || int( ( $left + $right ) / 2 ) == $right )
2270 ) ||
2271 ( $left >= 2 && $right >= 2 )
2272 )
2273 {
2274 0 $cell->align( 'center' );
2275 }
2276 0 ▶ if( $is_prev_row )
Branch: 1 branch
BranchTrueFalseTotal
if ($is_prev_row) { } 0 0 0
2277 {
2278 0 ▶ if( length( $content ) )
Branch: 1 branch
BranchTrueFalseTotal
if (length $content) { } 0 0 0
2279 {
2280 ## Check for the cell above
2281 0 my $prev_cell = $rows->[-1]->children->get( $col_n );
2282 0 ▶ if( $prev_cell )
Branch: 1 branch
BranchTrueFalseTotal
if ($prev_cell) { } 0 0 0
2283 {
2284 0 $prev_cell->add_element( $cell->create_text({ text => $content }) );
2285 # $prev_cell->children->push( $cell->create_text( $content ) );
2286 }
2287 else
2288 {
2289 0 warn( "This cell $col_n at row $row_n is marked as continuity, but there is no record of previous upper cell.\n" );
2290 }
2291 }
2292 ## Empty cell and this row is a continuity from the previous row, so we skip
2293 else
2294 {
2295 0 next;
2296 }
2297 }
2298 else
2299 {
2300 # push( @$cols, $cell );
2301 0 $row->add_element( $cell );
2302 }
2303 0 $col_n++;
2304 }
2305
2306 0 ▶ unless( $is_prev_row )
Branch: 1 branch
BranchTrueFalseTotal
unless ($is_prev_row) 0 0 0
2307 {
2308 0 $row_n++;
2309 0 push( @$rows, $row );
2310 }
2311 }
2312 0 ▶ push( @$body, $rows ) if( scalar( @$rows ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$rows 0 0 0
2313 ## Return body of rows set, which is an array of array reference containing row objects.
2314 0 return( $body );
2315 }
2316  
2317 0 ▶sub scope { return( shift->_set_get_object( 'scope', 'Markdown::Parser::Scope', @_ ) ); }
Subroutine scope: not called CC=1 SCAR=6.9
Pod documented
2318  
2319 sub scope_block
2320 {
2321 0 ▶ my $self = shift( @_ );
Subroutine scope_block: not called CC=6 SCAR=37.4
Pod documented
2322 0 my $opts = {};
2323 0 ▶ if( scalar( @_ ) && $self->_is_array( $_[0] ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ and $self->_is_array($_[0])) { } 0 0 0
Condition0%0/3
scalar @_ and $self->_is_array($_[0])
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ and $self->_is_array($_[0])
scalar @_ $self->_is_array($_[0])
Truth table0%0/3
A and B
A= scalar @_B= $self->_is_array($_[0])
ABresult
0X0
100
111
2324 {
2325 0 $opts = $self->new_array( shift( @_ ) )->as_hash({ start_from => 1 });
2326 }
2327 else
2328 {
2329 0 $opts = $self->new_hash;
2330 }
2331 0 my $res = $self->new_array( [qw( block )] );
2332 0 ▶ if( !$opts->exists( '-extended' ) && $self->scope->has( 'extended' ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not $opts->exists('-extended') and $self->scope->has('extended')) { } 0 0 0
elsif ($opts->exists('+extended')) { } 0 0 0
Condition0%0/3
not $opts->exists("-extended") and $self->scope->has("extended")
!ll&&!rl&&r
000
MC/DC0%0/2
not $opts->exists("-extended") and $self->scope->has("extended")
not $opts->exists("-extended") $self->scope->has("extended")
Truth table0%0/3
not(A) and B
A= not $opts->exists("-extended")B= $self->scope->has("extended")
ABresult
0X0
100
111
2333 {
2334 0 $res->push( 'extended' );
2335 }
2336 elsif( $opts->exists( '+extended' ) )
2337 {
2338 0 $res->push( 'extended' );
2339 }
2340 0 return( $res );
2341 }
2342  
2343 sub scope_inline
2344 {
2345 0 ▶ my $self = shift( @_ );
Subroutine scope_inline: not called CC=6 SCAR=37.4
Pod documented
2346 0 my $opts = {};
2347 0 ▶ if( scalar( @_ ) && $self->_is_array( $_[0] ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ and $self->_is_array($_[0])) { } 0 0 0
Condition0%0/3
scalar @_ and $self->_is_array($_[0])
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ and $self->_is_array($_[0])
scalar @_ $self->_is_array($_[0])
Truth table0%0/3
A and B
A= scalar @_B= $self->_is_array($_[0])
ABresult
0X0
100
111
2348 {
2349 0 $opts = $self->new_array( shift( @_ ) )->as_hash({ start_from => 1 });
2350 }
2351 else
2352 {
2353 0 $opts = $self->new_hash;
2354 }
2355 0 my $res = $self->new_array( [qw( inline )] );
2356 0 ▶ if( !$opts->exists( '-extended' ) && $self->scope->has( 'extended' ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not $opts->exists('-extended') and $self->scope->has('extended')) { } 0 0 0
elsif ($opts->exists('+extended')) { } 0 0 0
Condition0%0/3
not $opts->exists("-extended") and $self->scope->has("extended")
!ll&&!rl&&r
000
MC/DC0%0/2
not $opts->exists("-extended") and $self->scope->has("extended")
not $opts->exists("-extended") $self->scope->has("extended")
Truth table0%0/3
not(A) and B
A= not $opts->exists("-extended")B= $self->scope->has("extended")
ABresult
0X0
100
111
2357 {
2358 0 $res->push( 'extended' );
2359 }
2360 elsif( $opts->exists( '+extended' ) )
2361 {
2362 0 $res->push( 'extended' );
2363 }
2364 0 return( $res );
2365 }
2366  
2367 # Used for debugging
2368 sub whereami
2369 {
2370 0 ▶ my $self = shift( @_ );
Subroutine whereami: not called CC=5 SCAR=34.0
Pod documented
2371 0 my( $ref, $pos, $opts ) = @_;
2372 0 ▶ return if( $self->debug < 4 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug < 4 0 0 0
2373 0 ▶ my $text = $opts->{text} || "Cusrsor is now here at position '$pos':";
Condition0%0/2
$opts->{'text'} || "Cusrsor is now here at position '${pos}':"
l!l
00
MC/DC0%0/1
$opts->{'text'} || "Cusrsor is now here at position '${pos}':"
$opts->{'text'}
Truth table0%0/2
A
A= $opts->{'text'}
Aresult
11
00
2374 ## How far back should we look?
2375 0 my $lookback = 10;
2376 0 ▶ $lookback = $pos if( $pos < $lookback );
Branch: 1 branch
BranchTrueFalseTotal
if $pos < $lookback 0 0 0
2377 0 my $lookahed = 20;
2378 0 my $start = $pos - $lookback;
2379 0 my $first_line = substr( $$ref, $start, $lookback + $lookahed );
2380 0 $lookback += () = substr( $$ref, $start, $lookback ) =~ /\n/gs;
2381 0 $first_line =~ s/\n/\\n/gs;
2382 0 my $sec_line = ( '.' x $lookback ) . '^' . ( '.' x $lookahed );
2383 0 ▶ return( "$text\n$first_line\n$sec_line" ) if( $opts->{return} );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"return"} 0 0 0
2384 0 $self->message_colour( 3, "$text\n$first_line\n$sec_line" );
2385 }
2386  
2387 sub _total_trailing_new_lines
2388 {
2389 0 ▶ my $self = shift( @_ );
Subroutine _total_trailing_new_lines: not called CC=2 SCAR=17.9
2390 0 my $text = shift( @_ );
2391 0 my $trailing_nl = ( $text =~ /(\n+)$/ )[0];
2392 0 ▶ return( defined( $trailing_nl ) ? length( $trailing_nl ) : 0 );
Branch: 1 branch
BranchTrueFalseTotal
defined $trailing_nl ? : 0 0 0
2393 }
2394  
2395 # NOTE: Markdown::Parser::Scope package
2396 package Markdown::Parser::Scope;
2397 BEGIN
2398 {
2399 2 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2400 2 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
2401 2 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
2402 2 ▶ use vars qw( $ELEMENTS_DICTIONARY $ELEMENTS_DICTIONARY_EXTENDED $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
2403 2 ▶ use Devel::Confess;
Subroutine BEGIN: called CC=1 SCAR=0.0
2404 2 ▶ our $VERSION = 'v0.1.0';
Subroutine BEGIN: called CC=1 SCAR=0.0
2405 2 our $ELEMENTS_DICTIONARY = $Markdown::Parser::ELEMENTS_DICTIONARY;
2406 2 our $ELEMENTS_DICTIONARY_EXTENDED = $Markdown::Parser::ELEMENTS_DICTIONARY_EXTENDED;
2407 };
2408  
2409 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2410 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
2411  
2412 sub init
2413 {
2414 0 ▶ my $self = shift( @_ );
Subroutine init: not called CC=2 SCAR=17.9
2415 0 my $scope = shift( @_ );
2416 0 $self->{cache} = {};
2417 0 $self->{condition} = 'any';
2418 0 $self->{extended} = 0;
2419 0 $self->{scope} = {};
2420 0 $self->{_init_strict_use_sub} = 1;
2421 0 $self->SUPER::init( @_ );
2422 0 ▶ if( $self->_is_array( $scope ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_array($scope)) 0 0 0
2423 {
2424 0 $self->{scope} = $self->_to_array_object( $scope )->as_hash;
2425 }
2426 0 return( $self );
2427 }
2428  
2429 0 ▶sub all { return( shift->_set_get_prop( 'all', @_ ) ); }
Subroutine all: not called CC=1 SCAR=6.9
2430  
2431 0 ▶sub as_string { return( shift->scope->as_string ); }
Subroutine as_string: not called CC=1 SCAR=6.9
2432  
2433 0 ▶sub cache { return( shift->_set_get_hash_as_mix_object( 'cache', @_ ) ); }
Subroutine cache: not called CC=1 SCAR=6.9
2434  
2435 0 ▶sub condition { return( shift->_set_get_scalar_as_object( 'condition', @_ ) ); }
Subroutine condition: not called CC=1 SCAR=6.9
2436  
2437 0 ▶sub extended { return( shift->_set_get_prop( 'extended', @_ ) ); }
Subroutine extended: not called CC=1 SCAR=6.9
2438  
2439 0 ▶sub extended_only { return( shift->_set_get_prop( 'extended_only', @_ ) ); }
Subroutine extended_only: not called CC=1 SCAR=6.9
2440  
2441 sub has
2442 {
2443 0 ▶ my $self = shift( @_ );
Subroutine has: not called CC=15 SCAR=54.8
2444 0 ▶ my $check = shift( @_ ) || return;
Condition0%0/2
shift @_ || (return)
l!l
00
MC/DC0%0/1
shift @_ || (return)
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
2445 ## We clone the object, because we might modify it for the purpose of our checks
2446 0 my $scope = $self->scope->clone;
2447 0 ▶ my $what = $self->new_array( $self->_is_array( $check ) ? $check : [ $check ] );
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_array($check) ? : 0 0 0
2448 0 my $cache = $self->cache;
2449 0 ▶ my $scope_cond = $self->condition || 'any';
Condition0%0/2
$self->condition || 'any'
l!l
00
MC/DC0%0/1
$self->condition || 'any'
$self->condition
Truth table0%0/2
A
A= $self->condition
Aresult
11
00
2450 0 my $term_cond = 'all';
2451 0 my $new = $self->new_array;
2452 $what->foreach(sub
2453 {
2454 0 ▶ if( s/\|{1,2}/ /g )
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
if (s/\|{1,2}/ /g) 0 0 0
2455 {
2456 0 $new->push( split( /\s+/, $_ ) );
2457 0 $term_cond = 'any';
2458 }
2459 0 ▶ if( s/\+{1,2}/ /g )
Branch: 1 branch
BranchTrueFalseTotal
if (s/\+{1,2}/ /g) { } 0 0 0
2460 {
2461 0 $new->push( split( /\s+/, $_ ) );
2462 0 $term_cond = 'all';
2463 }
2464 else
2465 {
2466 0 $new->push( $_ );
2467 }
2468 0 });
2469 0 my $cache_key = join( ':', $scope_cond, $term_cond, $what->join( '|' )->scalar );
2470 0 ▶ return( $cache->{ $cache_key } ) if( exists( $cache->{ $cache_key } ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $cache->{$cache_key} 0 0 0
2471 $new->for(sub
2472 {
2473 0 ▶ my( $i, $val ) = @_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
2474 0 ▶ if( substr( $val, 0, 4 ) eq 'ext_' )
Branch: 1 branch
BranchTrueFalseTotal
if (substr($val, 0, 4) eq "ext_") 0 0 0
2475 {
2476 0 $new->splice( $i, 1, substr( $val, 4 ) );
2477 0 ▶ $new->push( 'extended' ) unless( $new->has( 'extended' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $new->has("extended") 0 0 0
2478 }
2479 0 });
2480 0 $what = $new;
2481 ## Expected positive hits should be equal to the number of array elements for the scope terms being checked
2482 ## Ex: [qw( header extended )] requires 2 hits, but
2483 ## [qw( header||extended )] requires just 1 hit
2484 0 my $expect = $what->length;
2485 0 my $hits = 0;
2486 0 my $is_ext = $what->has( 'extended' );
2487 0 ▶ if( $scope_cond eq 'all' )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope_cond eq 'all') { } 0 0 0
2488 {
2489 0 my $dict;
2490 0 my $is_ext = 0;
2491 0 ▶ if( $scope->has( 'extended' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has('extended')) { } 0 0 0
2492 {
2493 0 $dict = $ELEMENTS_DICTIONARY_EXTENDED;
2494 0 $scope->delete( 'extended' );
2495 0 $is_ext++;
2496 }
2497 else
2498 {
2499 0 $dict = $ELEMENTS_DICTIONARY;
2500 }
2501
2502 $scope->foreach(sub
2503 {
2504 0 ▶ my $scope_key = shift( @_ );
Subroutine __ANON__: not called CC=2 SCAR=17.9
2505 0 my $check_res = 0;
2506 $what->foreach(sub
2507 {
2508 0 ▶ my $scope_check = shift( @_ );
Subroutine __ANON__: not called CC=14 SCAR=53.5
2509 0 ▶ if( $scope_key eq $scope_check ||
Branch: 1 branch
BranchTrueFalseTotal
if ($scope_key eq $scope_check or $scope_key eq 'all' || $scope_key eq 'block' || $scope_key eq 'inline' and exists $dict->{$scope_key} and ref $dict->{$scope_key} eq 'ARRAY' and scalar grep(/^$scope_check$/i, @{$$dict{$scope_key};}) or $scope_key eq 'all' and $scope_check eq 'block' || $scope_check eq 'inline' and exists $dict->{$scope_check} or $is_ext and $scope_check eq 'extended') { } 0 0 0
Condition0%0/23
$scope_key eq $scope_check or $scope_key eq "all" || $scope_key eq "block" || $scope_key eq "inline" and exists $dict->{$scope_key} and ref $dict->{$scope_key} eq "ARRAY" and scalar grep(/^$scope_check$/i, @{$$dict{$scope_key};}) or $scope_key eq "all" and $scope_check eq "block" || $scope_check eq "inline" and exists $dict->{$scope_check} or $is_ext and $scope_check eq "extended"
l!l&&r!l&&!r
000
$scope_key eq $scope_check or $scope_key eq "all" || $scope_key eq "block" || $scope_key eq "inline" and exists $dict->{$scope_key} and ref $dict->{$scope_key} eq "ARRAY" and scalar grep(/^$scope_check$/i, @{$$dict{$scope_key};}) or $scope_key eq "all" and $scope_check eq "block" || $scope_check eq "inline" and exists $dict->{$scope_check}
l!l&&r!l&&!r
000
$scope_key eq $scope_check or $scope_key eq "all" || $scope_key eq "block" || $scope_key eq "inline" and exists $dict->{$scope_key} and ref $dict->{$scope_key} eq "ARRAY" and scalar grep(/^$scope_check$/i, @{$$dict{$scope_key};})
l!l&&r!l&&!r
000
$scope_key eq "all" || $scope_key eq "block" || $scope_key eq "inline" and exists $dict->{$scope_key} and ref $dict->{$scope_key} eq "ARRAY" and scalar grep(/^$scope_check$/i, @{$$dict{$scope_key};})
!ll
00
$scope_key eq "all" || $scope_key eq "block" || $scope_key eq "inline" and exists $dict->{$scope_key} and ref $dict->{$scope_key} eq "ARRAY"
!ll&&!rl&&r
000
$scope_key eq "all" || $scope_key eq "block" || $scope_key eq "inline" and exists $dict->{$scope_key}
!ll&&!rl&&r
000
$scope_key eq "all" or $scope_key eq "block" or $scope_key eq "inline"
l!l&&r!l&&!r
000
$scope_key eq "all" or $scope_key eq "block"
l!l&&r!l&&!r
000
MC/DC0%0/8
$scope_key eq $scope_check or $scope_key eq "all" || $scope_key eq "block" || $scope_key eq "inline" and exists $dict->{$scope_key} and ref $dict->{$scope_key} eq "ARRAY" and scalar grep(/^$scope_check$/i, @{$$dict{$scope_key};}) or $scope_key eq "all" and $scope_check eq "block" || $scope_check eq "inline" and exists $dict->{$scope_check} or $is_ext and $scope_check eq "extended"
$scope_key eq $scope_check $scope_key eq "all" $scope_key eq "block" $scope_key eq "inline" exists $dict->{$scope_key} ref $dict->{$scope_key} eq "ARRAY" $scope_key eq "all" and $scope_check eq "block" || $scope_check eq "inline" and exists $dict->{$scope_check} $is_ext and $scope_check eq "extended"
Truth table0%0/25
A or B or C or D and E and F or G or H
A= $scope_key eq $scope_checkB= $scope_key eq "all"C= $scope_key eq "block"D= $scope_key eq "inline"E= exists $dict->{$scope_key}F= ref $dict->{$scope_key} eq "ARRAY"G= $scope_key eq "all" and $scope_check eq "block" || $scope_check eq "inline" and exists $dict->{$scope_check}H= $is_ext and $scope_check eq "extended"
ABCDEFGHresult
1XXXXXXX1
01XX11XX1
001X11XX1
000111XX1
0000XX1X1
01XX0X1X1
001X0X1X1
00010X1X1
01XX101X1
001X101X1
0001101X1
0000XX011
01XX0X011
001X0X011
00010X011
01XX10011
001X10011
000110011
0000XX000
01XX0X000
001X0X000
00010X000
01XX10000
001X10000
000110000
2510 (
2511 ( $scope_key eq 'all' || $scope_key eq 'block' || $scope_key eq 'inline' ) &&
2512 exists( $dict->{ $scope_key } ) &&
2513 ref( $dict->{ $scope_key } ) eq 'ARRAY' &&
2514 0 ▶ scalar( grep( /^$scope_check$/i, @{$dict->{ $scope_key }} ) )
Condition0%0/12
$scope_key eq "all" and $scope_check eq "block" || $scope_check eq "inline" and exists $dict->{$scope_check}
!ll&&!rl&&r
000
$scope_key eq "all" and $scope_check eq "block" || $scope_check eq "inline"
!ll&&!rl&&r
000
$scope_check eq "block" or $scope_check eq "inline"
l!l&&r!l&&!r
000
$is_ext and $scope_check eq "extended"
!ll&&!rl&&r
000
MC/DC0%0/4
$scope_key eq "all" and $scope_check eq "block" || $scope_check eq "inline" and exists $dict->{$scope_check}
$scope_key eq "all" $scope_check eq "block" $scope_check eq "inline" exists $dict->{$scope_check}
MC/DC0%0/2
$is_ext and $scope_check eq "extended"
$is_ext $scope_check eq "extended"
Truth table0%0/6
A and B or C and D
A= $scope_key eq "all"B= $scope_check eq "block"C= $scope_check eq "inline"D= exists $dict->{$scope_check}
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
Truth table0%0/3
A and B
A= $is_extB= $scope_check eq "extended"
ABresult
0X0
100
111
2515 ) ||
2516 ( $scope_key eq 'all' && ( $scope_check eq 'block' || $scope_check eq 'inline' ) && exists( $dict->{ $scope_check } ) ) ||
2517 ( $is_ext && $scope_check eq 'extended' ) )
2518 {
2519 0 $check_res++;
2520 }
2521 else
2522 {
2523 }
2524 0 });
2525 0 ▶ $hits++ if( $check_res == $what->length );
Branch: 1 branch
BranchTrueFalseTotal
if $check_res == $what->length 0 0 0
2526 0 });
2527 0 ▶ $cache->{ $cache_key } = $hits > 0 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$hits > 0 ? : 0 0 0
2528 0 ▶ return( $hits > 0 ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$hits > 0 ? : 0 0 0
2529 }
2530 else
2531 {
2532 $what->foreach(sub
2533 {
2534 0 ▶ my $term = shift( @_ );
Subroutine __ANON__: not called CC=10 SCAR=47.0
2535 ## If the scope is explicitly included; or
2536 ## if the scope is all, but excluding extended features and the query item is not an extended feature; or
2537 ## if the scope is extended ONLY and the query item is an extended feature; or
2538 ## if the scope is extended and it does not matter what the query item is
2539 ## $hits++ if( $scope->has( $term ) || ( $term ne 'extended' && $scope->has( 'all' ) ) );
2540 0 ▶ if( $scope->has( $term ) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->has($term) or $scope->has("block") and scalar grep(/^$term$/i, @{$$Markdown::Parser::Scope::ELEMENTS_DICTIONARY{"block"};}) or $scope->has("inline") and scalar grep(/^$term$/i, @{$$Markdown::Parser::Scope::ELEMENTS_DICTIONARY{"inline"};}) or $scope->has("extended") and scalar grep(/^$term$/i, @{$$Markdown::Parser::Scope::ELEMENTS_DICTIONARY_EXTENDED{"all"};}) or $term ne "extended" and $scope->has("all")) 0 0 0
Condition0%0/14
$scope->has($term) or $scope->has("block") and scalar grep(/^$term$/i, @{$$Markdown::Parser::Scope::ELEMENTS_DICTIONARY{"block"};}) or $scope->has("inline") and scalar grep(/^$term$/i, @{$$Markdown::Parser::Scope::ELEMENTS_DICTIONARY{"inline"};}) or $scope->has("extended") and scalar grep(/^$term$/i, @{$$Markdown::Parser::Scope::ELEMENTS_DICTIONARY_EXTENDED{"all"};}) or $term ne "extended" and $scope->has("all")
l!l&&r!l&&!r
000
$scope->has($term) or $scope->has("block") and scalar grep(/^$term$/i, @{$$Markdown::Parser::Scope::ELEMENTS_DICTIONARY{"block"};}) or $scope->has("inline") and scalar grep(/^$term$/i, @{$$Markdown::Parser::Scope::ELEMENTS_DICTIONARY{"inline"};}) or $scope->has("extended") and scalar grep(/^$term$/i, @{$$Markdown::Parser::Scope::ELEMENTS_DICTIONARY_EXTENDED{"all"};})
l!l&&r!l&&!r
000
$scope->has($term) or $scope->has("block") and scalar grep(/^$term$/i, @{$$Markdown::Parser::Scope::ELEMENTS_DICTIONARY{"block"};}) or $scope->has("inline") and scalar grep(/^$term$/i, @{$$Markdown::Parser::Scope::ELEMENTS_DICTIONARY{"inline"};})
l!l&&r!l&&!r
000
$scope->has($term) or $scope->has("block") and scalar grep(/^$term$/i, @{$$Markdown::Parser::Scope::ELEMENTS_DICTIONARY{"block"};})
l!l&&r!l&&!r
000
$scope->has("block") and scalar grep(/^$term$/i, @{$$Markdown::Parser::Scope::ELEMENTS_DICTIONARY{"block"};})
!ll
00
MC/DC0%0/5
$scope->has($term) or $scope->has("block") and scalar grep(/^$term$/i, @{$$Markdown::Parser::Scope::ELEMENTS_DICTIONARY{"block"};}) or $scope->has("inline") and scalar grep(/^$term$/i, @{$$Markdown::Parser::Scope::ELEMENTS_DICTIONARY{"inline"};}) or $scope->has("extended") and scalar grep(/^$term$/i, @{$$Markdown::Parser::Scope::ELEMENTS_DICTIONARY_EXTENDED{"all"};}) or $term ne "extended" and $scope->has("all")
$scope->has($term) $scope->has("block") $scope->has("inline") and scalar grep(/^$term$/i, @{$$Markdown::Parser::Scope::ELEMENTS_DICTIONARY{"inline"};}) $scope->has("extended") and scalar grep(/^$term$/i, @{$$Markdown::Parser::Scope::ELEMENTS_DICTIONARY_EXTENDED{"all"};}) $term ne "extended" and $scope->has("all")
Truth table0%0/6
A or B or C or D or E
A= $scope->has($term)B= $scope->has("block")C= $scope->has("inline") and scalar grep(/^$term$/i, @{$$Markdown::Parser::Scope::ELEMENTS_DICTIONARY{"inline"};})D= $scope->has("extended") and scalar grep(/^$term$/i, @{$$Markdown::Parser::Scope::ELEMENTS_DICTIONARY_EXTENDED{"all"};})E= $term ne "extended" and $scope->has("all")
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
2541 0 ▶ ( $scope->has( 'block' ) && scalar( grep( /^$term$/i, @{$ELEMENTS_DICTIONARY->{block}} ) ) ) ||
Condition0%0/2
$scope->has("inline") and scalar grep(/^$term$/i, @{$$Markdown::Parser::Scope::ELEMENTS_DICTIONARY{"inline"};})
!ll
00
MC/DC0%0/1
$scope->has("inline") and scalar grep(/^$term$/i, @{$$Markdown::Parser::Scope::ELEMENTS_DICTIONARY{"inline"};})
$scope->has("inline")
Truth table0%0/2
A
A= $scope->has("inline")
Aresult
00
11
2542 0 ▶ ( $scope->has( 'inline' ) && scalar( grep( /^$term$/i, @{$ELEMENTS_DICTIONARY->{inline}} ) ) ) ||
Condition0%0/2
$scope->has("extended") and scalar grep(/^$term$/i, @{$$Markdown::Parser::Scope::ELEMENTS_DICTIONARY_EXTENDED{"all"};})
!ll
00
MC/DC0%0/1
$scope->has("extended") and scalar grep(/^$term$/i, @{$$Markdown::Parser::Scope::ELEMENTS_DICTIONARY_EXTENDED{"all"};})
$scope->has("extended")
Truth table0%0/2
A
A= $scope->has("extended")
Aresult
00
11
2543 0 ▶ ( $scope->has( 'extended' ) && scalar( grep( /^$term$/i, @{$ELEMENTS_DICTIONARY_EXTENDED->{all}} ) ) ) ||
Condition0%0/3
$term ne "extended" and $scope->has("all")
!ll&&!rl&&r
000
MC/DC0%0/2
$term ne "extended" and $scope->has("all")
$term ne "extended" $scope->has("all")
Truth table0%0/3
A and B
A= $term ne "extended"B= $scope->has("all")
ABresult
0X0
100
111
2544 ( $term ne 'extended' && $scope->has( 'all' ) ) )
2545 {
2546 0 $hits++;
2547 }
2548 0 });
2549 0 ▶ $cache->{ $cache_key } = ( $term_cond eq 'all' && $expect == $hits ) || ( $term_cond eq 'any' && $hits );
Condition0%0/9
$term_cond eq 'all' && $expect == $hits || $term_cond eq 'any' && $hits
l!l&&r!l&&!r
000
$term_cond eq "all" and $expect == $hits
!ll&&!rl&&r
000
$term_cond eq "any" and $hits
!ll&&!rl&&r
000
MC/DC0%0/4
$term_cond eq 'all' && $expect == $hits || $term_cond eq 'any' && $hits
$term_cond eq "all" $expect == $hits $term_cond eq "any" $hits
Truth table0%0/7
A and B || C and D
A= $term_cond eq "all"B= $expect == $hitsC= $term_cond eq "any"D= $hits
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
2550 0 ▶ return( ( $term_cond eq 'all' && $expect == $hits ) || ( $term_cond eq 'any' && $hits ) );
Condition0%0/9
$term_cond eq 'all' && $expect == $hits || $term_cond eq 'any' && $hits
l!l&&r!l&&!r
000
$term_cond eq "all" and $expect == $hits
!ll&&!rl&&r
000
$term_cond eq "any" and $hits
!ll&&!rl&&r
000
MC/DC0%0/4
$term_cond eq 'all' && $expect == $hits || $term_cond eq 'any' && $hits
$term_cond eq "all" $expect == $hits $term_cond eq "any" $hits
Truth table0%0/7
A and B || C and D
A= $term_cond eq "all"B= $expect == $hitsC= $term_cond eq "any"D= $hits
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
2551 }
2552 }
2553  
2554 0 ▶sub scope { return( shift->_set_get_hash_as_mix_object( 'scope', @_ ) ); }
Subroutine scope: not called CC=1 SCAR=6.9
2555  
2556 sub _set_get_prop
2557 {
2558 0 ▶ my $self = shift( @_ );
Subroutine _set_get_prop: not called CC=2 SCAR=17.9
2559 0 my $key = shift( @_ );
2560 0 my $scope = $self->scope;
2561 0 ▶ $scope->{ $key } = shift( @_ ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
2562 0 return( $scope->{ $key } );
2563 }
2564  
2565 2 1;
2566 # NOTE: POD
2567 __END__
↑ Summary lib/Markdown/Parser/Document.pm »