lib/Text/AsciidocDown/Subs.pm

filter: Statementstmt 97.1% 201 / 207 Branchbran 70.0% 70 / 100 Conditioncond 58.3% 28 / 48 MC/DCmcdc 31.0% 9 / 29 Subroutinesub 100% 29 / 29 Podpod 54.5% 6 / 11 totaltotal 80.9% 343 / 424 CC 68 SCAR 18.6
CC
68
Cov
84%
_rewrite_xref_macro
16.5
image_to_markdown
10.5
apply_macros
9.0
CRAP 6.4
« lib/Text/AsciidocDown/Refs.pm ↑ Summary lib/Text/AsciidocDown.pm »
1 package Text::AsciidocDown::Subs;
2  
3 18 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 18 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 18 our $VERSION = '0.1.3';
7  
8 18 my $ATTR_REF_RX = qr/(\\)?\{([a-z0-9_][a-z0-9_-]*)\}/i;
9 18 my $INLINE_ANCHOR_RX = qr/\[\[([A-Za-z_][A-Za-z0-9_\-:.]*)\]\]/;
10 18 my $INLINE_IMG_RX = qr/image:([^\s:`[\\][^[\\]*)\[(|.*?[^\\])\]/;
11 18 my $XREF_SHORT_RX = qr/<<([^\s,>][^,>]*)(?:, ?([^>]+))?>>/;
12 18 my $BOLD_RX = qr/(?<![A-Za-z0-9_\\])\*(\S(?:.*?\S)?)\*(?![A-Za-z0-9_])/;
13 18 my $EMPH_RX = qr/(?<![A-Za-z0-9_\\])_(\S(?:.*?\S)?)_(?![A-Za-z0-9_])/;
14 18 my $MARK_RX = qr/(?<![A-Za-z0-9_\\])#(\S(?:.*?\S)?)#(?![A-Za-z0-9_])/;
15 18 my $STRIKE_MARK_RX = qr/(?<![A-Za-z0-9_\\])\[\.line-through\]#(\S(?:.*?\S)?)#(?![A-Za-z0-9_])/;
16 18 my $MONO_PASSTHRU_RX = qr/`\+(.*?)\+`/;
17  
18 # A code-span opening backtick. A backtick that is part of a standalone
19 # curly-quote marker must not open a span, or two markers in one line
20 # (the file`'s x, the account`'s y) are swallowed as a single span and
21 # never converted:
22 # * a backtick preceded by a quote character is the close of a "`
23 # or '` opener marker, never a span opener;
24 # * a backtick preceded by a letter, digit or sentence punctuation and
25 # followed by a quote character is a `' or `" closer marker (a
26 # constrained span cannot open right after a word character anyway).
27 # Genuine paired quotes were already consumed by apply_quotes().
28 18 my $MONO_RX = qr/(?<!['"])(?:(?<![\p{L}\p{N}.,;:!?)])|(?!`['"]))`(\S(?:.*?\S)?)`/;
29 18 my $PASSTHROUGH_RX = qr/\+\+\+(.*?)\+\+\+/s;
30  
31 sub build_attributes
32 99 ▶{
Subroutine build_attributes: called CC=3 SCAR=11.0
Pod documented
33 99 my ($runtime) = @_;
34  
35 99 my %attrs = (
36 empty => '',
37 idprefix => '_',
38 idseparator => '_',
39 'markdown-line-break' => '\\',
40 'markdown-strikethrough' => '~~',
41 nbsp => '&#160;',
42 quotes => "\x{201C} \x{201D}",
43 'quotes-single' => "\x{2018} \x{2019}",
44 sp => ' ',
45 vbar => '|',
46 zwsp => '&#8203;',
47 );
48  
49 99 ▶ if (ref($runtime) eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $runtime eq "HASH") 99 0 99
50 {
51 99 for my $k (keys %{$runtime})
52 {
53 6 $attrs{$k} = $runtime->{$k};
54 }
55 }
56  
57 99 return \%attrs;
58 }
59  
60 sub substitute_attributes
61 251 ▶{
Subroutine substitute_attributes: called CC=4 SCAR=14.1
Pod documented
62 251 my ($text, $attrs) = @_;
63 251 ▶ return '' unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 251 251
64 251 ▶ return $text unless ref($attrs) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $attrs eq "HASH" 0 251 251
65  
66 251 ▶ return $text =~ /\{/ ? $text =~ s/$ATTR_REF_RX/_replace_attr_ref($1, $2, $attrs)/gier : $text;
Branch: 1 branch
BranchTrueFalseTotal
$text =~ /\{/ ? : 7 244 251
67 }
68  
69 sub apply_normal_subs
70 173 ▶{
Subroutine apply_normal_subs: called CC=4 SCAR=13.9
Pod documented
71 173 my ($text, $attrs) = @_;
72 173 ▶ return '' unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 173 173
73  
74 # AsciiDoc inline passthrough (+++...+++) must survive completely
75 # unprocessed -- no escaping, no quote/format substitution, no
76 # attribute or macro expansion, exactly like real AsciiDoc passthrough
77 # semantics. It is stashed here, before any other step runs, and
78 # restored verbatim at the very end. Without this, a literal
79 # "+++<tag>+++" in the source (or one generated by a round trip through
80 # a Markdown-to-AsciiDoc converter that wraps unknown inline HTML this
81 # way) gets its "<" escaped to "&lt;" by escape_lt_outside_monospace()
82 # like any other text, corrupting content that is supposed to be
83 # emitted verbatim.
84 173 my @passthrough;
85 173 ▶ $text =~ s/$PASSTHROUGH_RX/_stash_passthrough(\@passthrough, $1)/ge if index($text, '+++') >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($text, "+++") != -1 4 169 173
86  
87 # Order mirrors a pragmatic flow similar to downdoc:
88 # escape-sensitive quote/format handling first, then attrs/macros.
89 173 $text = escape_lt_outside_monospace($text);
90 173 $text = apply_quotes($text, $attrs);
91 173 $text = apply_inline_formatting($text, $attrs);
92 173 $text = substitute_attributes($text, $attrs);
93 173 $text = apply_macros($text, $attrs);
94 173 $text = apply_curly_apostrophe($text);
95  
96 173 ▶ $text =~ s/\x{1F}PASS(\d+)\x{1E}/$passthrough[$1]/ge if @passthrough;
Branch: 1 branch
BranchTrueFalseTotal
if @passthrough 4 169 173
97  
98 173 return $text;
99 }
100  
101 sub apply_inline_formatting
102 173 ▶{
Subroutine apply_inline_formatting: called CC=2 SCAR=7.0
Pod undocumented
103 173 my ($text, $attrs) = @_;
104 173 ▶ return '' unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 173 173
105  
106 173 my @mono;
107 0 $text =~ s/$MONO_PASSTHRU_RX/_stash_mono(\@mono, $1)/ge;
108 173 $text =~ s/$MONO_RX/_stash_mono(\@mono, $1)/ge;
109  
110 # Standalone curly-quote/apostrophe markers (`', '`, `", "`) must be
111 # resolved here, after real code-span backticks have been stashed above
112 # and before they are restored below. apply_quotes() has already run
113 # (see apply_normal_subs) and consumed any genuine paired '`text`' or
114 # "`text`" forms, so any bare marker pair still present at this point is
115 # a true standalone marker and cannot be a code-span delimiter.
116 173 $text = apply_standalone_quote_markers($text);
117  
118 173 $text =~ s/$STRIKE_MARK_RX/_strikethrough($1, $attrs)/ge;
119 173 $text =~ s/$MARK_RX/<mark>$1<\/mark>/g;
120 173 $text =~ s/$BOLD_RX/*$1*/g;
121 173 $text =~ s/$EMPH_RX/_$1_/g;
122  
123 173 $text =~ s/\x{1F}MONO(\d+)\x{1E}/'`' . $mono[$1] . '`'/ge;
124 173 return $text;
125 }
126  
127 sub apply_standalone_quote_markers
128 173 ▶{
Subroutine apply_standalone_quote_markers: called CC=2 SCAR=7.0
Pod undocumented
129 173 my ($text) = @_;
130 173 ▶ return '' unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 173 173
131  
132 173 $text =~ s/`'/\x{2019}/g;
133 173 $text =~ s/'`/\x{2018}/g;
134 173 $text =~ s/`"/\x{201D}/g;
135 173 $text =~ s/"`/\x{201C}/g;
136  
137 173 return $text;
138 }
139  
140 sub apply_quotes
141 173 ▶{
Subroutine apply_quotes: called CC=4 SCAR=14.6
Pod undocumented
142 173 my ($text, $attrs) = @_;
143 173 ▶ return '' unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 173 173
144 173 ▶ return $text unless defined($attrs) && ref($attrs) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $attrs and ref $attrs eq "HASH" 0 173 173
Condition33%1/3
defined $attrs and ref $attrs eq "HASH"
!ll&&!rl&&r
00173
MC/DC0%0/2
defined $attrs and ref $attrs eq "HASH"
defined $attrs ref $attrs eq "HASH"
Truth table33%1/3
A and B
A= defined $attrsB= ref $attrs eq "HASH"
ABresult
0X0
100
111
145  
146 # Unlike downdoc (which uses one `quotes` attribute for both paired
147 # forms and defaults to raw `<q></q>` HTML), this module distinguishes
148 # the double-quoted and single-quoted forms and defaults to real curly
149 # Unicode characters. That default is what makes the round trip through
150 # Text::MarkdownAdoc stable (it maps U+201C/201D and U+2018/2019 back to
151 # these exact AsciiDoc forms); `<q></q>` never stabilises because it is
152 # unknown HTML that gets re-escaped as passthrough on every pass.
153 # Callers who want the old shared `<q></q>` behavior can still get it
154 # by setting both `quotes` and `quotes-single` explicitly.
155 173 my ($dq_open, $dq_close) = _quote_pair($attrs->{quotes}, "\x{201C}", "\x{201D}");
156 173 my ($sq_open, $sq_close) = _quote_pair($attrs->{'quotes-single'}, "\x{2018}", "\x{2019}");
157  
158 # AsciiDoc quote syntax in this phase: "`text`" and '`text`'
159 #
160 # Content must be bounded by non-whitespace on both sides (a single
161 # non-space character, or non-space...non-space), mirroring downdoc's
162 # QuotedSpanRx (`("|')`(\S|\S.*?\S)`\1`). This intentionally rejects
163 # empty (` `` `) and whitespace-padded (` ` text ` `) spans, which
164 # downdoc never treats as a quoted span either. Anything rejected here
165 # still falls through to apply_standalone_quote_markers() later, which
166 # resolves the individual open/close markers on their own.
167 173 $text =~ s/"`(\S(?:.*?\S)?)`"/$dq_open$1$dq_close/g;
168 173 $text =~ s/'`(\S(?:.*?\S)?)`'/$sq_open$1$sq_close/g;
169 173 return $text;
170 }
171  
172 sub apply_macros
173 173 ▶{
Subroutine apply_macros: called CC=9 SCAR=22.0
Pod undocumented
174 173 my ($text, $attrs) = @_;
175 173 ▶ return '' unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 173 173
176  
177 173 ▶ $text = _apply_inline_anchor($text) if index($text, '[[') >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($text, "[[") != -1 1 172 173
178 173 ▶ $text = _apply_images($text, $attrs) if index($text, 'image:') >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($text, "image:") != -1 3 170 173
179 173 ▶ $text = _apply_links($text, $attrs)
Branch: 1 branch
BranchTrueFalseTotal
if index($text, "http://") != -1 or index($text, "https://") != -1 or index($text, "link:") != -1 4 169 173
Condition83%5/6
index($text, "http://") != -1 or index($text, "https://") != -1 or index($text, "link:") != -1
l!l&&r!l&&!r
31169
index($text, "http://") != -1 or index($text, "https://") != -1
l!l&&r!l&&!r
03170
MC/DC66%2/3
index($text, "http://") != -1 or index($text, "https://") != -1 or index($text, "link:") != -1
index($text, "http://") != -1 index($text, "https://") != -1 index($text, "link:") != -1
Truth table75%3/4
A or B or C
A= index($text, "http://") != -1B= index($text, "https://") != -1C= index($text, "link:") != -1
ABCresult
1XX1
01X1
0011
0000
180 if index($text, 'http://') >= 0 || index($text, 'https://') >= 0 || index($text, 'link:') >= 0;
181 173 ▶ $text = _apply_xrefs($text) if index($text, 'xref:') >= 0 || index($text, '<<') >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($text, "xref:") != -1 or index($text, "<<") != -1 6 167 173
Condition100%3/3
index($text, "xref:") != -1 or index($text, "<<") != -1
l!l&&r!l&&!r
42167
MC/DC100%2/2
index($text, "xref:") != -1 or index($text, "<<") != -1
index($text, "xref:") != -1 index($text, "<<") != -1
Truth table100%3/3
A or B
A= index($text, "xref:") != -1B= index($text, "<<") != -1
ABresult
1X1
011
000
182 173 return $text;
183 }
184  
185 sub block_image_to_markdown
186 140 ▶{
Subroutine block_image_to_markdown: called CC=3 SCAR=11.0
Pod documented
187 140 my ($line, $attrs) = @_;
188 140 ▶ return undef unless defined $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 0 140 140
189 140 ▶ return undef unless $line =~ /^image::([^\s[][^[]*)\[(.*)\]$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /^image::([^\s[][^[]*)\[(.*)\]$/ 139 1 140
190  
191 1 my ($target, $attrlist) = ($1, $2);
192 1 $target = substitute_attributes($target, $attrs);
193 1 return image_to_markdown($target, $attrlist, $attrs);
194 }
195  
196 sub image_to_markdown
197 4 ▶{
Subroutine image_to_markdown: called CC=10 SCAR=23.5
Pod documented
198 4 my ($target, $attrlist, $attrs) = @_;
199 4 ▶ $target = '' unless defined $target;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $target 0 4 4
200 4 ▶ $attrlist = '' unless defined $attrlist;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $attrlist 0 4 4
201  
202 4 my $alt = '';
203 4 ▶ if (length $attrlist)
Branch: 1 branch
BranchTrueFalseTotal
if (length $attrlist) 3 1 4
204 {
205 3 ($alt) = split /,/, $attrlist, 2;
206 }
207 4 ▶ if (!defined($alt) || $alt eq '')
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $alt or $alt eq "") 1 3 4
Condition66%2/3
not defined $alt or $alt eq ""
l!l&&r!l&&!r
013
MC/DC50%1/2
not defined $alt or $alt eq ""
not defined $alt $alt eq ""
Truth table66%2/3
not(A) or B
A= not defined $altB= $alt eq ""
ABresult
1X1
011
000
208 {
209 1 my $base = $target;
210 1 $base =~ s{.*/}{};
211 1 $base =~ s{\.[^.]+$}{};
212 1 $alt = $base;
213 }
214  
215 4 ▶ if (ref($attrs) eq 'HASH' && defined $attrs->{imagesdir} && $attrs->{imagesdir} ne '' && $target !~ m{^(?:https?://|/)})
Branch: 1 branch
BranchTrueFalseTotal
if (ref $attrs eq "HASH" and defined $attrs->{"imagesdir"} and $attrs->{"imagesdir"} ne "" and not $target =~ m[^(?:https?://|/)]) 1 3 4
Condition66%6/9
ref $attrs eq "HASH" and defined $attrs->{"imagesdir"} and $attrs->{"imagesdir"} ne "" and not $target =~ m[^(?:https?://|/)]
!ll&&!rl&&r
301
ref $attrs eq "HASH" and defined $attrs->{"imagesdir"} and $attrs->{"imagesdir"} ne ""
!ll&&!rl&&r
301
ref $attrs eq "HASH" and defined $attrs->{"imagesdir"}
!ll&&!rl&&r
031
MC/DC25%1/4
ref $attrs eq "HASH" and defined $attrs->{"imagesdir"} and $attrs->{"imagesdir"} ne "" and not $target =~ m[^(?:https?://|/)]
ref $attrs eq "HASH" defined $attrs->{"imagesdir"} $attrs->{"imagesdir"} ne "" not $target =~ m[^(?:https?://|/)]
Truth table40%2/5
A and B and C and not(D)
A= ref $attrs eq "HASH"B= defined $attrs->{"imagesdir"}C= $attrs->{"imagesdir"} ne ""D= not $target =~ m[^(?:https?://|/)]
ABCDresult
0XXX0
10XX0
110X0
11100
11111
216 {
217 1 $target = $attrs->{imagesdir} . '/' . $target;
218 }
219  
220 4 return '![' . $alt . '](' . $target . ')';
221 }
222  
223 sub escape_lt_outside_monospace
224 173 ▶{
Subroutine escape_lt_outside_monospace: called CC=2 SCAR=7.0
Pod documented
225 173 my ($text) = @_;
226 173 ▶ return '' unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 173 173
227  
228 173 my @mono;
229 0 $text =~ s/$MONO_PASSTHRU_RX/_stash_mono(\@mono, $1)/ge;
230 173 $text =~ s/$MONO_RX/_stash_mono(\@mono, $1)/ge;
231  
232 # Preserve xref shorthand delimiters while escaping normal less-than signs.
233 173 $text =~ s/<</\x{1F}XREFL\x{1E}/g;
234 173 $text =~ s/>>/\x{1F}XREFR\x{1E}/g;
235 173 $text =~ s/</&lt;/g;
236 173 $text =~ s/\x{1F}XREFL\x{1E}/<</g;
237 173 $text =~ s/\x{1F}XREFR\x{1E}/>>/g;
238  
239 173 $text =~ s/\x{1F}MONO(\d+)\x{1E}/'`' . $mono[$1] . '`'/ge;
240 173 return $text;
241 }
242  
243 sub apply_curly_apostrophe
244 173 ▶{
Subroutine apply_curly_apostrophe: called CC=2 SCAR=7.0
Pod undocumented
245 173 my ($text) = @_;
246 173 ▶ return '' unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 173 173
247  
248 173 return $text =~ s/(?<=[A-Za-z0-9])'(?=[A-Za-z])/"\x{2019}"/ger;
249 }
250  
251 sub _replace_attr_ref
252 10 ▶{
Subroutine _replace_attr_ref: called CC=3 SCAR=11.1
253 10 my ($escaped, $name, $attrs) = @_;
254 10 ▶ return '{' . $name . '}' if $escaped;
Branch: 1 branch
BranchTrueFalseTotal
if $escaped 0 10 10
255 10 ▶ return exists $attrs->{$name} ? _stringify($attrs->{$name}) : '{' . $name . '}';
Branch: 1 branch
BranchTrueFalseTotal
exists $attrs->{$name} ? : 9 1 10
256 }
257  
258 sub _apply_inline_anchor
259 1 ▶{
Subroutine _apply_inline_anchor: called CC=1 SCAR=0.0
260 1 my ($text) = @_;
261 1 return $text =~ s{$INLINE_ANCHOR_RX}{'<a name="' . $1 . '"></a>'}ger;
262 }
263  
264 sub _apply_images
265 3 ▶{
Subroutine _apply_images: called CC=1 SCAR=0.0
266 3 my ($text, $attrs) = @_;
267 3 $text =~ s{$INLINE_IMG_RX}{image_to_markdown($1, $2, $attrs)}ge;
268 3 return $text;
269 }
270  
271 sub _apply_links
272 4 ▶{
Subroutine _apply_links: called CC=1 SCAR=0.0
273 4 my ($text, $attrs) = @_;
274  
275 # link:target[text]
276 4 $text =~ s{(?<!\\)link:([^\s\[]+)\[(.*?)\]}{_rewrite_link_macro($1, $2, $attrs)}ge;
277  
278 # URL macro https://target[text]
279 4 $text =~ s{(?<!\\)(https?://[^\s\[]+)\[(.*?)\]}{_rewrite_url_macro($1, $2, $attrs)}ge;
280  
281 # Bare URL
282 4 $text =~ s{(?<![\\\w/])(https?://[^\s\])]+)}{_rewrite_bare_url($1, $attrs)}ge;
283  
284 # Escaped URL macro/bare URL handling.
285 4 $text =~ s{\\(https?://)([^\s\]]+)}{'<span>' . $1 . '</span>' . $2}ge;
286 4 $text =~ s{\\link:([^\s\[]+)\[(.*?)\]}{'link:' . $1 . '[' . $2 . ']'}ge;
287  
288 4 return $text;
289 }
290  
291 sub _apply_xrefs
292 6 ▶{
Subroutine _apply_xrefs: called CC=1 SCAR=0.0
293 6 my ($text) = @_;
294  
295 6 $text =~ s{(?<!\\)xref:([^\[]+)\[(.*?)\]}{_rewrite_xref_macro($1, $2)}ge;
296 6 $text =~ s{$XREF_SHORT_RX}{_rewrite_xref_short($1, $2)}ge;
297 6 return $text;
298 }
299  
300 sub _rewrite_xref_macro
301 6 ▶{
Subroutine _rewrite_xref_macro: called CC=13 SCAR=28.0
302 6 my ($target, $text) = @_;
303 6 $target =~ s/^\s+|\s+$//g;
304 6 ▶ my $label = (defined($text) && $text ne '') ? $text : $target;
Branch: 1 branch
BranchTrueFalseTotal
defined $text && $text ne '' ? : 2 4 6
Condition66%2/3
defined $text and $text ne ""
!ll&&!rl&&r
042
MC/DC50%1/2
defined $text and $text ne ""
defined $text $text ne ""
Truth table66%2/3
A and B
A= defined $textB= $text ne ""
ABresult
0X0
100
111
305  
306 6 ▶ if ($target =~ /^#(.+)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($target =~ /^#(.+)$/) 4 2 6
307 {
308 4 my $id = $1;
309 4 ▶ return 'xref:#' . $id . '[' . (defined($text) ? $text : '') . ']' if $id =~ /\s/;
Branch: 2 branches
BranchTrueFalseTotal
if $id =~ /\s/ 1 3 4
defined $text ? : 1 0 1
310 3 ▶ return '[' . (($label ne '#' . $id) ? $label : $id) . '](#!' . $id . ')';
Branch: 1 branch
BranchTrueFalseTotal
$label ne '#' . $id ? : 1 2 3
311 }
312  
313 2 ▶ if ($target =~ /\.adoc#(.+)/)
Branch: 1 branch
BranchTrueFalseTotal
if ($target =~ /\.adoc#(.+)/) 1 1 2
314 {
315 1 my $frag = $1;
316 1 ▶ return 'xref:' . $target . '[' . (defined($text) ? $text : '') . ']' if $frag =~ /\s/;
Branch: 2 branches
BranchTrueFalseTotal
if $frag =~ /\s/ 1 0 1
defined $text ? : 1 0 1
317 }
318  
319 # Natural/internal xref target: defer resolution to parser post-pass.
320 1 ▶ if ($target !~ m{^(?:https?://|/)} && $target !~ /\.adoc(?:#.*)?$/)
Branch: 1 branch
BranchTrueFalseTotal
unless ($target =~ m[^(?:https?://|/)] or $target =~ /\.adoc(?:#.*)?$/) 1 0 1
Condition33%1/3
$target =~ m[^(?:https?://|/)] or $target =~ /\.adoc(?:#.*)?$/
l!l&&r!l&&!r
001
MC/DC0%0/2
$target =~ m[^(?:https?://|/)] or $target =~ /\.adoc(?:#.*)?$/
$target =~ m[^(?:https?://|/)] $target =~ /\.adoc(?:#.*)?$/
Truth table33%1/3
A or B
A= $target =~ m[^(?:https?://|/)]B= $target =~ /\.adoc(?:#.*)?$/
ABresult
1X1
011
000
321 {
322 1 return '[' . $label . '](#!' . $target . ')';
323 }
324  
325 # External/interdocument fallback.
326 0 $target =~ s/#$//;
327 0 ▶ return '[' . ($label ne '' ? $label : $target) . '](' . $target . ')';
Branch: 1 branch
BranchTrueFalseTotal
$label ne '' ? : 0 0 0
328 }
329  
330 sub _rewrite_xref_short
331 5 ▶{
Subroutine _rewrite_xref_short: called CC=5 SCAR=16.1
332 5 my ($id, $text) = @_;
333 5 ▶ return '<<' . $id . (defined($text) ? ', ' . $text : '') . '>>' if $id =~ /\s/;
Branch: 2 branches
BranchTrueFalseTotal
if $id =~ /\s/ 3 2 5
defined $text ? : 1 2 3
334 2 ▶ return '[' . (defined($text) && $text ne '' ? $text : $id) . '](#!' . $id . ')';
Branch: 1 branch
BranchTrueFalseTotal
defined $text && $text ne '' ? : 1 1 2
Condition66%2/3
defined $text and $text ne ""
!ll&&!rl&&r
101
MC/DC50%1/2
defined $text and $text ne ""
defined $text $text ne ""
Truth table66%2/3
A and B
A= defined $textB= $text ne ""
ABresult
0X0
100
111
335 }
336  
337 sub _hide_uri_scheme
338 2 ▶{
Subroutine _hide_uri_scheme: called CC=2 SCAR=7.1
339 2 my ($attrs) = @_;
340 2 ▶ return ref($attrs) eq 'HASH' && exists $attrs->{'hide-uri-scheme'};
Condition66%2/3
ref $attrs eq 'HASH' && exists $attrs->{'hide-uri-scheme'}
!ll&&!rl&&r
011
MC/DC50%1/2
ref $attrs eq 'HASH' && exists $attrs->{'hide-uri-scheme'}
ref $attrs eq 'HASH' exists $attrs->{'hide-uri-scheme'}
Truth table66%2/3
A && B
A= ref $attrs eq 'HASH'B= exists $attrs->{'hide-uri-scheme'}
ABresult
0X0
100
111
341 }
342  
343 sub _rewrite_link_macro
344 1 ▶{
Subroutine _rewrite_link_macro: called CC=4 SCAR=15.6
345 1 my ($target, $text, $attrs) = @_;
346 1 ▶ return 'link:' . $target . '[' . $text . ']' if $target =~ /\s/;
Branch: 1 branch
BranchTrueFalseTotal
if $target =~ /\s/ 0 1 1
347 1 ▶ my $label = (defined($text) && $text ne '') ? $text : $target;
Branch: 1 branch
BranchTrueFalseTotal
defined $text && $text ne '' ? : 1 0 1
Condition33%1/3
defined $text and $text ne ""
!ll&&!rl&&r
001
MC/DC0%0/2
defined $text and $text ne ""
defined $text $text ne ""
Truth table33%1/3
A and B
A= defined $textB= $text ne ""
ABresult
0X0
100
111
348 1 return '[' . $label . '](' . $target . ')';
349 }
350  
351 sub _rewrite_url_macro
352 1 ▶{
Subroutine _rewrite_url_macro: called CC=4 SCAR=17.9
353 1 my ($url, $text, $attrs) = @_;
354 1 my $label;
355 1 ▶ if (defined($text) && $text ne '')
Branch: 2 branches
BranchTrueFalseTotal
if (defined $text and $text ne '') { } 1 0 1
elsif (_hide_uri_scheme($attrs)) { } 0 0 0
Condition33%1/3
defined $text and $text ne ""
!ll&&!rl&&r
001
MC/DC0%0/2
defined $text and $text ne ""
defined $text $text ne ""
Truth table33%1/3
A and B
A= defined $textB= $text ne ""
ABresult
0X0
100
111
356 {
357 1 $label = $text;
358 }
359 elsif (_hide_uri_scheme($attrs))
360 {
361 0 ($label = $url) =~ s{^https?://}{};
362 }
363 else
364 {
365 0 $label = $url;
366 }
367 1 return '[' . $label . '](' . $url . ')';
368 }
369  
370 sub _rewrite_bare_url
371 2 ▶{
Subroutine _rewrite_bare_url: called CC=2 SCAR=6.9
372 2 my ($url, $attrs) = @_;
373 2 ▶ return $url unless _hide_uri_scheme($attrs);
Branch: 1 branch
BranchTrueFalseTotal
unless _hide_uri_scheme($attrs) 1 1 2
374 1 (my $label = $url) =~ s{^https?://}{};
375 1 return '[' . $label . '](' . $url . ')';
376 }
377  
378 sub _quote_pair
379 346 ▶{
Subroutine _quote_pair: called CC=4 SCAR=15.2
380 346 my ($quotes, $default_open, $default_close) = @_;
381 346 ▶ return ($default_open, $default_close) unless defined $quotes && length $quotes;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $quotes and length $quotes 0 346 346
Condition33%1/3
defined $quotes and length $quotes
!ll&&!rl&&r
00346
MC/DC0%0/2
defined $quotes and length $quotes
defined $quotes length $quotes
Truth table33%1/3
A and B
A= defined $quotesB= length $quotes
ABresult
0X0
100
111
382 346 my @parts = split /\s+/, $quotes;
383 346 ▶ my ($open, $close) = @parts >= 2 ? @parts[0, 1] : ($default_open, $default_close);
Branch: 1 branch
BranchTrueFalseTotal
@parts >= 2 ? : 346 0 346
384 346 return ($open, $close);
385 }
386  
387 sub _strikethrough
388 2 ▶{
Subroutine _strikethrough: called CC=4 SCAR=14.5
389 2 my ($text, $attrs) = @_;
390 2 ▶ my $mark = ref($attrs) eq 'HASH' && defined($attrs->{'markdown-strikethrough'}) ? $attrs->{'markdown-strikethrough'} :
Branch: 1 branch
BranchTrueFalseTotal
ref $attrs eq 'HASH' && defined $attrs->{'markdown-strikethrough'} ? : 2 0 2
Condition33%1/3
ref $attrs eq "HASH" and defined $attrs->{"markdown-strikethrough"}
!ll&&!rl&&r
002
MC/DC0%0/2
ref $attrs eq "HASH" and defined $attrs->{"markdown-strikethrough"}
ref $attrs eq "HASH" defined $attrs->{"markdown-strikethrough"}
Truth table33%1/3
A and B
A= ref $attrs eq "HASH"B= defined $attrs->{"markdown-strikethrough"}
ABresult
0X0
100
111
391 '~~';
392  
393 2 my @parts = split /\s+/, $mark;
394 2 ▶ my ($open, $close) = @parts >= 2 ? @parts[0, 1] : ($mark, $mark);
Branch: 1 branch
BranchTrueFalseTotal
@parts >= 2 ? : 1 1 2
395 2 return $open . $text . $close;
396 }
397  
398 sub _stash_mono
399 12 ▶{
Subroutine _stash_mono: called CC=1 SCAR=0.0
400 12 my ($stash, $content) = @_;
401 12 push @{$stash}, $content;
402 12 return "\x{1F}MONO" . ($#{$stash}) . "\x{1E}";
403 }
404  
405 sub _stash_passthrough
406 4 ▶{
Subroutine _stash_passthrough: called CC=1 SCAR=0.0
407 4 my ($stash, $content) = @_;
408 4 push @{$stash}, $content;
409 4 return "\x{1F}PASS" . ($#{$stash}) . "\x{1E}";
410 }
411  
412 sub _stringify
413 9 ▶{
Subroutine _stringify: called CC=2 SCAR=7.1
414 9 my ($value) = @_;
415 9 ▶ return '' unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 9 9
416 9 return "$value";
417 }
418  
419 18 1;
420  
421 __END__
« lib/Text/AsciidocDown/Refs.pm ↑ Summary lib/Text/AsciidocDown.pm »