| 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
| |||||||||||||||
| 32 | 0 | my $fence = '`' x $len; | |||||||||||||
| 33 | 0 | ▶ | "$fence$lang\n$text" . ($text =~ /\n\z/ ? '' : "\n") . "$fence\n"; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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)
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))
| |||||||||||||||
| 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
| |||||||||||||||
| 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; | |||||||||||||