Highlight/pandoc.pm

filter: Statementstmt 43.5% 17 / 39 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 57.1% 4 / 7 Podpod 0.0% 0 / 3 totaltotal 32.3% 21 / 65 CC 9 SCAR 31.1
CC
9
Cov
32%
highlight
42.0
run
20.0
markdown
2.0
CRAP 22.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 style: the name of one of pandoc (pygments, haddock, ...), or a
19 # theme file of KDE. Set by Text::ANSI::Highlight for a call. Without
20 # it, pandoc uses its default, pygments.
21 #
22 # The option is --syntax-highlighting in a new pandoc, and
23 # --highlight-style in an older one, which a new one still takes with a
24 # warning. The one which worked is used again.
25 1 our $STYLE;
26 1 my @STYLE_OPTION = qw(--syntax-highlighting --highlight-style);
27  
28 0 ▶sub run {
Subroutine run: not called CC=4 SCAR=30.0
Pod undocumented
29 0 my $input = shift;
30 0 ▶ defined $STYLE
Branch: 1 branch
BranchTrueFalseTotal
defined $Text::ANSI::Highlight::pandoc::STYLE or return Text::ANSI::Highlight::run(\@Text::ANSI::Highlight::pandoc::COMMAND, $input) 0 0 0
31 or return Text::ANSI::Highlight::run(\@COMMAND, $input);
32 0 for my $option (@STYLE_OPTION) {
33 0 ▶ my $out = Text::ANSI::Highlight::run(
Condition0%0/2
Text::ANSI::Highlight::run([@Text::ANSI::Highlight::pandoc::COMMAND, "$option=$Text::ANSI::Highlight::pandoc::STYLE"], $input) // (next)
l!l
00
MC/DC0%0/1
Text::ANSI::Highlight::run([@Text::ANSI::Highlight::pandoc::COMMAND, "$option=$Text::ANSI::Highlight::pandoc::STYLE"], $input) // (next)
Text::ANSI::Highlight::run([@Text::ANSI::Highlight::pandoc::COMMAND, "$option=$Text::ANSI::Highlight::pandoc::STYLE"], $input)
Truth table0%0/2
A
A= Text::ANSI::Highlight::run([@Text::ANSI::Highlight::pandoc::COMMAND, "$option=$Text::ANSI::Highlight::pandoc::STYLE"], $input)
Aresult
11
00
34 [ @COMMAND, "$option=$STYLE" ], $input) // next;
35 0 @STYLE_OPTION = ($option);
36 0 return $out;
37 }
38 0 undef;
39 }
40  
41 # The paragraph between the code blocks. A line of the code never
42 # looks like this in what pandoc writes: the code is indented.
43 1 my $SEPARATOR = 'TextANSIHighlightPandocSeparator';
44  
45 # All the texts are given to pandoc at once, each in a fence of its
46 # own. pandoc reads the fences by its parser of Markdown, so the code
47 # of one fence has nothing to do with that of the next.
48 0 ▶sub highlight {
Subroutine highlight: not called CC=6 SCAR=37.4
Pod undocumented
49 0 my @code = @_;
50 my @block = map {
51 0 my($lang, $text) = @$_;
52 # a fence longer than any in the text
53 0 my $len = 3;
54 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
55 0 my $fence = '`' x $len;
56 0 ▶ "$fence$lang\n$text" . ($text =~ /\n\z/ ? '' : "\n") . "$fence\n";
Branch: 1 branch
BranchTrueFalseTotal
$text =~ /\n\z/u ? : 0 0 0
57 } @code;
58 0 my @none = (undef) x @code;
59 0 ▶ my $out = run(join "\n$SEPARATOR\n\n", @block) // return @none;
Condition0%0/2
run(join("\n$SEPARATOR\n\n", @block)) // (return @none)
l!l
00
MC/DC0%0/1
run(join("\n$SEPARATOR\n\n", @block)) // (return @none)
run(join("\n$SEPARATOR\n\n", @block))
Truth table0%0/2
A
A= run(join("\n$SEPARATOR\n\n", @block))
Aresult
11
00
60 # the end of a hyperlink, which pandoc puts at the end
61 0 $out =~ s/\e\]8;;\e\\//g;
62 0 my @out = split /^\Q$SEPARATOR\E\n/m, $out, -1;
63 0 ▶ @out == @block or return @none;
Branch: 1 branch
BranchTrueFalseTotal
@out == @block or return @none 0 0 0
64 # the code is indented by four columns
65 0 map { Text::ANSI::Highlight::skylighting::clean(s/^ {4}//mgr) } @out;
66 }
67  
68 1 1;
« Highlight/sourcehighlight.pm ↑ Summary Highlight/skylighting.pm »