Markdown/Perl/BlockParser.pm

filter: Statementstmt 99.6% 514 / 516 Branchbran 92.6% 241 / 260 Conditioncond 89.3% 176 / 197 MC/DCmcdc 63.7% 65 / 102 Subroutinesub 100% 51 / 51 Podpod 0.0% 0 / 7 totaltotal 92.4% 1047 / 1133 CC 199 SCAR 27.6
CC
199
Cov
96%
_parse_table_structure
46.2
_parse_blocks
22.0
_do_list_item
20.0
CRAP 15.8
« Markdown/Perl.pm ↑ Summary Markdown/Perl/InlineTree.pm »
1 package Markdown::Perl::BlockParser;
2  
3 31 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 31 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 31 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 31 ▶use feature ':5.24';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 31 ▶use feature 'refaliasing';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 31 ▶no warnings 'experimental::refaliasing';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 31 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 31 ▶use English;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 31 ▶use Hash::Util 'lock_keys_plus';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 31 ▶use List::MoreUtils 'first_index';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 31 ▶use List::Util 'pairs', 'min';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 31 ▶use Markdown::Perl::HTML 'html_escape', 'decode_entities', 'remove_disallowed_tags';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 31 ▶use Markdown::Perl::Util ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
18 31 ▶use YAML::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 31 our $VERSION = '0.02';
21  
22 =pod
23  
24 =encoding utf8
25  
26 =cut
27  
28 41108 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
29 # $md must be a reference
30 41108 my ($class, $pmarkdown, $md) = @_;
31  
32 41108 my $this = bless {
33 pmarkdown => $pmarkdown,
34 blocks => [],
35 blocks_stack => [],
36 paragraph => [],
37 last_line_is_blank => 0,
38 last_line_was_blank => 0,
39 skip_next_block_matching => 0,
40 is_lazy_continuation => 0,
41 md => undef,
42 last_pos => 0,
43 line_ending => '',
44 continuation_re => qr//,
45 linkrefs => {},
46 matched_prefix_size => 0,
47 }, $class;
48 41108 lock_keys_plus(%{$this}, qw(forced_line));
49  
50 41108 \$this->{md} = $md; # aliasing to avoid copying the input, does this work? is it useful?
51  
52 41108 return $this;
53 }
54  
55 # This autoload method allows to call option accessors from the parent object
56 # transparently.
57 31 my $pkg = __PACKAGE__;
58  
59 688011 ▶sub AUTOLOAD { ## no critic (ProhibitAutoloading, RequireArgUnpacking)
Subroutine AUTOLOAD: called CC=3 SCAR=11.0
60 688011 our $AUTOLOAD; # Automatically populated when the method is called.
61 688011 $AUTOLOAD =~ s/${pkg}:://;
62 688011 ▶ return if $AUTOLOAD eq 'DESTROY';
Branch: 1 branch
BranchTrueFalseTotal
if $Markdown::Perl::BlockParser::AUTOLOAD eq "DESTROY" 37001 651010 688011
63 651010 ▶ confess "Undefined method ${AUTOLOAD}" unless $AUTOLOAD =~ m/^get_/;
Branch: 1 branch
BranchTrueFalseTotal
unless $Markdown::Perl::BlockParser::AUTOLOAD =~ /^get_/u 0 651010 651010
64 651010 my $this = shift @_;
65 651010 return $this->{pmarkdown}->$AUTOLOAD(@_);
66 }
67  
68 31 my $eol_re = qr/ \r\n | \n | \r /x;
69  
70 180341 ▶sub next_line {
Subroutine next_line: called CC=9 SCAR=22.0
Pod undocumented
71 180341 my ($this) = @_;
72 # When we are forcing a line, we don’t recompute the line_ending, but it
73 # should already be correct because the forced one is a substring of the last
74 # line.
75 180341 ▶ return delete $this->{forced_line} if exists $this->{forced_line};
Branch: 1 branch
BranchTrueFalseTotal
if exists $this->{"forced_line"} 23877 156464 180341
76 156464 ▶ return if pos($this->{md}) == length($this->{md});
Branch: 1 branch
BranchTrueFalseTotal
if pos $this->{"md"} == length $this->{"md"} 26773 129691 156464
77 129691 $this->{last_pos} = pos($this->{md});
78 129691 ▶ $this->{md} =~ m/\G([^\n\r]*)(${eol_re})?/g or confess 'Should not happen';
Branch: 1 branch
BranchTrueFalseTotal
$this->{"md"} =~ /\G([^\n\r]*)($eol_re)?/gu or confess("Should not happen") 129691 0 129691
79 129691 my ($t, $e) = ($1, $2);
80 129691 ▶ if ($1 =~ /^[ \t]+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 =~ /^[ \t]+$/u) { } 1529 128162 129691
81 1529 ▶ $this->{line_ending} = $t.($e // '') if $this->get_preserve_white_lines;
Branch: 1 branch
BranchTrueFalseTotal
if $this->get_preserve_white_lines 1174 355 1529
Condition100%2/2
$e // ""
l!l
110074
MC/DC100%1/1
$e // ""
$e
Truth table100%2/2
A
A= $e
Aresult
11
00
82 1529 return '';
83 } else {
84 128162 ▶ $this->{line_ending} = $e // ($this->get_force_final_new_line ? "\n" : '');
Branch: 1 branch
BranchTrueFalseTotal
$this->get_force_final_new_line ? : 3802 12960 16762
Condition100%2/2
$e // ($this->get_force_final_new_line ? "\n" : "")
l!l
11140016762
MC/DC100%1/1
$e // ($this->get_force_final_new_line ? "\n" : "")
$e
Truth table100%2/2
A
A= $e
Aresult
11
00
85 128162 return $t;
86 }
87 }
88  
89 30214 ▶sub line_ending {
Subroutine line_ending: called CC=1 SCAR=0.0
Pod undocumented
90 30214 my ($this) = @_;
91 30214 return $this->{line_ending};
92 }
93  
94 # last_pos should be passed whenever set_pos can be followed by a "return;" in
95 # one of the _do_..._block method (so, if the method fails), to reset the parser
96 # to its previous state, when the pos was manipulated.
97 # TODO: add a better abstraction to save and restore parser state.
98 21950 ▶sub set_pos {
Subroutine set_pos: called CC=2 SCAR=6.9
Pod undocumented
99 21950 my ($this, $pos, $last_pos) = @_;
100 21950 pos($this->{md}) = $pos;
101 21950 ▶ $this->{last_pos} = $last_pos if defined $last_pos;
Branch: 1 branch
BranchTrueFalseTotal
if defined $last_pos 7772 14178 21950
102 21950 return;
103 }
104  
105 20568 ▶sub get_pos {
Subroutine get_pos: called CC=1 SCAR=0.0
Pod undocumented
106 20568 my ($this) = @_;
107 20568 return pos($this->{md});
108 }
109  
110 9579 ▶sub redo_line {
Subroutine redo_line: called CC=2 SCAR=7.0
Pod undocumented
111 9579 my ($this) = @_;
112 9579 ▶ confess 'Cannot push back more than one line' unless exists $this->{last_pos};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $this->{"last_pos"} 0 9579 9579
113 9579 $this->set_pos(delete $this->{last_pos});
114 9579 return;
115 }
116  
117 # Takes a string and converts it to HTML. Can be called as a free function or as
118 # class method. In the latter case, provided options override those set in the
119 # class constructor.
120 # Both the input and output are unicode strings.
121 17572 ▶sub process {
Subroutine process: called CC=4 SCAR=13.9
Pod undocumented
122 17572 my ($this) = @_;
123 17572 pos($this->{md}) = 0;
124  
125 # https://spec.commonmark.org/0.30/#characters-and-lines
126 # TODO: The spec asks for this, however we can’t apply it, because md is a
127 # reference to the value passed by the user and we don’t want to modify it (it
128 # may even be a read-only value). I’m too lazy to find another place to
129 # implement this behavior.
130 # $this->{md} =~ s/\000/\xfffd/g;
131  
132 # https://spec.commonmark.org/0.30/#tabs
133 # TODO: nothing to do at this stage.
134  
135 # https://spec.commonmark.org/0.30/#backslash-escapes
136 # https://spec.commonmark.org/0.30/#entity-and-numeric-character-references
137 # Done at a later stage, as escaped characters don’t have their Markdown
138 # meaning, we need a way to represent that.
139  
140 17572 ▶ $this->_parse_yaml_metadata() if $this->get_parse_file_metadata eq 'yaml';
Branch: 1 branch
BranchTrueFalseTotal
if $this->get_parse_file_metadata eq "yaml" 4244 13328 17572
141  
142 17571 ▶ while (defined (my $l = $this->next_line())) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $l = $this->next_line)) 123933 17571 141504
143 # This field might be set to true at the beginning of the processing, while
144 # we’re looking at the conditions of the currently open containers.
145 123933 $this->{is_lazy_continuation} = 0;
146 123933 $this->_parse_blocks($l);
147 }
148 17571 $this->_finalize_paragraph();
149 17571 ▶ while (@{$this->{blocks_stack}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$this->{"blocks_stack"};}) 6961 17571 24532
150 6961 $this->_restore_parent_block();
151 }
152 17571 return delete $this->{linkrefs}, delete $this->{blocks};
153 }
154  
155 # The $force_loose_test parameter is used when we are actually starting a new
156 # block. In that case, or if we are actually after a paragraph, then we possibly
157 # convert the enclosing list to a loose list.
158 # TODO: the logic to decide if a list is loose is extremely complex and split in
159 # many different place. It would be great to rewrite it in a simpler way.
160 123883 ▶sub _finalize_paragraph {
Subroutine _finalize_paragraph: called CC=7 SCAR=19.5
161 123883 my ($this, $force_loose_test) = @_;
162 123883 ▶ if (@{$this->{paragraph}} || $force_loose_test) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$this->{"paragraph"};} or $force_loose_test) 86548 37335 123883
Condition100%3/3
@{$this->{"paragraph"};} or $force_loose_test
l!l&&r!l&&!r
538463270237335
MC/DC100%2/2
@{$this->{"paragraph"};} or $force_loose_test
@{$this->{"paragraph"};} $force_loose_test
Truth table100%3/3
A or B
A= @{$this->{"paragraph"};}B= $force_loose_test
ABresult
1X1
011
000
163 86548 ▶ if ($this->{last_line_was_blank}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"last_line_was_blank"}) 5807 80741 86548
164 5807 ▶ if (@{$this->{blocks_stack}}
Branch: 1 branch
BranchTrueFalseTotal
if (@{$this->{"blocks_stack"};} and $this->{"blocks_stack"}[-1]{"block"}{"type"} eq "list_item") 137 5670 5807
Condition100%3/3
@{$this->{"blocks_stack"};} and $this->{"blocks_stack"}[-1]{"block"}{"type"} eq "list_item"
!ll&&!rl&&r
565416137
MC/DC100%2/2
@{$this->{"blocks_stack"};} and $this->{"blocks_stack"}[-1]{"block"}{"type"} eq "list_item"
@{$this->{"blocks_stack"};} $this->{"blocks_stack"}[-1]{"block"}{"type"} eq "list_item"
Truth table100%3/3
A and B
A= @{$this->{"blocks_stack"};}B= $this->{"blocks_stack"}[-1]{"block"}{"type"} eq "list_item"
ABresult
0X0
100
111
165 && $this->{blocks_stack}[-1]{block}{type} eq 'list_item') {
166 137 $this->{blocks_stack}[-1]{block}{loose} = 1;
167 }
168 }
169 }
170 123883 ▶ return unless @{$this->{paragraph}};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$this->{"paragraph"};} 70037 53846 123883
171 53846 push @{$this->{blocks}}, {type => 'paragraph', content => $this->{paragraph}};
172 53846 $this->{paragraph} = [];
173 53846 return;
174 }
175  
176 # Whether the list_item match the most recent list (should we add to the same
177 # list or create a new one).
178 34731 ▶sub _list_match {
Subroutine _list_match: called CC=4 SCAR=13.9
179 34731 my ($this, $item) = @_;
180 34731 ▶ return 0 unless @{$this->{blocks}};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$this->{"blocks"};} 9748 24983 34731
181 24983 my $list = $this->{blocks}[-1];
182 return
183 $list->{type} eq 'list'
184 && $list->{style} eq $item->{style}
185 24983 ▶ && $list->{marker} eq $item->{marker};
Condition100%6/6
$list->{'type'} eq 'list' && $list->{'style'} eq $item->{'style'} && $list->{'marker'} eq $item->{'marker'}
!ll&&!rl&&r
195441145325
$list->{"type"} eq "list" and $list->{"style"} eq $item->{"style"}
!ll&&!rl&&r
1439851465439
MC/DC100%3/3
$list->{'type'} eq 'list' && $list->{'style'} eq $item->{'style'} && $list->{'marker'} eq $item->{'marker'}
$list->{"type"} eq "list" $list->{"style"} eq $item->{"style"} $list->{'marker'} eq $item->{'marker'}
Truth table100%4/4
A and B && C
A= $list->{"type"} eq "list"B= $list->{"style"} eq $item->{"style"}C= $list->{'marker'} eq $item->{'marker'}
ABCresult
0XX0
10X0
1100
1111
186 }
187  
188 36545 ▶sub _add_block {
Subroutine _add_block: called CC=4 SCAR=13.9
189 36545 my ($this, $block) = @_;
190 36545 ▶ if ($block->{type} eq 'list_item') {
Branch: 1 branch
BranchTrueFalseTotal
if ($block->{'type'} eq 'list_item') { } 16371 20174 36545
191 16371 $this->_finalize_paragraph(0);
192 # https://spec.commonmark.org/0.30/#lists
193 16371 ▶ if ($this->_list_match($block)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->_list_match($block)) { } 2471 13900 16371
194 2471 push @{$this->{blocks}[-1]{items}}, $block;
195 2471 ▶ $this->{blocks}[-1]{loose} ||= $block->{loose};
Condition100%3/3
$this->{"blocks"}[-1]{"loose"} ||= $block->{"loose"}
l!l&&r!l&&!r
441762251
MC/DC100%2/2
$this->{"blocks"}[-1]{"loose"} ||= $block->{"loose"}
$this->{"blocks"}[-1]{"loose"} $block->{"loose"}
Truth table100%3/3
A ||= B
A= $this->{"blocks"}[-1]{"loose"}B= $block->{"loose"}
ABresult
1X1
011
000
196 } else {
197 my $list = {
198 type => 'list',
199 style => $block->{style},
200 marker => $block->{marker},
201 start_num => $block->{num},
202 items => [$block],
203 loose => $block->{loose}
204 13900 };
205 13900 push @{$this->{blocks}}, $list;
206 }
207 } else {
208 20174 $this->_finalize_paragraph(1);
209 20174 push @{$this->{blocks}}, $block;
210 }
211 36545 return;
212 }
213  
214 # Anything passed to $prefix_re must necessary accept an empty string unless the
215 # block cannot accept lazy continuations. This is a best effort simulation of
216 # the block condition, to be used for some complex multi-line constructs that
217 # are parsed through a single regex.
218 30079 ▶sub _enter_child_block {
Subroutine _enter_child_block: called CC=2 SCAR=6.9
219 30079 my ($this, $new_block, $cond, $prefix_re, $forced_next_line) = @_;
220 30079 $this->_finalize_paragraph(1);
221 30079 ▶ if (defined $forced_next_line) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $forced_next_line) 27695 2384 30079
222 27695 $this->{forced_line} = $forced_next_line;
223 }
224 30079 push @{$this->{blocks_stack}}, {
225 cond => $cond,
226 block => $new_block,
227 parent_blocks => $this->{blocks},
228 continuation_re => $this->{continuation_re}
229 30079 };
230 30079 $this->{continuation_re} = qr/$this->{continuation_re} $prefix_re/x;
231 30079 $this->{blocks} = [];
232 30079 return;
233 }
234  
235 25951 ▶sub _restore_parent_block {
Subroutine _restore_parent_block: called CC=1 SCAR=0.0
236 25951 my ($this) = @_;
237 # TODO: rename the variables here with something better.
238 25951 my $last_block = pop @{$this->{blocks_stack}};
239 25951 my $block = delete $last_block->{block};
240 # TODO: maybe rename content to blocks here.
241 25951 $block->{content} = $this->{blocks};
242 25951 $this->{blocks} = delete $last_block->{parent_blocks};
243 25951 $this->{continuation_re} = delete $last_block->{continuation_re};
244 25951 $this->_add_block($block);
245 25951 return;
246 }
247  
248 # Returns true if $l would be parsed as the continuation of a paragraph in the
249 # context of $this (which is not modified).
250 29956 ▶sub _test_lazy_continuation {
Subroutine _test_lazy_continuation: called CC=4 SCAR=13.9
251 29956 my ($this, $l) = @_;
252 29956 ▶ return unless @{$this->{paragraph}};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$this->{"paragraph"};} 6420 23536 29956
253 23536 my $tester = new(ref($this), $this->{pmarkdown}, \'');
254 23536 pos($tester->{md}) = 0;
255 # What is a paragraph depends on whether we already have a paragraph or not.
256 23536 ▶ $tester->{paragraph} = [@{$this->{paragraph}} ? ('foo') : ()];
Branch: 1 branch
BranchTrueFalseTotal
@{$this->{'paragraph'};} ? : 23536 0 23536
257 # We use this field both in the tester and in the actual object when we
258 # matched a lazy continuation.
259 23536 $tester->{is_lazy_continuation} = 1;
260 # We’re ignoring the eol of the original line as it should not affect parsing.
261 23536 $tester->_parse_blocks($l);
262 # BUG: there is a bug here which is that a construct like a fenced code block
263 # or a link ref definition, whose validity depends on more than one line,
264 # might be misclassified. The probability of that is low.
265 23536 ▶ if (@{$tester->{paragraph}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$tester->{"paragraph"};}) 12684 10852 23536
266 12684 $this->{is_lazy_continuation} = 1;
267 12684 return 1;
268 }
269 10852 return 0;
270 }
271  
272 153227 ▶sub _count_matching_blocks {
Subroutine _count_matching_blocks: called CC=5 SCAR=16.1
273 153227 my ($this, $lr) = @_; # $lr is a scalar *reference* to the current line text.
274 153227 $this->{matched_prefix_size} = 0;
275 153227 for my $i (0 .. $#{$this->{blocks_stack}}) {
276 38461 local *::_ = $lr;
277 38461 my $r = $this->{blocks_stack}[$i]{cond}();
278 38461 ▶ $this->{matched_prefix_size} += $r if defined $r && $r > 0; # $r < 0 means match but no prefix.
Branch: 1 branch
BranchTrueFalseTotal
if defined $r and $r > 0 18811 19650 38461
Condition100%3/3
defined $r and $r > 0
!ll&&!rl&&r
18891776118811
MC/DC100%2/2
defined $r and $r > 0
defined $r $r > 0
Truth table100%3/3
A and B
A= defined $rB= $r > 0
ABresult
0X0
100
111
279 38461 ▶ return $i unless $r;
Branch: 1 branch
BranchTrueFalseTotal
unless $r 19443 19018 38461
280 }
281 133784 return @{$this->{blocks_stack}};
282 }
283  
284 29635 ▶sub _all_blocks_match {
Subroutine _all_blocks_match: called CC=1 SCAR=0.0
285 29635 my ($this, $lr) = @_;
286 29635 return @{$this->{blocks_stack}} == $this->_count_matching_blocks($lr);
287 }
288  
289 31 my $thematic_break_re = qr/^\ {0,3} (?: (?:-[ \t]*){3,} | (_[ \t]*){3,} | (\*[ \t]*){3,} ) $/x;
290 31 my $block_quotes_re = qr/^ {0,3}>/;
291 31 my $indented_code_re = qr/^(?: {0,3}\t| {4})/;
292 31 my $list_item_marker_re = qr/ [-+*] | (?<digits>\d{1,9}) (?<symbol>[.)])/x;
293 31 my $list_item_re =
294 qr/^ (?<indent>\ {0,3}) (?<marker>${list_item_marker_re}) (?<text>(?:[ \t].*)?) $/x;
295 31 my $supported_html_tags = join('|',
296 qw(address article aside base basefont blockquote body caption center col colgroup dd details dialog dir div dl dt fieldset figcaption figure footer form frame frameset h1 h2 h3 h4 h5 h6 head header hr html iframe legend li link main menu menuitem nav noframes ol optgroup option p param search section summary table tbody td tfoot th thead title tr track ul)
297 );
298  
299 31 my $directive_name_re = qr/(?<name> [-\w]+ )?/x;
300 31 my $directive_content_re = qr/(?: \s* \[ (?<content> [^\]]+ ) \] )?/x;
301 31 my $directive_attribute_re = qr/(?: \s* \{ (?<attributes> .* ) \} )?/x;
302 31 my $directive_data_re = qr/${directive_name_re} ${directive_content_re} ${directive_attribute_re}/x;
303 31 my $directive_block_re = qr/^\ {0,3} (?<marker> :{3,} ) \s* ${directive_data_re} \s* :* \s* $/x;
304  
305 # TODO: Share these regex with the Inlines.pm file that has a copy of them.
306 31 my $html_tag_name_re = qr/[a-zA-Z][-a-zA-Z0-9]*/;
307 31 my $html_attribute_name_re = qr/[a-zA-Z_:][-a-zA-Z0-9_.:]*/;
308 # We include new lines in these regex as the spec mentions them, but we can’t
309 # match them for now as the regex will see lines one at a time.
310 31 my $html_space_re = qr/\n[ \t]*|[ \t][ \t]*\n?[ \t]*/; # Spaces, tabs, and up to one line ending.
311 31 my $opt_html_space_re = qr/[ \t]*\n?[ \t]*/; # Optional spaces.
312 31 my $html_attribute_value_re = qr/ [^ \t\n"'=<>`]+ | '[^']*' | "[^"]*" /x;
313 31 my $html_attribute_re =
314 qr/ ${html_space_re} ${html_attribute_name_re} (?: ${opt_html_space_re} = ${opt_html_space_re} ${html_attribute_value_re} )? /x;
315 31 my $html_open_tag_re =
316 qr/ < ${html_tag_name_re} ${html_attribute_re}* ${opt_html_space_re} \/? > /x;
317 31 my $html_close_tag_re = qr/ <\/ ${html_tag_name_re} ${opt_html_space_re} > /x;
318  
319 # Parse at least one line of text to build a new block; and possibly several
320 # lines, depending on the block type.
321 # https://spec.commonmark.org/0.30/#blocks-and-inlines
322 31 our $l; # global variable, localized during the call to _parse_blocks.
323  
324 147469 ▶sub _parse_blocks { ## no critic (RequireArgUnpacking)
Subroutine _parse_blocks: called CC=22 SCAR=30.9
325 147469 my $this = shift @_;
326 # TODO do the localization in process to avoid the copy (but this will need
327 # change in the continuation tester).
328 147469 local $l = shift @_; ## no critic (ProhibitLocalVars)
329  
330 147469 ▶ if (!$this->{skip_next_block_matching}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $this->{'skip_next_block_matching'}) { } 123592 23877 147469
331 123592 my $matched_block = $this->_count_matching_blocks(\$l);
332 123592 ▶ if (@{$this->{blocks_stack}} > $matched_block) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$this->{"blocks_stack"};} > $matched_block) 17739 105853 123592
333 17739 $this->_finalize_paragraph();
334 17739 ▶ while (@{$this->{blocks_stack}} > $matched_block) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$this->{"blocks_stack"};} > $matched_block) 18990 17739 36729
335 18990 $this->_restore_parent_block();
336 }
337 }
338 } else {
339 23877 $this->{skip_next_block_matching} = 0;
340 }
341  
342 # There are two different cases. The first one, handled here, is when we have
343 # multiple blocks inside a list item separated by a blank line. The second
344 # case (when the list items themselves are separated by a blank line) is
345 # handled when parsing the list item itself (based on the last_line_was_blank
346 # setting).
347 147469 ▶ if ($this->{last_line_is_blank}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"last_line_is_blank"}) 15110 132359 147469
348 15110 ▶ if (@{$this->{blocks_stack}}
Branch: 1 branch
BranchTrueFalseTotal
if (@{$this->{"blocks_stack"};} and $this->{"blocks_stack"}[-1]{"block"}{"type"} eq "list_item") 604 14506 15110
Condition100%3/3
@{$this->{"blocks_stack"};} and $this->{"blocks_stack"}[-1]{"block"}{"type"} eq "list_item"
!ll&&!rl&&r
1448224604
MC/DC100%2/2
@{$this->{"blocks_stack"};} and $this->{"blocks_stack"}[-1]{"block"}{"type"} eq "list_item"
@{$this->{"blocks_stack"};} $this->{"blocks_stack"}[-1]{"block"}{"type"} eq "list_item"
Truth table100%3/3
A and B
A= @{$this->{"blocks_stack"};}B= $this->{"blocks_stack"}[-1]{"block"}{"type"} eq "list_item"
ABresult
0X0
100
111
349 && $this->{blocks_stack}[-1]{block}{type} eq 'list_item') {
350 # $this->{blocks_stack}[-1]{block}{loose} = 1;
351 }
352 }
353 147469 $this->{last_line_was_blank} = $this->{last_line_is_blank};
354 147469 $this->{last_line_is_blank} = 0;
355  
356 147469 ▶ _do_atx_heading($this)
Branch: 1 branch
BranchTrueFalseTotal
_do_atx_heading($this) or $this->get_use_setext_headings and _do_setext_heading($this) or _do_thematic_break($this) or _do_indented_code_block($this) or $this->get_use_fenced_code_blocks and _do_fenced_code_block($this) or _do_html_block($this) or _do_block_quotes($this) or _do_list_item($this) or _do_directive_block($this) or _do_link_reference_definition($this) or $this->get_use_table_blocks and _do_table_block($this) or _do_paragraph($this) or croak("Current line could not be parsed as anything: $Markdown::Perl::BlockParser::l") 147469 0 147469
Condition97%41/42
_do_atx_heading($this) or $this->get_use_setext_headings and _do_setext_heading($this) or _do_thematic_break($this) or _do_indented_code_block($this) or $this->get_use_fenced_code_blocks and _do_fenced_code_block($this) or _do_html_block($this) or _do_block_quotes($this) or _do_list_item($this) or _do_directive_block($this) or _do_link_reference_definition($this) or $this->get_use_table_blocks and _do_table_block($this) or _do_paragraph($this)
l!l&&r!l&&!r
408661066030
_do_atx_heading($this) or $this->get_use_setext_headings and _do_setext_heading($this) or _do_thematic_break($this) or _do_indented_code_block($this) or $this->get_use_fenced_code_blocks and _do_fenced_code_block($this) or _do_html_block($this) or _do_block_quotes($this) or _do_list_item($this) or _do_directive_block($this) or _do_link_reference_definition($this) or $this->get_use_table_blocks and _do_table_block($this)
l!l&&r!l&&!r
408597106603
_do_atx_heading($this) or $this->get_use_setext_headings and _do_setext_heading($this) or _do_thematic_break($this) or _do_indented_code_block($this) or $this->get_use_fenced_code_blocks and _do_fenced_code_block($this) or _do_html_block($this) or _do_block_quotes($this) or _do_list_item($this) or _do_directive_block($this) or _do_link_reference_definition($this)
l!l&&r!l&&!r
40667192106610
_do_atx_heading($this) or $this->get_use_setext_headings and _do_setext_heading($this) or _do_thematic_break($this) or _do_indented_code_block($this) or $this->get_use_fenced_code_blocks and _do_fenced_code_block($this) or _do_html_block($this) or _do_block_quotes($this) or _do_list_item($this) or _do_directive_block($this)
l!l&&r!l&&!r
4057394106802
_do_atx_heading($this) or $this->get_use_setext_headings and _do_setext_heading($this) or _do_thematic_break($this) or _do_indented_code_block($this) or $this->get_use_fenced_code_blocks and _do_fenced_code_block($this) or _do_html_block($this) or _do_block_quotes($this) or _do_list_item($this)
l!l&&r!l&&!r
2221318360106896
_do_atx_heading($this) or $this->get_use_setext_headings and _do_setext_heading($this) or _do_thematic_break($this) or _do_indented_code_block($this) or $this->get_use_fenced_code_blocks and _do_fenced_code_block($this) or _do_html_block($this) or _do_block_quotes($this)
l!l&&r!l&&!r
1058811625125256
_do_atx_heading($this) or $this->get_use_setext_headings and _do_setext_heading($this) or _do_thematic_break($this) or _do_indented_code_block($this) or $this->get_use_fenced_code_blocks and _do_fenced_code_block($this) or _do_html_block($this)
l!l&&r!l&&!r
75562994136919
_do_atx_heading($this) or $this->get_use_setext_headings and _do_setext_heading($this) or _do_thematic_break($this) or _do_indented_code_block($this) or $this->get_use_fenced_code_blocks and _do_fenced_code_block($this)
l!l&&r!l&&!r
24465088139935
_do_atx_heading($this) or $this->get_use_setext_headings and _do_setext_heading($this) or _do_thematic_break($this) or _do_indented_code_block($this)
l!l&&r!l&&!r
13861060145023
_do_atx_heading($this) or $this->get_use_setext_headings and _do_setext_heading($this) or _do_thematic_break($this)
l!l&&r!l&&!r
1086300146083
_do_atx_heading($this) or $this->get_use_setext_headings and _do_setext_heading($this)
l!l&&r!l&&!r
557529146383
$this->get_use_setext_headings and _do_setext_heading($this)
!ll&&!rl&&r
44539101844529
$this->get_use_fenced_code_blocks and _do_fenced_code_block($this)
!ll&&!rl&&r
364711034645088
$this->get_use_table_blocks and _do_table_block($this)
!ll&&!rl&&r
52830537737
MC/DC0%0/15
_do_atx_heading($this) or $this->get_use_setext_headings and _do_setext_heading($this) or _do_thematic_break($this) or _do_indented_code_block($this) or $this->get_use_fenced_code_blocks and _do_fenced_code_block($this) or _do_html_block($this) or _do_block_quotes($this) or _do_list_item($this) or _do_directive_block($this) or _do_link_reference_definition($this) or $this->get_use_table_blocks and _do_table_block($this) or _do_paragraph($this)
_do_atx_heading($this) $this->get_use_setext_headings _do_setext_heading($this) _do_thematic_break($this) _do_indented_code_block($this) $this->get_use_fenced_code_blocks _do_fenced_code_block($this) _do_html_block($this) _do_block_quotes($this) _do_list_item($this) _do_directive_block($this) _do_link_reference_definition($this) $this->get_use_table_blocks _do_table_block($this) _do_paragraph($this)
Truth table56%27/48
A or B and C or D or E or F and G or H or I or J or K or L or M and N or O
A= _do_atx_heading($this)B= $this->get_use_setext_headingsC= _do_setext_heading($this)D= _do_thematic_break($this)E= _do_indented_code_block($this)F= $this->get_use_fenced_code_blocksG= _do_fenced_code_block($this)H= _do_html_block($this)I= _do_block_quotes($this)J= _do_list_item($this)K= _do_directive_block($this)L= _do_link_reference_definition($this)M= $this->get_use_table_blocksN= _do_table_block($this)O= _do_paragraph($this)
ABCDEFGHIJKLMNOresult
1XXXXXXXXXXXXXX1
011XXXXXXXXXXXX1
00X1XXXXXXXXXXX1
0101XXXXXXXXXXX1
00X01XXXXXXXXXX1
01001XXXXXXXXXX1
00X0011XXXXXXXX1
0100011XXXXXXXX1
00X000X1XXXXXXX1
00X00101XXXXXXX1
010000X1XXXXXXX1
01000101XXXXXXX1
00X000X01XXXXXX1
00X001001XXXXXX1
010000X01XXXXXX1
010001001XXXXXX1
00X000X001XXXXX1
00X0010001XXXXX1
010000X001XXXXX1
0100010001XXXXX1
00X000X0001XXXX1
00X00100001XXXX1
010000X0001XXXX1
01000100001XXXX1
00X000X00001XXX1
00X001000001XXX1
010000X00001XXX1
010001000001XXX1
00X000X0000011X1
00X00100000011X1
010000X0000011X1
01000100000011X1
00X000X000000X11
00X000X000001011
00X0010000000X11
00X0010000001011
010000X000000X11
010000X000001011
0100010000000X11
0100010000001011
00X000X000000X00
00X000X000001000
00X0010000000X00
00X0010000001000
010000X000000X00
010000X000001000
0100010000000X00
0100010000001000
357 || ($this->get_use_setext_headings && _do_setext_heading($this))
358 # Thematic breaks are described first in the spec, but the setext headings has
359 # precedence in case of conflict, so we test for the break after the heading.
360 || _do_thematic_break($this)
361 || _do_indented_code_block($this)
362 || ($this->get_use_fenced_code_blocks && _do_fenced_code_block($this))
363 || _do_html_block($this)
364 || _do_block_quotes($this)
365 || _do_list_item($this)
366 || _do_directive_block($this)
367 || _do_link_reference_definition($this)
368 || ($this->get_use_table_blocks && _do_table_block($this))
369 || _do_paragraph($this)
370 || croak "Current line could not be parsed as anything: $l";
371 147469 return;
372 }
373  
374 1 ▶sub _load_yaml_module {
Subroutine _load_yaml_module: called CC=2 SCAR=7.6
375 1 my ($module_name) = @_;
376 1 ▶ if (!eval "require $module_name; 1") { ## no critic (BuiltinFunctions::ProhibitStringyEval)
Branch: 1 branch
BranchTrueFalseTotal
unless (eval "require $module_name; 1") 0 1 1
377 0 croak "Cannot load module $module_name: ${EVAL_ERROR}";
378 }
379 1 return;
380 }
381  
382 9 ▶sub _call_yaml_parser {
Subroutine _call_yaml_parser: called CC=4 SCAR=14.4
383 9 my ($this, $yaml) = @_;
384 9 my $parser = $this->get_yaml_parser;
385 9 my $metadata;
386 9 ▶ if ($parser eq 'YAML::Tiny') {
Branch: 2 branches
BranchTrueFalseTotal
if ($parser eq 'YAML::Tiny') { } 8 1 9
elsif ($parser eq 'YAML::PP' or $parser eq 'YAML::PP::LibYAML') { } 1 0 1
387 8 return eval { YAML::Tiny->read_string($yaml)->[0] };
388 ▶ } elsif ($parser eq 'YAML::PP' || $parser eq 'YAML::PP::LibYAML') {
Condition33%1/3
$parser eq "YAML::PP" or $parser eq "YAML::PP::LibYAML"
l!l&&r!l&&!r
100
MC/DC0%0/2
$parser eq "YAML::PP" or $parser eq "YAML::PP::LibYAML"
$parser eq "YAML::PP" $parser eq "YAML::PP::LibYAML"
Truth table33%1/3
A or B
A= $parser eq "YAML::PP"B= $parser eq "YAML::PP::LibYAML"
ABresult
1X1
011
000
389 1 _load_yaml_module($parser);
390 1 return eval { ($parser->new()->load_string($yaml))[0] };
391 }
392 0 croak "Unsupported YAML parser: $parser";
393 }
394  
395 4244 ▶sub _parse_yaml_metadata {
Subroutine _parse_yaml_metadata: called CC=6 SCAR=17.9
396 4244 my ($this) = @_;
397  
398 # At this point, pos(md) is guaranteed to be 0.
399 4244 ▶ my $line_re = $this->get_yaml_file_metadata_allows_empty_lines ? qr/.*\n/ : qr/.+\n/;
Branch: 1 branch
BranchTrueFalseTotal
$this->get_yaml_file_metadata_allows_empty_lines ? : 2 4242 4244
400 4244 ▶ if ($this->{md} =~ m/ ^ ---\n (?<YAML> (?: $line_re )+? ) (?: --- | \.\.\. ) \n /gxc) { ## no critic (ProhibitUnusedCapture)
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"md"} =~ / ^ ---\n (?<YAML> (?: $line_re )+? ) (?: --- | \.\.\. ) \n /cgux) 9 4235 4244
401 9 my $metadata = $this->_call_yaml_parser($+{YAML});
402 9 ▶ if ($EVAL_ERROR) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Markdown::Perl::BlockParser::EVAL_ERROR) 2 7 9
403 2 pos($this->{md}) = 0;
404 2 ▶ carp 'YAML Metadata (Markdown frontmatter) is invalid' if $this->get_warn_for_unused_input();
Branch: 1 branch
BranchTrueFalseTotal
if $this->get_warn_for_unused_input 2 0 2
405 2 return;
406 }
407 7 ▶ if (exists($this->{pmarkdown}{hooks}{yaml_metadata})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $this->{"pmarkdown"}{"hooks"}{"yaml_metadata"}) 5 2 7
408 5 $this->{pmarkdown}{hooks}{yaml_metadata}->($metadata);
409 }
410 }
411 4241 return;
412 }
413  
414 # https://spec.commonmark.org/0.30/#atx-headings
415 147469 ▶sub _do_atx_heading {
Subroutine _do_atx_heading: called CC=3 SCAR=11.0
416 147469 my ($this) = @_;
417 147469 ▶ if ($l =~ /^ \ {0,3} (\#{1,6}) (?:[ \t]+(.+?))?? (?:[ \t]+\#+)? [ \t]* $/x) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Markdown::Perl::BlockParser::l =~ /^ \ {0,3} (\#{1,6}) (?:[ \t]+(.+?))?? (?:[ \t]+\#+)? [ \t]* $/ux) 557 146912 147469
418 # Note: heading breaks can interrupt a paragraph or a list
419 # TODO: the content of the header needs to be interpreted for inline content.
420 557 ▶ $this->_add_block({
Condition100%2/2
$2 // ""
l!l
246311
MC/DC100%1/1
$2 // ""
$2
Truth table100%2/2
A
A= $2
Aresult
11
00
421 type => 'heading',
422 level => length($1),
423 content => $2 // '',
424 debug => 'atx'
425 });
426 557 return 1;
427 }
428 146912 return;
429 }
430  
431 # https://spec.commonmark.org/0.30/#setext-headings
432 102373 ▶sub _do_setext_heading {
Subroutine _do_setext_heading: called CC=11 SCAR=24.0
433 102373 my ($this) = @_;
434 102373 ▶ return unless $l =~ /^ {0,3}(-+|=+)[ \t]*$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $Markdown::Perl::BlockParser::l =~ /^ {0,3}(-+|=+)[ \t]*$/u 100738 1635 102373
435 1635 ▶ if ( !@{$this->{paragraph}}
Branch: 1 branch
BranchTrueFalseTotal
if (not @{$this->{"paragraph"};} or indent_size($this->{"paragraph"}[0]) >= 4 or $this->{"is_lazy_continuation"}) 1106 529 1635
Condition83%5/6
not @{$this->{"paragraph"};} or indent_size($this->{"paragraph"}[0]) >= 4 or $this->{"is_lazy_continuation"}
l!l&&r!l&&!r
757349529
not @{$this->{"paragraph"};} or indent_size($this->{"paragraph"}[0]) >= 4
l!l&&r!l&&!r
7570878
MC/DC66%2/3
not @{$this->{"paragraph"};} or indent_size($this->{"paragraph"}[0]) >= 4 or $this->{"is_lazy_continuation"}
not @{$this->{"paragraph"};} indent_size($this->{"paragraph"}[0]) >= 4 $this->{"is_lazy_continuation"}
Truth table75%3/4
not(A) or B or C
A= not @{$this->{"paragraph"};}B= indent_size($this->{"paragraph"}[0]) >= 4C= $this->{"is_lazy_continuation"}
ABCresult
1XX1
01X1
0011
0000
436 || indent_size($this->{paragraph}[0]) >= 4
437 || $this->{is_lazy_continuation}) {
438 1106 return;
439 }
440 # TODO: this should not interrupt a list if the heading is just one -
441 529 my $c = substr $1, 0, 1;
442 529 my $p = $this->{paragraph};
443 529 my $m = $this->get_multi_lines_setext_headings;
444 529 ▶ if ($m eq 'single_line' && @{$p} > 1) {
Branch: 3 branches
BranchTrueFalseTotal
if ($m eq 'single_line' and @{$p;} > 1) { } 1 528 529
elsif ($m eq 'break' and $Markdown::Perl::BlockParser::l =~ /$thematic_break_re/u) { } 1 527 528
elsif ($m eq 'ignore') { } 1 526 527
Condition66%2/3
$m eq "single_line" and @{$p;} > 1
!ll&&!rl&&r
52801
MC/DC50%1/2
$m eq "single_line" and @{$p;} > 1
$m eq "single_line" @{$p;} > 1
Truth table66%2/3
A and B
A= $m eq "single_line"B= @{$p;} > 1
ABresult
0X0
100
111
445 1 my $last_line = pop @{$p};
446 1 $this->_finalize_paragraph();
447 1 $p = [$last_line];
448 ▶ } elsif ($m eq 'break' && $l =~ m/${thematic_break_re}/) {
Condition66%2/3
$m eq "break" and $Markdown::Perl::BlockParser::l =~ /$thematic_break_re/u
!ll&&!rl&&r
52701
MC/DC50%1/2
$m eq "break" and $Markdown::Perl::BlockParser::l =~ /$thematic_break_re/u
$m eq "break" $Markdown::Perl::BlockParser::l =~ /$thematic_break_re/u
Truth table66%2/3
A and B
A= $m eq "break"B= $Markdown::Perl::BlockParser::l =~ /$thematic_break_re/u
ABresult
0X0
100
111
449 1 $this->_finalize_paragraph();
450 1 $this->_add_block({type => 'break', debug => 'setext_as_break'});
451 1 return 1;
452 } elsif ($m eq 'ignore') {
453 # TODO: maybe we should just do nothing and return 0 here.
454 1 push @{$this->{paragraph}}, $l;
455 1 return 1;
456 }
457 527 $this->{paragraph} = [];
458 527 ▶ $this->_add_block({
Branch: 1 branch
BranchTrueFalseTotal
$c eq '=' ? : 31 496 527
459 type => 'heading',
460 level => ($c eq '=' ? 1 : 2),
461 content => $p,
462 debug => 'setext'
463 });
464 527 return 1;
465 }
466  
467 # https://spec.commonmark.org/0.30/#thematic-breaks
468 146383 ▶sub _do_thematic_break {
Subroutine _do_thematic_break: called CC=2 SCAR=6.9
469 146383 my ($this) = @_;
470 146383 ▶ if ($l !~ /${thematic_break_re}/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Markdown::Perl::BlockParser::l =~ /$thematic_break_re/u) 146083 300 146383
471 146083 return;
472 }
473 300 $this->_add_block({type => 'break', debug => 'native_break'});
474 300 return 1;
475 }
476  
477 # https://spec.commonmark.org/0.30/#indented-code-blocks
478 146083 ▶sub _do_indented_code_block {
Subroutine _do_indented_code_block: called CC=9 SCAR=22.0
479 146083 my ($this) = @_;
480 # Indented code blocks cannot interrupt a paragraph.
481 146083 ▶ if (@{$this->{paragraph}} || $l !~ m/${indented_code_re}/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$this->{"paragraph"};} or not $Markdown::Perl::BlockParser::l =~ /$indented_code_re/u) 145023 1060 146083
Condition100%3/3
@{$this->{"paragraph"};} or not $Markdown::Perl::BlockParser::l =~ /$indented_code_re/u
l!l&&r!l&&!r
71896731271060
MC/DC100%2/2
@{$this->{"paragraph"};} or not $Markdown::Perl::BlockParser::l =~ /$indented_code_re/u
@{$this->{"paragraph"};} not $Markdown::Perl::BlockParser::l =~ /$indented_code_re/u
Truth table100%3/3
A or not(B)
A= @{$this->{"paragraph"};}B= not $Markdown::Perl::BlockParser::l =~ /$indented_code_re/u
ABresult
1X1
011
000
482 145023 return;
483 }
484 1060 my $convert_tabs = $this->get_code_blocks_convert_tabs_to_spaces;
485 1060 ▶ tabs_to_space($l, $this->{matched_prefix_size}) if $convert_tabs;
Branch: 1 branch
BranchTrueFalseTotal
if $convert_tabs 227 833 1060
486 1060 my @code_lines = scalar(remove_prefix_spaces(4, $l.$this->line_ending()));
487 1060 my $count = 1; # The number of lines we have read
488 1060 my $valid_count = 1; # The number of lines we know are in the code block.
489 1060 my $valid_pos = $this->get_pos();
490 1060 ▶ while (defined (my $nl = $this->next_line())) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $nl = $this->next_line)) 1047 263 1310
491 1047 ▶ if ($this->_all_blocks_match(\$nl)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->_all_blocks_match(\$nl)) { } 848 199 1047
492 848 $count++;
493 848 ▶ if ($nl =~ m/${indented_code_re}/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($nl =~ /$indented_code_re/u) { } 49 799 848
elsif ($nl eq '') { } 201 598 799
494 49 $valid_pos = $this->get_pos();
495 49 $valid_count = $count;
496 49 ▶ tabs_to_space($nl, $this->{matched_prefix_size}) if $convert_tabs;
Branch: 1 branch
BranchTrueFalseTotal
if $convert_tabs 1 48 49
497 49 push @code_lines, scalar(remove_prefix_spaces(4, $nl.$this->line_ending()));
498 } elsif ($nl eq '') {
499 201 push @code_lines, scalar(remove_prefix_spaces(4, $nl.$this->line_ending(), !$convert_tabs));
500 } else {
501 598 last;
502 }
503 } else {
504 199 last;
505 }
506 }
507 1060 splice @code_lines, $valid_count;
508 1060 $this->set_pos($valid_pos);
509 1060 my $code = join('', @code_lines);
510 1060 $this->_add_block({type => 'code', content => $code, debug => 'indented'});
511 1060 return 1;
512 }
513  
514 # https://spec.commonmark.org/0.30/#fenced-code-blocks
515 108552 ▶sub _do_fenced_code_block {
Subroutine _do_fenced_code_block: called CC=10 SCAR=23.0
516 108552 my ($this) = @_;
517 108552 ▶ return unless $l =~ /^ (?<indent>\ {0,3}) (?<fence>`{3,}|~{3,}) [ \t]* (?<info>.*?) [ \t]* $/x; ## no critic (ProhibitComplexRegexes)
Branch: 1 branch
BranchTrueFalseTotal
unless $Markdown::Perl::BlockParser::l =~ /^ (?<indent>\ {0,3}) (?<fence>`{3,}|~{3,}) [ \t]* (?<info>.*?) [ \t]* $/ux 98331 10221 108552
518 10221 my $f = substr $+{fence}, 0, 1;
519 10221 ▶ if ($f eq '`' && index($+{info}, '`') != -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f eq "`" and index($+{"info"}, "`") != -1) 1572 8649 10221
Condition100%3/3
$f eq "`" and index($+{"info"}, "`") != -1
!ll&&!rl&&r
1986301572
MC/DC100%2/2
$f eq "`" and index($+{"info"}, "`") != -1
$f eq "`" index($+{"info"}, "`") != -1
Truth table100%3/3
A and B
A= $f eq "`"B= index($+{"info"}, "`") != -1
ABresult
0X0
100
111
520 1572 return;
521 }
522 8649 my $fl = length($+{fence});
523 8649 my $info = $+{info};
524 8649 my $indent = length($+{indent});
525 # This is one of the few case where we need to process character escaping
526 # outside of the full inlines rendering process.
527 # TODO: Consider if it would be cleaner to do it inside the render_html method.
528 8649 $info =~ s/\\(\p{PosixPunct})/$1/g;
529 # The spec does not describe what we should do with fenced code blocks inside
530 # other containers if we don’t match them.
531 8649 my @code_lines; # The first line is not part of the block.
532 8649 my $end_fence_seen = 0;
533 8649 my $start_pos = $this->get_pos();
534 8649 ▶ while (defined (my $nl = $this->next_line())) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $nl = $this->next_line)) 22792 7384 30176
535 22792 ▶ if ($this->_all_blocks_match(\$nl)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->_all_blocks_match(\$nl)) { } 21910 882 22792
536 21910 ▶ if ($nl =~ m/^ {0,3}${f}{$fl,}[ \t]*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nl =~ /^ {0,3}${f}{$fl,}[ \t]*$/u) { } 383 21527 21910
537 383 $end_fence_seen = 1;
538 383 last;
539 } else {
540 # We’re adding one line to the fenced code block
541 21527 push @code_lines, scalar(remove_prefix_spaces($indent, $nl.$this->line_ending()));
542 }
543 } else {
544 # We’re out of our enclosing block and we haven’t seen the end of the
545 # fence. If we accept enclosed fence, then that last line must be tried
546 # again (and, otherwise, we will start again from start_pos).
547 882 ▶ $this->redo_line() if !$this->get_fenced_code_blocks_must_be_closed;
Branch: 1 branch
BranchTrueFalseTotal
unless $this->get_fenced_code_blocks_must_be_closed 157 725 882
548 882 last;
549 }
550 }
551  
552 8649 ▶ if (!$end_fence_seen && $this->get_fenced_code_blocks_must_be_closed) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $end_fence_seen and $this->get_fenced_code_blocks_must_be_closed) 3539 5110 8649
Condition100%3/3
not $end_fence_seen and $this->get_fenced_code_blocks_must_be_closed
!ll&&!rl&&r
38347273539
MC/DC100%2/2
not $end_fence_seen and $this->get_fenced_code_blocks_must_be_closed
not $end_fence_seen $this->get_fenced_code_blocks_must_be_closed
Truth table100%3/3
not(A) and B
A= not $end_fence_seenB= $this->get_fenced_code_blocks_must_be_closed
ABresult
0X0
100
111
553 3539 $this->set_pos($start_pos);
554 3539 return;
555 }
556 5110 my $code = join('', @code_lines);
557 5110 $this->_add_block({
558 type => 'code',
559 content => $code,
560 info => $info,
561 debug => 'fenced'
562 });
563 5110 return 1;
564 }
565  
566 # https://spec.commonmark.org/0.31.2/#html-blocks
567 139913 ▶sub _do_html_block {
Subroutine _do_html_block: called CC=15 SCAR=27.1
568 139913 my ($this) = @_;
569 # HTML blocks can interrupt a paragraph.
570 # TODO: add an option so that they don’t interrupt a paragraph (make it be
571 # the default?).
572 # TODO: PERF: test that $l =~ m/^ {0,3}</ to short circuit all these regex.
573 139913 my $html_end_condition;
574 139913 ▶ if ($l =~ m/ ^\ {0,3} < (?:pre|script|style|textarea) (?:\ |\t|>|$) /x) {
Branch: 7 branches
BranchTrueFalseTotal
if ($Markdown::Perl::BlockParser::l =~ / ^\ {0,3} < (?:pre|script|style|textarea) (?:\ |\t|>|$) /ux) { } 16 139897 139913
elsif ($Markdown::Perl::BlockParser::l =~ /^ {0,3}<!--/u) { } 10 139887 139897
elsif ($Markdown::Perl::BlockParser::l =~ /^ {0,3}<\?/u) { } 2 139885 139887
elsif ($Markdown::Perl::BlockParser::l =~ /^ {0,3}<![a-zA-Z]/u) { } 2 139883 139885
elsif ($Markdown::Perl::BlockParser::l =~ /^ {0,3}<!\[CDATA\[/u) { } 2 139881 139883
elsif ($Markdown::Perl::BlockParser::l =~ m[^\ {0,3} < /? (?:$supported_html_tags) (?:\ |\t|/?>|$) ]ux) { } 2977 136904 139881
elsif (not @{$this->{'paragraph'};} and $Markdown::Perl::BlockParser::l =~ /^\ {0,3} (?: $html_open_tag_re | $html_close_tag_re ) [ \t]* $ /ux) { } 23 205220 205243
575 16 $html_end_condition = qr/ <\/ (?:pre|script|style|textarea) > /x;
576 } elsif ($l =~ m/^ {0,3}<!--/) {
577 10 $html_end_condition = qr/-->/;
578 } elsif ($l =~ m/^ {0,3}<\?/) {
579 2 $html_end_condition = qr/\?>/;
580 } elsif ($l =~ m/^ {0,3}<![a-zA-Z]/) {
581 2 $html_end_condition = qr/=>/;
582 } elsif ($l =~ m/^ {0,3}<!\[CDATA\[/) {
583 2 $html_end_condition = qr/]]>/;
584 } elsif ($l =~ m/^\ {0,3} < \/? (?:${supported_html_tags}) (?:\ |\t|\/?>|$) /x) {
585 2977 $html_end_condition = qr/^$/; ## no critic (ProhibitFixedStringMatches)
586 136904 ▶ } elsif (!@{$this->{paragraph}}
Condition100%3/3
not @{$this->{"paragraph"};} and $Markdown::Perl::BlockParser::l =~ /^\ {0,3} (?: $html_open_tag_re | $html_close_tag_re ) [ \t]* $ /ux
!ll&&!rl&&r
683396854223
MC/DC100%2/2
not @{$this->{"paragraph"};} and $Markdown::Perl::BlockParser::l =~ /^\ {0,3} (?: $html_open_tag_re | $html_close_tag_re ) [ \t]* $ /ux
not @{$this->{"paragraph"};} $Markdown::Perl::BlockParser::l =~ /^\ {0,3} (?: $html_open_tag_re | $html_close_tag_re ) [ \t]* $ /ux
Truth table100%3/3
not(A) and B
A= not @{$this->{"paragraph"};}B= $Markdown::Perl::BlockParser::l =~ /^\ {0,3} (?: $html_open_tag_re | $html_close_tag_re ) [ \t]* $ /ux
ABresult
0X0
100
111
587 && $l =~ m/^\ {0,3} (?: ${html_open_tag_re} | ${html_close_tag_re} ) [ \t]* $ /x) {
588 # TODO: the spec seem to say that the tag can take more than one line, but
589 # this is not tested, so we don’t implement this for now.
590 23 $html_end_condition = qr/^$/; ## no critic (ProhibitFixedStringMatches)
591 }
592 # TODO: Implement rule 7 about any possible tag.
593 139913 ▶ if (!$html_end_condition) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($html_end_condition) 136881 3032 139913
594 136881 return;
595 }
596 # TODO: see if some code could be shared with the code blocks
597 3032 my @html_lines = $l.$this->line_ending();
598 # TODO: add an option to not parse a tag if it’s closing condition is never
599 # seen.
600 3032 ▶ if ($l !~ m/${html_end_condition}/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Markdown::Perl::BlockParser::l =~ /$html_end_condition/u) 3022 10 3032
601 # The end condition can occur on the opening line.
602 3022 ▶ while (defined (my $nl = $this->next_line())) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $nl = $this->next_line)) 5796 1555 7351
603 5796 ▶ if ($this->_all_blocks_match(\$nl)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->_all_blocks_match(\$nl)) { } 5173 623 5796
604 5173 ▶ if ($nl !~ m/${html_end_condition}/) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $nl =~ /$html_end_condition/u) { } 4329 844 5173
elsif ($nl eq '') { } 828 16 844
605 4329 push @html_lines, $nl.$this->line_ending();
606 } elsif ($nl eq '') {
607 # This can only happen for rules 6 and 7 where the end condition
608 # line is not part of the HTML block.
609 828 $this->redo_line();
610 828 last;
611 } else {
612 16 push @html_lines, $nl.$this->line_ending();
613 16 last;
614 }
615 } else {
616 623 $this->redo_line();
617 623 last;
618 }
619 }
620 }
621 3032 my $html = join('', @html_lines);
622 3032 remove_disallowed_tags($html, $this->get_disallowed_html_tags);
623 3032 $this->_add_block({type => 'html', content => $html});
624 3032 return 1;
625 }
626  
627 # https://spec.commonmark.org/0.30/#block-quotes
628 136881 ▶sub _do_block_quotes {
Subroutine _do_block_quotes: called CC=2 SCAR=6.9
629 136881 my ($this) = @_;
630 136881 ▶ return unless $l =~ /${block_quotes_re}/;
Branch: 1 branch
BranchTrueFalseTotal
unless $Markdown::Perl::BlockParser::l =~ /$block_quotes_re/u 125256 11625 136881
631 # TODO: handle laziness (block quotes where the > prefix is missing)
632 26583 ▶ my $cond = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
633 26583 ▶ if (s/(${block_quotes_re})/' ' x length($1)/e) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/($block_quotes_re)/" " x length($1);/eu) 13582 13001 26583
634 # We remove the '>' character that we replaced by a space, and the
635 # optional space after it. We’re using this approach to correctly handle
636 # the case of a line like '>\t\tfoo' where we need to retain the 6
637 # spaces of indentation, to produce a code block starting with two
638 # spaces.
639 13582 my $m;
640 13582 ($_, $m) = remove_prefix_spaces(length($1) + 1, $_);
641 # Returns the matched horizontal size.
642 13582 return $m;
643 }
644 13001 return $this->_test_lazy_continuation($_);
645 11625 };
646 {
647 11625 local *::_ = \$l;
648 11625 $this->{matched_prefix_size} += $cond->();
649 }
650 11625 $this->{skip_next_block_matching} = 1;
651 11625 $this->_enter_child_block({type => 'quotes'}, $cond, qr/ {0,3}(?:> ?)?/, $l);
652 11625 return 1;
653 }
654  
655 # https://spec.commonmark.org/0.30/#list-items
656 125256 ▶sub _do_list_item {
Subroutine _do_list_item: called CC=20 SCAR=30.0
657 125256 my ($this) = @_;
658 125256 ▶ return unless $l =~ m/${list_item_re}/;
Branch: 1 branch
BranchTrueFalseTotal
unless $Markdown::Perl::BlockParser::l =~ /$list_item_re/u 101433 23823 125256
659 # There is a note in the spec on thematic breaks that are not list items,
660 # it’s not exactly clear what is intended, and there are no examples.
661 23823 my ($indent_outside, $marker, $text, $digits, $symbol) = @+{qw(indent marker text digits symbol)};
662 23823 my $indent_marker = length($indent_outside) + length($marker);
663 23823 ▶ my $type = $marker =~ m/[-+*]/ ? 'ul' : 'ol';
Branch: 1 branch
BranchTrueFalseTotal
$marker =~ /[-+*]/u ? : 12322 11501 23823
664 # The $indent_marker is passed in case the text starts with tabs, to properly
665 # compute the tab stops. This is better than nothing but won’t work inside
666 # other container blocks. In all cases, using tabs instead of space should not
667 # be encouraged.
668 23823 my $text_indent = indent_size($text, $indent_marker + $this->{matched_prefix_size});
669 # When interrupting a paragraph, the rules are stricter.
670 23823 my $mode = $this->get_lists_can_interrupt_paragraph;
671 23823 ▶ if (@{$this->{paragraph}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$this->{"paragraph"};}) 12682 11141 23823
672 12682 ▶ return if $mode eq 'never';
Branch: 1 branch
BranchTrueFalseTotal
if $mode eq "never" 6 12676 12682
673 12676 ▶ if ($mode eq 'within_list'
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq "within_list" and not @{$this->{"blocks_stack"};} && $this->{"blocks_stack"}[-1]{"block"}{"type"} eq "list_item") 5377 7299 12676
Condition100%6/6
$mode eq "within_list" and not @{$this->{"blocks_stack"};} && $this->{"blocks_stack"}[-1]{"block"}{"type"} eq "list_item"
!ll&&!rl&&r
729635377
@{$this->{'blocks_stack'};} && $this->{'blocks_stack'}[-1]{'block'}{'type'} eq 'list_item'
!ll&&!rl&&r
419511823
MC/DC100%3/3
$mode eq "within_list" and not @{$this->{"blocks_stack"};} && $this->{"blocks_stack"}[-1]{"block"}{"type"} eq "list_item"
$mode eq "within_list" @{$this->{'blocks_stack'};} $this->{'blocks_stack'}[-1]{'block'}{'type'} eq 'list_item'
Truth table100%4/4
A and not(B && C)
A= $mode eq "within_list"B= @{$this->{'blocks_stack'};}C= $this->{'blocks_stack'}[-1]{'block'}{'type'} eq 'list_item'
ABCresult
0XX0
1110
10X1
1101
674 5380 && !(@{$this->{blocks_stack}} && $this->{blocks_stack}[-1]{block}{type} eq 'list_item')) {
675 5377 return;
676 }
677 7299 ▶ if ($mode eq 'strict' && ($text eq '' || ($type eq 'ol' && $digits != 1))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq "strict" and $text eq "" || $type eq "ol" && $digits != 1) 80 7219 7299
Condition100%9/9
$mode eq "strict" and $text eq "" || $type eq "ol" && $digits != 1
!ll&&!rl&&r
9721080
$text eq "" or $type eq "ol" and $digits != 1
l!l&&r!l&&!r
7647210
$type eq "ol" and $digits != 1
!ll&&!rl&&r
357836324
MC/DC100%4/4
$mode eq "strict" and $text eq "" || $type eq "ol" && $digits != 1
$mode eq "strict" $text eq "" $type eq "ol" $digits != 1
Truth table100%5/5
A and B or C and D
A= $mode eq "strict"B= $text eq ""C= $type eq "ol"D= $digits != 1
ABCDresult
0XXX0
100X0
10100
11XX1
10111
678 80 return;
679 }
680 }
681 18360 ▶ return if $text ne '' && $text_indent == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $text ne "" and $text_indent == 0 0 18360 18360
Condition66%2/3
$text ne "" and $text_indent == 0
!ll&&!rl&&r
287180730
MC/DC0%0/2
$text ne "" and $text_indent == 0
$text ne "" $text_indent == 0
Truth table66%2/3
A and B
A= $text ne ""B= $text_indent == 0
ABresult
0X0
100
111
682 # in the current implementation, $text_indent is enough to know if $text
683 # is matching $indented_code_re, but let’s not depend on that.
684 18360 my $first_line_blank = $text =~ m/^[ \t]*$/;
685 18360 ▶ my $discard_text_indent = $first_line_blank || indented(4 + 1, $text); # 4 + 1 is an indented code block, plus the required space after marker.
Condition100%3/3
$first_line_blank || indented(5, $text)
l!l&&r!l&&!r
229026015810
MC/DC100%2/2
$first_line_blank || indented(5, $text)
$first_line_blank indented(5, $text)
Truth table100%3/3
A || B
A= $first_line_blankB= indented(5, $text)
ABresult
1X1
011
000
686 18360 ▶ my $indent_inside = $discard_text_indent ? 1 : $text_indent;
Branch: 1 branch
BranchTrueFalseTotal
$discard_text_indent ? : 2550 15810 18360
687 18360 my $indent = $indent_inside + $indent_marker;
688 23284 ▶ my $cond = sub {
Subroutine __ANON__: called CC=6 SCAR=17.9
689 23284 ▶ if ($first_line_blank && m/^[ \t]*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first_line_blank and /^[ \t]*$/u) { } 311 22973 23284
Condition100%3/3
$first_line_blank and /^[ \t]*$/u
!ll&&!rl&&r
217931180311
MC/DC100%2/2
$first_line_blank and /^[ \t]*$/u
$first_line_blank /^[ \t]*$/u
Truth table100%3/3
A and B
A= $first_line_blankB= /^[ \t]*$/u
ABresult
0X0
100
111
690 # A list item can start with at most one blank line
691 311 return 0;
692 } else {
693 22973 $first_line_blank = 0;
694 }
695 22973 ▶ if (indent_size($_) >= $indent) {
Branch: 1 branch
BranchTrueFalseTotal
if (indent_size($_) >= $indent) 641 22332 22973
696 641 $_ = remove_prefix_spaces($indent, $_);
697 # Returns the matched horizontal size.
698 641 return $indent;
699 }
700 # TODO: we probably don’t need to test the list_item_re case here, just
701 # the lazy continuation and the emptiness is enough.
702 22332 ▶ return (!m/${list_item_re}/ && $this->_test_lazy_continuation($_))
Condition100%6/6
!/$list_item_re/u && $this->_test_lazy_continuation($_) || $_ eq ''
l!l&&r!l&&!r
6369352912434
not /$list_item_re/u and $this->_test_lazy_continuation($_)
!ll&&!rl&&r
5377105866369
MC/DC100%3/3
!/$list_item_re/u && $this->_test_lazy_continuation($_) || $_ eq ''
not /$list_item_re/u $this->_test_lazy_continuation($_) $_ eq ''
Truth table80%4/5
not(A) and B || C
A= not /$list_item_re/uB= $this->_test_lazy_continuation($_)C= $_ eq ''
ABCresult
11X1
0X11
1011
0X00
1000
703 || $_ eq '';
704 18360 };
705 18360 my $forced_next_line = undef;
706 18360 ▶ if (!$first_line_blank) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($first_line_blank) 16070 2290 18360
707 # We are doing a weird compensation for the fact that we are not
708 # processing the condition and to correctly handle the case where the
709 # list marker was followed by tabs.
710 16070 $forced_next_line = remove_prefix_spaces($indent, (' ' x $indent_marker).$text);
711 16070 $this->{matched_prefix_size} = $indent;
712 16070 $this->{skip_next_block_matching} = 1;
713 }
714 # Note that we are handling the creation of the lists themselves in the
715 # _add_block method. See https://spec.commonmark.org/0.30/#lists for
716 # reference.
717 # TODO: handle tight and loose lists.
718 18360 ▶ my $item = {
Condition80%4/5
$symbol // $marker
l!l&&r!l&&!r
878695740
$digits // 1
l!l
87869574
MC/DC0%0/2
$symbol // $marker
$symbol $marker
MC/DC100%1/1
$digits // 1
$digits
Truth table66%2/3
A // B
A= $symbolB= $marker
ABresult
1X1
011
000
Truth table100%2/2
A
A= $digits
Aresult
11
00
719 type => 'list_item',
720 style => $type,
721 marker => $symbol // $marker,
722 num => int($digits // 1),
723 };
724 $item->{loose} =
725 18360 ▶ $this->_list_match($item) && $this->{last_line_was_blank};
Condition100%3/3
$this->_list_match($item) && $this->{'last_line_was_blank'}
!ll&&!rl&&r
155062681173
MC/DC100%2/2
$this->_list_match($item) && $this->{'last_line_was_blank'}
$this->_list_match($item) $this->{'last_line_was_blank'}
Truth table100%3/3
A && B
A= $this->_list_match($item)B= $this->{'last_line_was_blank'}
ABresult
0X0
100
111
726 18360 $this->_enter_child_block($item, $cond, qr/ {0,${indent}}/, $forced_next_line);
727 18360 return 1;
728 }
729  
730 # https://talk.commonmark.org/t/generic-directives-plugins-syntax/444
731 # See also https://github.com/mkende/pmarkdown/issues/5
732 106896 ▶sub _do_directive_block {
Subroutine _do_directive_block: called CC=3 SCAR=11.0
733 106896 my ($this) = @_;
734 106896 ▶ return unless $this->get_use_directive_blocks();
Branch: 1 branch
BranchTrueFalseTotal
unless $this->get_use_directive_blocks 74419 32477 106896
735 # marker, name, content, attributes
736 32477 ▶ return unless $l =~ /${directive_block_re}/; # TODO: add an option to allow this block type.
Branch: 1 branch
BranchTrueFalseTotal
unless $Markdown::Perl::BlockParser::l =~ /$directive_block_re/u 32383 94 32477
737 94 my $lm = length($+{marker});
738 219 ▶ my $cond = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
739 219 ▶ if (m/^\ {0,3} :{$lm,} \s* $/x) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\ {0,3} :{$lm,} \s* $/ux) 12 207 219
740 12 $_ = '';
741 12 return 0;
742 }
743 207 return -1;
744 94 };
745 # At rendering time, a hook should be able to intercept the name and
746 # attributes of the directive to do fancy things with it.
747 $this->_enter_child_block({
748 type => 'directive',
749 name => $+{name},
750 inline => $+{content},
751 attributes => $+{attributes}
752 },
753 94 $cond,
754 qr/ {0,3}/); # Unclear if we need the continuation prefix here.
755 94 return 1;
756 }
757  
758 # https://spec.commonmark.org/0.31.2/#link-reference-definitions
759 106802 ▶sub _do_link_reference_definition {
Subroutine _do_link_reference_definition: called CC=10 SCAR=23.0
760 106802 my ($this) = @_;
761 # Link reference definitions cannot interrupt paragraphs
762 #
763 # This construct needs to be parsed across multiple lines, so we are directly
764 # using the {md} string rather than our parsed $l line
765 # TODO: another maybe much simpler approach would be to parse the block as a
766 # normal paragraph but immediately try to parse the content as a link
767 # reference definition (and otherwise to keep it as a normal paragraph).
768 # That would allow to use the higher lever InlineTree parsing constructs.
769 106802 ▶ return if @{$this->{paragraph}} || $l !~ m/^ {0,3}\[/;
Branch: 1 branch
BranchTrueFalseTotal
if @{$this->{"paragraph"};} or not $Markdown::Perl::BlockParser::l =~ /^ {0,3}\[/u 103963 2839 106802
Condition100%3/3
@{$this->{"paragraph"};} or not $Markdown::Perl::BlockParser::l =~ /^ {0,3}\[/u
l!l&&r!l&&!r
54395495682839
MC/DC100%2/2
@{$this->{"paragraph"};} or not $Markdown::Perl::BlockParser::l =~ /^ {0,3}\[/u
@{$this->{"paragraph"};} not $Markdown::Perl::BlockParser::l =~ /^ {0,3}\[/u
Truth table100%3/3
A or not(B)
A= @{$this->{"paragraph"};}B= not $Markdown::Perl::BlockParser::l =~ /^ {0,3}\[/u
ABresult
1X1
011
000
770 2839 my $last_pos = $this->{last_pos};
771 2839 my $init_pos = $this->get_pos();
772 2839 $this->redo_line();
773 2839 my $start_pos = $this->get_pos();
774  
775 # We consume the continuation prefix of enclosing blocks. Note that in the big
776 # regex we allow any number of space after the continuation because it’s what
777 # cmark does.
778 2839 my $cont = $this->{continuation_re};
779 2839 ▶ confess 'Unexpected regex match failure' unless $this->{md} =~ m/\G${cont}/g;
Branch: 1 branch
BranchTrueFalseTotal
unless $this->{"md"} =~ /\G$cont/gu 0 2839 2839
780  
781 # TODO:
782 # - Support for escaped or balanced parenthesis in naked destination
783 # - break this up in smaller pieces and test them independently.
784 # - The need to disable ProhibitUnusedCapture seems to be buggy...
785 # - most of the regex parses only \n and not other eol sequence. The regex
786 # should either be fixed or the entry be normalized.
787 ## no critic (ProhibitComplexRegexes, ProhibitUnusedCapture)
788 2839 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"md"} =~ /\G \ {0,3} \[ (?>(?<LABEL> # The link label (in square brackets), matched as an atomic group (?: [^\\\[\]]{0,100} (?:(?:\\\\)* \\ .)? # The label cannot contain unescaped ] # With 5.38 this could be (?(*{ ...}) (*FAIL)) which will be more efficient. (*COMMIT) (?(?{ pos $_ > $start_pos + 1004; }) (*FAIL) ) # As our block can be repeated, we prune the search when we are far enough. )+ )) \]: [ \t]* (?:\n $cont)? [ \t]* # optional spaces and tabs with up to one line ending (?>(?<TARGET> # the destination can be either: < (?: [^\n>]* (?<! \\) (?:\\\\)* )+ > # - enclosed in <> and containing no unescaped > | [^< [:cntrl:]] [^ [:cntrl:]]* # - not enclosed but cannot contains spaces, new lines, etc. and only balanced or escaped parenthesis )) (?: # Note that this is an atomic pattern so that we don\342\200\231t backtrack in it # (so the pattern must not erroneously accept one of its branch). (?> [ \t]* (?:\n $cont) [ \t]* | [ \t]+ ) # The spec says that spaces must be present here, but it seems that a new line is fine too. (?<TITLE> # The title can be between ", ' or (). The matching characters can\342\200\231t appear unescaped in the title " (:?[^\n"]* (?: (?<! \n) \n (?! \n) | (?<! \\) (?:\\\\)* \\ " )? )* " | ' (:?[^\n']* (?: (?<! \n) \n (?! \n) | (?<! \\) (?:\\\\)* \\ ' )? )* ' | \( (:?[^\n"()]* (?: (?<! \n) \n (?! \n) | (?<! \\) (?:\\\\)* \\ [()] )? )* \) ) )? [ \t]*(:?\r\n|\n|\r|$) # The spec says that no characters can occur after the title, but it seems that whitespace is tolerated. /gux) 210 2629 2839
789 $this->{md} =~ m/\G
790 \ {0,3} \[
791 (?>(?<LABEL> # The link label (in square brackets), matched as an atomic group
792 (?:
793 [^\\\[\]]{0,100} (?:(?:\\\\)* \\ .)? # The label cannot contain unescaped ]
794 # With 5.38 this could be (?(*{ ...}) (*FAIL)) which will be more efficient.
795 1826 (*COMMIT) (?(?{ pos() > $start_pos + 1004 }) (*FAIL) ) # As our block can be repeated, we prune the search when we are far enough.
796 )+
797 )) \]:
798 [ \t]* (?:\n ${cont})? [ \t]* # optional spaces and tabs with up to one line ending
799 (?>(?<TARGET> # the destination can be either:
800 < (?: [^\n>]* (?<! \\) (?:\\\\)* )+ > # - enclosed in <> and containing no unescaped >
801 | [^< [:cntrl:]] [^ [:cntrl:]]* # - not enclosed but cannot contains spaces, new lines, etc. and only balanced or escaped parenthesis
802 ))
803 (?:
804 # Note that this is an atomic pattern so that we don’t backtrack in it
805 # (so the pattern must not erroneously accept one of its branch).
806 (?> [ \t]* (?:\n ${cont}) [ \t]* | [ \t]+ ) # The spec says that spaces must be present here, but it seems that a new line is fine too.
807 (?<TITLE> # The title can be between ", ' or (). The matching characters can’t appear unescaped in the title
808 " (:?[^\n"]* (?: (?<! \n) \n (?! \n) | (?<! \\) (?:\\\\)* \\ " )? )* "
809 | ' (:?[^\n']* (?: (?<! \n) \n (?! \n) | (?<! \\) (?:\\\\)* \\ ' )? )* '
810 | \( (:?[^\n"()]* (?: (?<! \n) \n (?! \n) | (?<! \\) (?:\\\\)* \\ [()] )? )* \)
811 )
812 )?
813 [ \t]*(:?\r\n|\n|\r|$) # The spec says that no characters can occur after the title, but it seems that whitespace is tolerated.
814 /gx
815 ## use critic
816 ) {
817 210 my ($ref, $target, $title) = @LAST_PAREN_MATCH{qw(LABEL TARGET TITLE)};
818 210 $ref = normalize_label($ref);
819 210 ▶ if ($ref ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref ne "") 192 18 210
820 192 $this->_finalize_paragraph(1);
821 # TODO: option to keep the last appearance instead of the first one.
822 192 ▶ if (exists $this->{linkrefs}{$ref}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $this->{"linkrefs"}{$ref}) 4 188 192
823 # We keep the first appearance of a label.
824 # TODO: mention the link label.
825 4 ▶ carp 'Only the first appearance of a link reference definition is kept'
Branch: 1 branch
BranchTrueFalseTotal
if $this->get_warn_for_unused_input 0 4 4
826 if $this->get_warn_for_unused_input();
827 4 return 1;
828 }
829 188 ▶ if (defined $title) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $title) 71 117 188
830 71 $title =~ s/^.(.*).$/$1/s;
831 71 _unescape_char($title);
832 }
833 188 $target =~ s/^<(.*)>$/$1/;
834 188 _unescape_char($target);
835 188 ▶ $this->{linkrefs}{$ref} = {
Branch: 1 branch
BranchTrueFalseTotal
defined $title ? : 71 117 188
836 target => $target,
837 (defined $title ? ('title' => $title) : ())
838 };
839 188 return 1;
840 }
841 #pass-through intended;
842 }
843 2647 $this->set_pos($init_pos, $last_pos);
844 2647 return;
845 }
846  
847 # https://github.github.com/gfm/#tables-extension-
848 53780 ▶sub _do_table_block {
Subroutine _do_table_block: called CC=9 SCAR=22.0
849 53780 my ($this) = @_;
850  
851 # TODO: add an option to prevent interrupting a paragraph with a table (and
852 # make it be true for pmarkdown, but not for github where tables can interrupt
853 # a paragraph).
854 # TODO: github supports omitting the first | even on the first line when we
855 # are not interrupting a paragraph and when subsequent the delimiter line has
856 # more than one dash per cell.
857 53780 my $i = !!@{$this->{paragraph}};
858 53780 ▶ return if $i && !$this->get_table_blocks_can_interrupt_paragraph;
Branch: 1 branch
BranchTrueFalseTotal
if $i and not $this->get_table_blocks_can_interrupt_paragraph 16771 37009 53780
Condition100%3/3
$i and not $this->get_table_blocks_can_interrupt_paragraph
!ll&&!rl&&r
28066894316771
MC/DC100%2/2
$i and not $this->get_table_blocks_can_interrupt_paragraph
$i not $this->get_table_blocks_can_interrupt_paragraph
Truth table100%3/3
A and not(B)
A= $iB= not $this->get_table_blocks_can_interrupt_paragraph
ABresult
0X0
100
111
859 37009 my $m = $this->get_table_blocks_pipes_requirements;
860 # The tests here are quite lenient and there are many ways in which parsing
861 # the table can fail even if these tests pass.
862 37009 ▶ if ($m eq 'strict' || ($m eq 'loose' && $i)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m eq 'strict' or $m eq 'loose' and $i) { } 24542 12467 37009
Condition83%5/6
$m eq "strict" or $m eq "loose" and $i
l!l&&r!l&&!r
15599894312467
$m eq "loose" and $i
!ll&&!rl&&r
0124678943
MC/DC66%2/3
$m eq "strict" or $m eq "loose" and $i
$m eq "strict" $m eq "loose" $i
Truth table75%3/4
A or B and C
A= $m eq "strict"B= $m eq "loose"C= $i
ABCresult
1XX1
0111
00X0
0100
863 24542 ▶ return unless $l =~ m/^ {0,3}\|/;
Branch: 1 branch
BranchTrueFalseTotal
unless $Markdown::Perl::BlockParser::l =~ /^ {0,3}\|/u 23503 1039 24542
864 } else {
865 12467 ▶ return unless $l =~ m/ (?<! \\) (?:\\\\)* \| /x;
Branch: 1 branch
BranchTrueFalseTotal
unless $Markdown::Perl::BlockParser::l =~ / (?<! \\) (?:\\\\)* \| /ux 8374 4093 12467
866 }
867 5132 my $last_pos = $this->{last_pos};
868 5132 my $init_pos = $this->get_pos();
869 5132 $this->redo_line();
870 5132 my $table = $this->_parse_table_structure();
871 5132 ▶ if (!$table) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($table) 5125 7 5132
872 5125 $this->set_pos($init_pos, $last_pos);
873 5125 return;
874 }
875  
876 7 $this->_add_block({type => 'table', content => $table});
877  
878 7 return 1;
879 }
880  
881 5132 ▶sub _parse_table_structure { ## no critic (ProhibitExcessComplexity)
Subroutine _parse_table_structure: called CC=42 SCAR=38.3
882 5132 my ($this) = @_;
883  
884 5132 my $m = $this->get_table_blocks_pipes_requirements;
885 5132 my $i = !!@{$this->{paragraph}};
886  
887 # A regexp that matches no back-slashes or an even number of them, so that the
888 # next character cannot be escaped.
889 5132 my $e = qr/(?<! \\) (?:\\\\)*/x;
890  
891 # We consume the continuation prefix of enclosing blocks. Note that,
892 # as opposed to what happens for links, subsequent lines can have at most
893 # 3 more spaces than the initial one with the GitHub implementation (but not
894 # some other GFM implementations).
895 5132 my $cont = $this->{continuation_re};
896 5132 ▶ confess 'Unexpected regex match failure' unless $this->{md} =~ m/\G${cont}/g;
Branch: 1 branch
BranchTrueFalseTotal
unless $this->{"md"} =~ /\G$cont/gu 0 5132 5132
897 # We want to allow successive 0 length matches. For more details on this
898 # behavior, see:
899 # https://perldoc.perl.org/perlre#Repeated-Patterns-Matching-a-Zero-length-Substring
900 5132 pos($this->{md}) = pos($this->{md});
901  
902 # Now we consume the initial | marking the beginning of the table that we know
903 # is here because of the initial match against $l in _do_table_block.
904 5132 ▶ confess 'Unexpected missing table markers' unless $this->{md} =~ m/\G (\ {0,3}) (\|)?/gcx;
Branch: 1 branch
BranchTrueFalseTotal
unless $this->{"md"} =~ /\G (\ {0,3}) (\|)?/cgux 0 5132 5132
905  
906 5132 my $n = length($1) + 3; # Maximum amount of space allowed on subsequent line
907 5132 my $has_pipe = defined $2;
908  
909 # We parse the header row
910 5132 my @headers = $this->{md} =~ m/\G [ \t]* (.*? [ \t]* $e) \| /gcx;
911 5132 ▶ return unless @headers;
Branch: 1 branch
BranchTrueFalseTotal
unless @headers 758 4374 5132
912 # We parse the last header if it is not followed by a pipe, and the newline.
913 # The only failure case here is if we have reached the end of the file.
914 4374 ▶ return unless $this->{md} =~ m/\G [ \t]* (.+)? [ \t]* ${eol_re} /gcx;
Branch: 1 branch
BranchTrueFalseTotal
unless $this->{"md"} =~ /\G [ \t]* (.+)? [ \t]* $eol_re /cgux 591 3783 4374
915 3783 ▶ if (defined $1) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $1) 3350 433 3783
916 3350 push @headers, $1;
917 3350 $has_pipe = 0;
918 }
919  
920 3783 ▶ return if ($m eq 'strict' || ($m eq 'loose' && $i) || @headers == 1) && !$has_pipe;
Branch: 1 branch
BranchTrueFalseTotal
if $m eq "strict" || $m eq "loose" && $i || @headers == 1 and not $has_pipe 642 3141 3783
Condition91%11/12
$m eq "strict" || $m eq "loose" && $i || @headers == 1 and not $has_pipe
!ll&&!rl&&r
310536642
$m eq "strict" or $m eq "loose" and $i or @headers == 1
l!l&&r!l&&!r
4382403105
$m eq "strict" or $m eq "loose" and $i
l!l&&r!l&&!r
380583345
$m eq "loose" and $i
!ll&&!rl&&r
0334558
MC/DC80%4/5
$m eq "strict" || $m eq "loose" && $i || @headers == 1 and not $has_pipe
$m eq "strict" $m eq "loose" $i @headers == 1 not $has_pipe
Truth table70%7/10
A or B and C or D and not(E)
A= $m eq "strict"B= $m eq "loose"C= $iD= @headers == 1E= not $has_pipe
ABCDEresult
00X0X0
0100X0
1XXX00
011X00
00X100
010100
1XXX11
011X11
00X111
010111
921  
922 # We consume the continuation marker at the beginning of the delimiter row.
923 3141 ▶ return unless $this->{md} =~ m/\G ${cont} \ {0,$n} (\|)? /gx;
Branch: 1 branch
BranchTrueFalseTotal
unless $this->{"md"} =~ /\G $cont \ {0,$n} (\|)? /gux 0 3141 3141
924  
925 3141 ▶ $has_pipe &&= defined $1;
Condition100%3/3
$has_pipe &&= defined $1
!ll&&!rl&&r
3091428
MC/DC100%2/2
$has_pipe &&= defined $1
$has_pipe defined $1
Truth table100%3/3
A &&= B
A= $has_pipeB= defined $1
ABresult
0X0
100
111
926  
927 3141 my @separators = $this->{md} =~ m/\G [ \t]* ( :? -+ :? ) [ \t]* \| /gcx;
928 3141 ▶ return unless $this->{md} =~ m/\G [ \t]* (:? -+ :?)? [ \t]* (:? ${eol_re} | $ ) /gcx;
Branch: 1 branch
BranchTrueFalseTotal
unless $this->{"md"} =~ /\G [ \t]* (:? -+ :?)? [ \t]* (:? $eol_re | $ ) /cgux 2562 579 3141
929 579 ▶ if (defined $1) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $1) 61 518 579
930 61 push @separators, $1;
931 61 $has_pipe = 0;
932 }
933 579 ▶ return unless @separators == @headers;
Branch: 1 branch
BranchTrueFalseTotal
unless @separators == @headers 569 10 579
934 my @align =
935 10 ▶ map { s/^(:)?-+(:)?$/ $1 ? ($2 ? 'center' : 'left') : ($2 ? 'right' : '') /er } @separators;
Branch: 3 branches
BranchTrueFalseTotal
$1 ? : 4 15 19
$2 ? : 1 3 4
$2 ? : 1 14 15
936  
937 10 ▶ return if ($m eq 'strict' || ($m eq 'loose' && $i) || @headers == 1) && !$has_pipe;
Branch: 1 branch
BranchTrueFalseTotal
if $m eq "strict" || $m eq "loose" && $i || @headers == 1 and not $has_pipe 0 10 10
Condition50%6/12
$m eq "strict" || $m eq "loose" && $i || @headers == 1 and not $has_pipe
!ll&&!rl&&r
910
$m eq "strict" or $m eq "loose" and $i or @headers == 1
l!l&&r!l&&!r
019
$m eq "strict" or $m eq "loose" and $i
l!l&&r!l&&!r
0010
$m eq "loose" and $i
!ll&&!rl&&r
0100
MC/DC0%0/5
$m eq "strict" || $m eq "loose" && $i || @headers == 1 and not $has_pipe
$m eq "strict" $m eq "loose" $i @headers == 1 not $has_pipe
Truth table20%2/10
A or B and C or D and not(E)
A= $m eq "strict"B= $m eq "loose"C= $iD= @headers == 1E= not $has_pipe
ABCDEresult
00X0X0
0100X0
1XXX00
011X00
00X100
010100
1XXX11
011X11
00X111
010111
938 10 ▶ return if $m ne 'lax' && @headers == 1 && !$has_pipe;
Branch: 1 branch
BranchTrueFalseTotal
if $m ne "lax" and @headers == 1 and not $has_pipe 0 10 10
Condition66%4/6
$m ne "lax" and @headers == 1 and not $has_pipe
!ll&&!rl&&r
910
$m ne "lax" and @headers == 1
!ll&&!rl&&r
091
MC/DC0%0/3
$m ne "lax" and @headers == 1 and not $has_pipe
$m ne "lax" @headers == 1 not $has_pipe
Truth table50%2/4
A and B and not(C)
A= $m ne "lax"B= @headers == 1C= not $has_pipe
ABCresult
0XX0
10X0
1100
1111
939 10 ▶ return if $m ne 'lax' && !$has_pipe && min(map { length } @separators) < 2;
Branch: 1 branch
BranchTrueFalseTotal
if $m ne "lax" and not $has_pipe and &min(map({length $_;} @separators)) < 2 3 7 10
Condition83%5/6
$m ne "lax" and not $has_pipe and &min(map({length $_;} @separators)) < 2
!ll&&!rl&&r
613
$m ne "lax" and not $has_pipe
!ll&&!rl&&r
064
MC/DC66%2/3
$m ne "lax" and not $has_pipe and &min(map({length $_;} @separators)) < 2
$m ne "lax" not $has_pipe &min(map({length $_;} @separators)) < 2
Truth table75%3/4
A and not(B) and C
A= $m ne "lax"B= not $has_pipeC= &min(map({length $_;} @separators)) < 2
ABCresult
0XX0
10X0
1100
1111
940  
941 # And now we try to read as many lines as possible
942 7 my @table;
943 7 while (1) {
944 16 ▶ last if pos($this->{md}) == length($this->{md});
Branch: 1 branch
BranchTrueFalseTotal
if pos $this->{"md"} == length $this->{"md"} 5 11 16
945 11 ▶ last unless $this->{md} =~ m/\G ${cont} \ {0,$n} (\|)? /gcx;
Branch: 1 branch
BranchTrueFalseTotal
unless $this->{"md"} =~ /\G $cont \ {0,$n} (\|)? /cgux 0 11 11
946 # TODO: use a simulator to decide whether we are entering a new block-level
947 # structure, rather than using this half baked regex.
948 11 ▶ $has_pipe &&= defined $1;
Condition100%3/3
$has_pipe &&= defined $1
!ll&&!rl&&r
227
MC/DC100%2/2
$has_pipe &&= defined $1
$has_pipe defined $1
Truth table100%3/3
A &&= B
A= $has_pipeB= defined $1
ABresult
0X0
100
111
949 11 ▶ last if !defined $1 && $this->{md} =~ m/\G (?: [ ] | > | ${list_item_marker_re} )/x;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $1 and $this->{"md"} =~ /\G (?: [ ] | > | $list_item_marker_re )/ux 1 10 11
Condition100%3/3
not defined $1 and $this->{"md"} =~ /\G (?: [ ] | > | $list_item_marker_re )/ux
!ll&&!rl&&r
731
MC/DC100%2/2
not defined $1 and $this->{"md"} =~ /\G (?: [ ] | > | $list_item_marker_re )/ux
not defined $1 $this->{"md"} =~ /\G (?: [ ] | > | $list_item_marker_re )/ux
Truth table100%3/3
not(A) and B
A= not defined $1B= $this->{"md"} =~ /\G (?: [ ] | > | $list_item_marker_re )/ux
ABresult
0X0
100
111
950 10 my @cells = $this->{md} =~ m/\G [ \t]* (.*? [ \t]* $e) \| /gcx;
951 10 pos($this->{md}) = pos($this->{md});
952 confess 'Unexpected match failure'
953 10 ▶ unless $this->{md} =~ m/\G [ \t]* (.+)? [ \t]* (?: ${eol_re} | $ ) /gcx;
Branch: 1 branch
BranchTrueFalseTotal
unless $this->{"md"} =~ /\G [ \t]* (.+)? [ \t]* (?: $eol_re | $ ) /cgux 0 10 10
954 10 ▶ if (defined $1) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $1) 2 8 10
955 2 push @cells, $1;
956 2 $has_pipe = 0;
957 }
958 # There is a small bug when we exit here which is that we have consumed a
959 # blank line. The only case where it would matter would be to decide whether
960 # a list is loose or not, which is a pretty "edge" case with tables.
961 # Otherwise, we will start a new paragraph in all cases.
962 10 ▶ last unless @cells;
Branch: 1 branch
BranchTrueFalseTotal
unless @cells 1 9 10
963 9 ▶ if (@cells != @headers) {
Branch: 1 branch
BranchTrueFalseTotal
if (@cells != @headers) 3 6 9
964 3 $#cells = @headers - 1;
965 # TODO: mention the line number in the file (if possible to track
966 # correctly).
967 3 ▶ carp 'Excess cells in table row are ignored'
Branch: 1 branch
BranchTrueFalseTotal
if @cells > @headers and $this->get_warn_for_unused_input 0 3 3
Condition33%1/3
@cells > @headers and $this->get_warn_for_unused_input
!ll&&!rl&&r
300
MC/DC0%0/2
@cells > @headers and $this->get_warn_for_unused_input
@cells > @headers $this->get_warn_for_unused_input
Truth table33%1/3
A and B
A= @cells > @headersB= $this->get_warn_for_unused_input
ABresult
0X0
100
111
968 if @cells > @headers && $this->get_warn_for_unused_input();
969 }
970 # Pipes need to be escaped inside table, and we need to unescape them here
971 # in case one would appear in a code block for example (where the escaping
972 # would appear literally otherwise). Given that pipes don’t have other
973 # meaning by default, there is not a big risk to do that (and this is
974 # mandated) by the GitHub Spec anyway.
975 9 ▶ push @table, [map { defined ? s/($e)\\\|/${1}|/gr : undef } @cells];
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 14 2 16
976 }
977  
978 7 return {headers => \@headers, align => \@align, table => \@table};
979 }
980  
981 # https://spec.commonmark.org/0.30/#paragraphs
982 106603 ▶sub _do_paragraph {
Subroutine _do_paragraph: called CC=3 SCAR=11.0
983 106603 my ($this) = @_;
984 # We need to test for blank lines here (not just emptiness) because after we
985 # have removed the markers of container blocks our line can become empty. The
986 # fact that we need to do this, seems to imply that we don’t really need to
987 # check for emptiness when initially building $l.
988 # TODO: check if the blank-line detection in next_line() is needed or not.
989 106603 ▶ if ($l !~ m/^[ \t]*$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Markdown::Perl::BlockParser::l =~ /^[ \t]*$/u) 84848 21755 106603
990 84848 push @{$this->{paragraph}}, $l;
991 84848 return 1;
992 }
993  
994 # https://spec.commonmark.org/0.30/#blank-lines
995 # if ($l eq '')
996 21755 $this->_finalize_paragraph();
997 # Needed to detect loose lists. But ignore blank lines when they are inside
998 # block quotes
999 $this->{last_line_is_blank} =
1000 21755 ▶ !@{$this->{blocks_stack}} || $this->{blocks_stack}[-1]{block}{type} ne 'quotes';
Condition100%3/3
!@{$this->{'blocks_stack'};} || $this->{'blocks_stack'}[-1]{'block'}{'type'} ne 'quotes'
l!l&&r!l&&!r
1732230511382
MC/DC100%2/2
!@{$this->{'blocks_stack'};} || $this->{'blocks_stack'}[-1]{'block'}{'type'} ne 'quotes'
!@{$this->{'blocks_stack'};} $this->{'blocks_stack'}[-1]{'block'}{'type'} ne 'quotes'
Truth table100%3/3
not(A) || B
A= !@{$this->{'blocks_stack'};}B= $this->{'blocks_stack'}[-1]{'block'}{'type'} ne 'quotes'
ABresult
1X1
011
000
1001 21755 return 1;
1002 }
1003  
1004 259 ▶sub _unescape_char {
Subroutine _unescape_char: called CC=1 SCAR=0.0
1005 # TODO: configure the set of escapable character. Note that this regex is
1006 # shared with Inlines.pm process_char_escaping.
1007 259 $_[0] =~ s/\\(\p{PosixPunct})/$1/g;
1008 259 return;
1009 }
1010  
1011 31 1;
« Markdown/Perl.pm ↑ Summary Markdown/Perl/InlineTree.pm »