| 1 | package Text::ANSI::Highlight::skylighting; | ||||||||||||||||||||
| 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 | # skylighting, the highlighter of pandoc, as a command, with the 16 | ||||||||||||||||||||
| 8 | # colors of the terminal. The style and the language are given after | ||||||||||||||||||||
| 9 | # it (-S or -t, and -s). | ||||||||||||||||||||
| 10 | 1 | our @COMMAND = qw(skylighting -f ansi -r -C 16); | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | # The style: the name of one of skylighting (pygments, haddock, ...), | ||||||||||||||||||||
| 13 | # or a theme file of KDE. Set by Text::ANSI::Highlight for a call. | ||||||||||||||||||||
| 14 | 1 | our $STYLE; | |||||||||||||||||||
| 15 | 1 | our $DEFAULT_STYLE = 'pygments'; | |||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | # A style is a file when it has a slash or a dot, or is one | ||||||||||||||||||||
| 18 | 0 | ▶ | sub style_is_file { $_[0] =~ m{[/.]} or -f $_[0] } | ||||||||||||||||||
|
Subroutine
style_is_file: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 0 | ▶ | sub style_option { | ||||||||||||||||||
|
Subroutine
style_option: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||
| 21 | 0 | ▶ | my $style = $STYLE // $DEFAULT_STYLE; | ||||||||||||||||||
|
Condition0%0/3
$Text::ANSI::Highlight::skylighting::STYLE // $Text::ANSI::Highlight::skylighting::DEFAULT_STYLE
MC/DC0%0/2
$Text::ANSI::Highlight::skylighting::STYLE // $Text::ANSI::Highlight::skylighting::DEFAULT_STYLE
$Text::ANSI::Highlight::skylighting::STYLE
$Text::ANSI::Highlight::skylighting::DEFAULT_STYLE
Truth table0%0/3
A // B
A= $Text::ANSI::Highlight::skylighting::STYLEB= $Text::ANSI::Highlight::skylighting::DEFAULT_STYLE
| |||||||||||||||||||||
| 22 | 0 | ▶ | style_is_file($style) ? ('-t', $style) : ('-S', $style); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 23 | } | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | # The languages of skylighting 0.15 (pandoc --list-highlight-languages, | ||||||||||||||||||||
| 26 | # pandoc 3.14). A language is given to the command only when it is | ||||||||||||||||||||
| 27 | # here: the command takes time to look for one it does not know. | ||||||||||||||||||||
| 28 | 1 | my %LANGUAGE = map { $_ => 1 } qw( | |||||||||||||||||||
| 29 | abc abnf actionscript ada agda apache asciidoc asn1 asp ats awk bash | ||||||||||||||||||||
| 30 | bibtex boo c cabal changelog clojure cmake cobol coffee coldfusion | ||||||||||||||||||||
| 31 | comments commonlisp context cpp crystal cs css csv curry d dart | ||||||||||||||||||||
| 32 | debiancontrol default desktop diff djangotemplate dockerfile dosbat | ||||||||||||||||||||
| 33 | dot doxygen doxygenlua dtd eiffel elixir elixireex elixirheex elm | ||||||||||||||||||||
| 34 | email erlang fasm fortranfixed fortranfree fsharp gap gcc gdscript | ||||||||||||||||||||
| 35 | gleam glsl gnuassembler go gpr graphql groovy haml hamlet haskell | ||||||||||||||||||||
| 36 | haxe html idl idris ini isocpp j java javadoc javascript | ||||||||||||||||||||
| 37 | javascriptreact jinja jira json jsp julia k kotlin latex lex | ||||||||||||||||||||
| 38 | lilypond literatecurry literatehaskell llvm logfile lua m4 makefile | ||||||||||||||||||||
| 39 | mandoc mathematica matlab maxima mediawiki mermaid meson metafont | ||||||||||||||||||||
| 40 | mips modelines modula2 modula3 monobasic mustache nasm nginx nim | ||||||||||||||||||||
| 41 | ninja nix noweb objectivec objectivecpp ocaml ocamllex ocamlyacc | ||||||||||||||||||||
| 42 | octave odin opencl orgmode pascal perl php pike postscript povray | ||||||||||||||||||||
| 43 | powershell prolog protobuf pure purebasic purescript python q qml | ||||||||||||||||||||
| 44 | quarto r racket raku rdoc relaxng relaxngcompact rest rhtml | ||||||||||||||||||||
| 45 | rmarkdown roff rtf ruby rust sas sass scala scheme sci scss sed sgml | ||||||||||||||||||||
| 46 | sml sparql spdxcomments sql sqlmysql sqlpostgresql stan stata swift | ||||||||||||||||||||
| 47 | systemverilog tcl tcsh terraform texinfo textile tlaplus todo toml | ||||||||||||||||||||
| 48 | typescript typst verilog vhdl vue xml xorg xslt xul yacc yaml zig | ||||||||||||||||||||
| 49 | zsh | ||||||||||||||||||||
| 50 | ); | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 0 | ▶ | sub language { $LANGUAGE{$_[0]} ? $_[0] : undef } | ||||||||||||||||||
|
Subroutine
language: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | # The text around the code of a Markdown text is colored | ||||||||||||||||||||
| 55 | 0 | ▶ | sub markdown { 1 } | ||||||||||||||||||
|
Subroutine
markdown: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | # The sequences of skylighting which do nothing: \e[22;23;24m after | ||||||||||||||||||||
| 58 | # every reset, and a reset where there is no color to reset, at the | ||||||||||||||||||||
| 59 | # top of a line or after another reset, with text between them or not. | ||||||||||||||||||||
| 60 | # skylighting resets after every word, colored or not. | ||||||||||||||||||||
| 61 | 0 | ▶ | sub clean { | ||||||||||||||||||
|
Subroutine
clean: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 62 | 0 | local $_ = shift; | |||||||||||||||||||
| 63 | 0 | s/\e\[0m\K\e\[22;23;24m//g; | |||||||||||||||||||
| 64 | 0 | ▶ | 1 while s/(?:^|\e\[0m)[^\e\n]*\K\e\[0m//mg; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 65 | 0 | $_; | |||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | # The command runs once for each text. | ||||||||||||||||||||
| 69 | 0 | ▶ | sub highlight { | ||||||||||||||||||
|
Subroutine
highlight: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 70 | map { | ||||||||||||||||||||
| 71 | 0 | my($lang, $text) = @$_; | |||||||||||||||||||
| 72 | 0 | my $out = Text::ANSI::Highlight::run( | |||||||||||||||||||
| 73 | [ @COMMAND, style_option(), '-s', $lang ], $text); | ||||||||||||||||||||
| 74 | 0 | ▶ | defined $out ? clean($out) : undef; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 75 | } @_; | ||||||||||||||||||||
| 76 | } | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 1 | 1; | |||||||||||||||||||