Highlight/pandoc.pm

filter: Statementstmt 50.0% 15 / 30 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 66.6% 4 / 6 Podpod 0.0% 0 / 2 totaltotal 38.7% 19 / 49 CC 6 SCAR 31.6
CC
6
Cov
38%
highlight
42.0
markdown
2.0
BEGIN
1.0
CRAP 23.5
« Highlight/sourcehighlight.pm ↑ Summary Highlight/skylighting.pm »
1 package Text::ANSI::Highlight::pandoc;
2  
3 1 ▶use v5.16;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Text::ANSI::Highlight ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Text::ANSI::Highlight::skylighting ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # pandoc reads a Markdown text which has the code in fences, and writes
9 # it for the terminal, with the code in the colors of its language.
10 # It has skylighting in it, and does not run the command.
11 1 our @COMMAND = qw(pandoc -f markdown -t ansi --wrap=none --preserve-tabs);
12  
13 # The languages are those of skylighting
14 1 *language = \&Text::ANSI::Highlight::skylighting::language;
15  
16 0 ▶sub markdown { 1 }
Subroutine markdown: not called CC=1 SCAR=6.9
Pod undocumented
17  
18 # The paragraph between the code blocks. A line of the code never
19 # looks like this in what pandoc writes: the code is indented.
20 1 my $SEPARATOR = 'TextANSIHighlightPandocSeparator';
21  
22 # All the texts are given to pandoc at once, each in a fence of its
23 # own. pandoc reads the fences by its parser of Markdown, so the code
24 # of one fence has nothing to do with that of the next.
25 0 ▶sub highlight {
Subroutine highlight: not called CC=6 SCAR=37.4
Pod undocumented
26 0 my @code = @_;
27 my @block = map {
28 0 my($lang, $text) = @$_;
29 # a fence longer than any in the text
30 0 my $len = 3;
31 0 ▶ $len < length($1) + 1 and $len = length($1) + 1 while $text =~ /(`{3,})/g;
Branch: 2 branches
BranchTrueFalseTotal
$text =~ /(`{3,})/gu and do { $len < length($1) + 1 and $len = length($1) + 1 } 0 0 0
$len < length($1) + 1 and $len = length($1) + 1 0 0 0
32 0 my $fence = '`' x $len;
33 0 ▶ "$fence$lang\n$text" . ($text =~ /\n\z/ ? '' : "\n") . "$fence\n";
Branch: 1 branch
BranchTrueFalseTotal
$text =~ /\n\z/u ? : 0 0 0
34 } @code;
35 0 my @none = (undef) x @code;
36 0 ▶ my $out = Text::ANSI::Highlight::run(\@COMMAND, join "\n$SEPARATOR\n\n", @block)
Condition0%0/2
Text::ANSI::Highlight::run(\@COMMAND, join("\n$SEPARATOR\n\n", @block)) // (return @none)
l!l
00
MC/DC0%0/1
Text::ANSI::Highlight::run(\@COMMAND, join("\n$SEPARATOR\n\n", @block)) // (return @none)
Text::ANSI::Highlight::run(\@COMMAND, join("\n$SEPARATOR\n\n", @block))
Truth table0%0/2
A
A= Text::ANSI::Highlight::run(\@COMMAND, join("\n$SEPARATOR\n\n", @block))
Aresult
11
00
37 // return @none;
38 # the end of a hyperlink, which pandoc puts at the end
39 0 $out =~ s/\e\]8;;\e\\//g;
40 0 my @out = split /^\Q$SEPARATOR\E\n/m, $out, -1;
41 0 ▶ @out == @block or return @none;
Branch: 1 branch
BranchTrueFalseTotal
@out == @block or return @none 0 0 0
42 # the code is indented by four columns
43 0 map { Text::ANSI::Highlight::skylighting::clean(s/^ {4}//mgr) } @out;
44 }
45  
46 1 1;
« Highlight/sourcehighlight.pm ↑ Summary Highlight/skylighting.pm »