| 1 | package Text::ANSI::Highlight::sourcehighlight; | ||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||
| 7 | # source-highlight of GNU. Its style esc is the colors that less | ||||||||||||||||||||||||||||
| 8 | # shows by its lesspipe. The style and the language are given after | ||||||||||||||||||||||||||||
| 9 | # it (--style-file and -s). | ||||||||||||||||||||||||||||
| 10 | 1 | our @COMMAND = qw(source-highlight -f esc); | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | # The style: the name of a style file of source-highlight without | ||||||||||||||||||||||||||||
| 13 | # .style (esc, esc256, default), or a style file. Set by | ||||||||||||||||||||||||||||
| 14 | # Text::ANSI::Highlight for a call. | ||||||||||||||||||||||||||||
| 15 | 1 | our $STYLE; | |||||||||||||||||||||||||||
| 16 | 1 | our $DEFAULT_STYLE = 'esc'; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | sub style_option { | ||||||||||||||||||||||||||
|
Subroutine
style_option: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 19 | 0 | ▶ | my $style = $STYLE // $DEFAULT_STYLE; | ||||||||||||||||||||||||||
|
Condition0%0/3
$Text::ANSI::Highlight::sourcehighlight::STYLE // $Text::ANSI::Highlight::sourcehighlight::DEFAULT_STYLE
MC/DC0%0/2
$Text::ANSI::Highlight::sourcehighlight::STYLE // $Text::ANSI::Highlight::sourcehighlight::DEFAULT_STYLE
$Text::ANSI::Highlight::sourcehighlight::STYLE
$Text::ANSI::Highlight::sourcehighlight::DEFAULT_STYLE
Truth table0%0/3
A // B
A= $Text::ANSI::Highlight::sourcehighlight::STYLEB= $Text::ANSI::Highlight::sourcehighlight::DEFAULT_STYLE
| |||||||||||||||||||||||||||||
| 20 | 0 | ▶ | $style .= '.style' unless $style =~ m{[/.]} or -f $style; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$style =~ m[[/.]]u or -f $style
MC/DC0%0/2
$style =~ m[[/.]]u or -f $style
$style =~ m[[/.]]u
-f $style
Truth table0%0/3
A or B
A= $style =~ m[[/.]]uB= -f $style
| |||||||||||||||||||||||||||||
| 21 | 0 | "--style-file=$style"; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | # The languages, and the extensions of the files, that the command | ||||||||||||||||||||||||||||
| 25 | # knows (source-highlight --lang-list) | ||||||||||||||||||||||||||||
| 26 | 1 | my $language; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | sub language { | ||||||||||||||||||||||||||
|
Subroutine
language: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 29 | 0 | ▶ | $language //= do { | ||||||||||||||||||||||||||
|
Condition0%0/3
$language //= do {
my $list = Text::ANSI::Highlight::run([$Text::ANSI::Highlight::sourcehighlight::COMMAND[0], "--lang-list"], "") // "";
+{map({/^(\S+) = (\S+)\.lang$/u && $2 ne "nohilite" ? ($1, 1) : ();} split(/\n/u, $list, 0))}
}
MC/DC0%0/2
$language //= do {
my $list = Text::ANSI::Highlight::run([$Text::ANSI::Highlight::sourcehighlight::COMMAND[0], "--lang-list"], "") // "";
+{map({/^(\S+) = (\S+)\.lang$/u && $2 ne "nohilite" ? ($1, 1) : ();} split(/\n/u, $list, 0))}
}
$language
do {
my $list = Text::ANSI::Highlight::run([$Text::ANSI::Highlight::sourcehighlight::COMMAND[0], "--lang-list"], "") // "";
+{map({/^(\S+) = (\S+)\.lang$/u && $2 ne "nohilite" ? ($1, 1) : ();} split(/\n/u, $list, 0))}
}
Truth table0%0/3
A //= B
A= $languageB= do {
my $list = Text::ANSI::Highlight::run([$Text::ANSI::Highlight::sourcehighlight::COMMAND[0], "--lang-list"], "") // "";
+{map({/^(\S+) = (\S+)\.lang$/u && $2 ne "nohilite" ? ($1, 1) : ();} split(/\n/u, $list, 0))}
}
| |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | my $list = Text::ANSI::Highlight::run([ $COMMAND[0], '--lang-list' ], '') // ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
Text::ANSI::Highlight::run([$Text::ANSI::Highlight::sourcehighlight::COMMAND[0], "--lang-list"], "") // ""
MC/DC0%0/1
Text::ANSI::Highlight::run([$Text::ANSI::Highlight::sourcehighlight::COMMAND[0], "--lang-list"], "") // ""
Text::ANSI::Highlight::run([$Text::ANSI::Highlight::sourcehighlight::COMMAND[0], "--lang-list"], "")
Truth table0%0/2
A
A= Text::ANSI::Highlight::run([$Text::ANSI::Highlight::sourcehighlight::COMMAND[0], "--lang-list"], "")
| |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | +{ map { /^(\S+) = (\S+)\.lang$/ && $2 ne 'nohilite' ? ($1 => 1) : () } split /\n/, $list }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
/^(\S+) = (\S+)\.lang$/u and $2 ne "nohilite"
MC/DC0%0/2
/^(\S+) = (\S+)\.lang$/u and $2 ne "nohilite"
/^(\S+) = (\S+)\.lang$/u
$2 ne "nohilite"
Truth table0%0/3
A and B
A= /^(\S+) = (\S+)\.lang$/uB= $2 ne "nohilite"
| |||||||||||||||||||||||||||||
| 32 | }; | ||||||||||||||||||||||||||||
| 33 | 0 | ▶ | $language->{$_[0]} ? $_[0] : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # It has no definition of Markdown: the text around the code of a | ||||||||||||||||||||||||||||
| 37 | # Markdown text is left as it is. | ||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub markdown { 0 } | ||||||||||||||||||||||||||
|
Subroutine
markdown: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | # The command runs once for each text. | ||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub highlight { | ||||||||||||||||||||||||||
|
Subroutine
highlight: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 42 | map { | ||||||||||||||||||||||||||||
| 43 | 0 | my($lang, $text) = @$_; | |||||||||||||||||||||||||||
| 44 | 0 | Text::ANSI::Highlight::run([ @COMMAND, style_option(), '-s', $lang ], $text); | |||||||||||||||||||||||||||
| 45 | } @_; | ||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 1 | 1; | |||||||||||||||||||||||||||