blib/lib/App/Greple/md/widen.pm

filter: Statementstmt 100% 21 / 21 Branchbran 100% 4 / 4 Conditioncond 100% 5 / 5 MC/DCmcdc 100% 3 / 3 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 2 totaltotal 95.0% 38 / 40 CC 5 SCAR 9.4
CC
5
Cov
100%
class
4.0
widen
2.0
BEGIN
1.0
CRAP 2.6
« blib/lib/App/Greple/md.pm ↑ Summary blib/lib/App/mdee.pm »
1 package App::Greple::md::widen;
2  
3 4 ▶use 5.026;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 our $VERSION = "1.19";
8  
9 =encoding utf-8
10  
11 =head1 NAME
12  
13 App::Greple::md::widen - give some characters a column of their own
14  
15 =head1 SYNOPSIS
16  
17 greple -Mmd --begin '&widen' -- file.md
18 greple -Mmd --begin '&widen(chars=2460-24FF:3248-324F)' -- file.md
19  
20 mdee -t widen file.md
21  
22 =head1 DESCRIPTION
23  
24 Circled digits and the wastebasket (U+1F5D1) are one column wide to
25 Unicode and to the terminals, but macOS terminals draw them over two
26 columns, on top of the next character. The function B<widen>, for the
27 C<--begin> option of L<App::Greple::md>, adds a no-break space after
28 such a character, so that its width is right for every tool. A
29 no-break space is used because it stays at the end of a folded line,
30 where B<ansifold> removes spaces. A variation selector (U+FE0E or
31 U+FE0F) after the character stays with it, and the space comes after
32 the selector.
33  
34 Fenced code with a language, code spans, the addresses of links and
35 autolinks are left as they are, because a program must stay as it is
36 written. Fenced code without a language is often a figure or an
37 output, and is changed. Copying the text from the screen brings the
38 no-break spaces along.
39  
40 =head1 PARAMETERS
41  
42 =over 4
43  
44 =item B<chars>
45  
46 The characters as code points and ranges in hexadecimal, separated by
47 colons. Default is C<2460-24FF:1F5D1>, the circled digits and the
48 wastebasket.
49  
50 =back
51  
52 =head1 SEE ALSO
53  
54 L<App::Greple::md>, L<App::mdee>
55  
56 =head1 LICENSE
57  
58 This software is released under the MIT License.
59 L<https://opensource.org/licenses/MIT>
60  
61 =cut
62  
63 # Where the text must stay as written: fenced code with a language, code
64 # spans, and the addresses of links.
65 4 my $SKIP = qr{
66 (?:
67 ^ [ ]{0,3} (?<_fence> (?<_fc>[`~]) \g{_fc}{2,}+ ) \h* \S .* \n
68 (?s:.*?)
69 ^ [ ]{0,3} \g{_fence} \g{_fc}*+ \h* $
70 |
71 (?<_bt> `++ ) (?: (?! \g{_bt} ) . )+? \g{_bt}
72 |
73 \] \( [^)\n]* \)
74 |
75 < [a-zA-Z][\w+.-]*: [^>\s]* >
76 )
77 (*SKIP)(*FAIL)
78 }xm;
79  
80 31 ▶sub class {
Subroutine class: called CC=4 SCAR=13.9
Pod undocumented
81 31 my $spec = shift;
82 31 state %class;
83 31 ▶ $class{$spec} //= do {
Condition100%3/3
$class{$spec} //= do { my $ranges = join("", map({/\A([0-9a-fA-F]+)(?:-([0-9a-fA-F]+))?\z/u or die "widen: ${spec}: bad range\n"; defined $2 ? "\\x{$1}-\\x{$2}" : "\\x{$1}";} split(/:/u, $spec, 0))); qr/[$ranges]/u }
l!l&&r!l&&!r
2371
MC/DC100%2/2
$class{$spec} //= do { my $ranges = join("", map({/\A([0-9a-fA-F]+)(?:-([0-9a-fA-F]+))?\z/u or die "widen: ${spec}: bad range\n"; defined $2 ? "\\x{$1}-\\x{$2}" : "\\x{$1}";} split(/:/u, $spec, 0))); qr/[$ranges]/u }
$class{$spec} do { my $ranges = join("", map({/\A([0-9a-fA-F]+)(?:-([0-9a-fA-F]+))?\z/u or die "widen: ${spec}: bad range\n"; defined $2 ? "\\x{$1}-\\x{$2}" : "\\x{$1}";} split(/:/u, $spec, 0))); qr/[$ranges]/u }
Truth table100%3/3
A //= B
A= $class{$spec}B= do { my $ranges = join("", map({/\A([0-9a-fA-F]+)(?:-([0-9a-fA-F]+))?\z/u or die "widen: ${spec}: bad range\n"; defined $2 ? "\\x{$1}-\\x{$2}" : "\\x{$1}";} split(/:/u, $spec, 0))); qr/[$ranges]/u }
ABresult
1X1
011
000
84 my $ranges = join '', map {
85 8 ▶ /\A([0-9a-fA-F]+)(?:-([0-9a-fA-F]+))?\z/ or die "widen: $spec: bad range\n";
Branch: 1 branch
BranchTrueFalseTotal
/\A([0-9a-fA-F]+)(?:-([0-9a-fA-F]+))?\z/u or die "widen: ${spec}: bad range\n" 10 1 11
86 10 ▶ defined $2 ? "\\x{$1}-\\x{$2}" : "\\x{$1}";
Branch: 1 branch
BranchTrueFalseTotal
defined $2 ? : 4 6 10
87 } split /:/, $spec;
88 7 qr/[$ranges]/;
89 };
90 }
91  
92 31 ▶sub widen {
Subroutine widen: called CC=2 SCAR=6.9
Pod undocumented
93 31 my %arg = @_;
94 31 ▶ my $class = class($arg{chars} // '2460-24FF:1F5D1');
Condition100%2/2
$arg{"chars"} // "2460-24FF:1F5D1"
l!l
292
MC/DC100%1/1
$arg{"chars"} // "2460-24FF:1F5D1"
$arg{"chars"}
Truth table100%2/2
A
A= $arg{"chars"}
Aresult
11
00
95 30 s{ $SKIP | (?<char> $class [\x{FE0E}\x{FE0F}]?+ ) (?!\x{A0}) }{$+{char}\x{A0}}xmg;
96 }
97  
98 4 1;
« blib/lib/App/Greple/md.pm ↑ Summary blib/lib/App/mdee.pm »