Parser.pm

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