lib/Markdown/Parser.pm

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