| 1 | package Text::ANSI::Highlight::Block::embedz; | ||||||||||||||||||||||||||||
| 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 utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # The parts of a block of pandoc-embedz, each with its language: | ||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||
| 9 | # --- | ||||||||||||||||||||||||||||
| 10 | # YAML | ||||||||||||||||||||||||||||
| 11 | # --- | ||||||||||||||||||||||||||||
| 12 | # template of Jinja2 | ||||||||||||||||||||||||||||
| 13 | # --- | ||||||||||||||||||||||||||||
| 14 | # data | ||||||||||||||||||||||||||||
| 15 | # | ||||||||||||||||||||||||||||
| 16 | # A block without the line of --- at the top is one part, and what it | ||||||||||||||||||||||||||||
| 17 | # is depends on the attributes of the fence. | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # the formats of the data which are the names of a language. CSV is | ||||||||||||||||||||||||||||
| 20 | # not here: its colors, one for each column, mean nothing in the data | ||||||||||||||||||||||||||||
| 21 | 1 | my %FORMAT = map { $_ => $_ } qw(json yaml toml); | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 19 | ▶ | sub parts { | ||||||||||||||||||||||||||
|
Subroutine
parts: called CC=19 SCAR=29.4
Pod
documented
| |||||||||||||||||||||||||||||
| 24 | 19 | my($info, $text) = @_; | |||||||||||||||||||||||||||
| 25 | 19 | ▶ | $text ne '' or return (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 18 | my %attr = map { $_ => 1 } $info =~ /(?<![\w.])([\w.-]+)=/g; | |||||||||||||||||||||||||||
| 27 | 18 | ▶ | my $format = $info =~ /(?<![\w.])format=["']?(\w+)/ ? $1 : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 18 | ▶ | my $as = $attr{as} || $attr{template}; | ||||||||||||||||||||||||||
|
Condition100%3/3
$attr{'as'} || $attr{'template'}
MC/DC100%2/2
$attr{'as'} || $attr{'template'}
$attr{'as'}
$attr{'template'}
Truth table100%3/3
A || B
A= $attr{'as'}B= $attr{'template'}
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 18 | ▶ | if ($text !~ /\A---/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 9 | ▶ | return [ jinja => $text, 'template' ] if $attr{define}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 8 | ▶ | return [ yaml => $text, 'config' ] if $as and $attr{data}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$as and $attr{"data"}
MC/DC100%2/2
$as and $attr{"data"}
$as
$attr{"data"}
Truth table100%3/3
A and B
A= $asB= $attr{"data"}
| |||||||||||||||||||||||||||||
| 33 | 6 | ▶ | return [ _data($format) => $text, 'data' ] if $as; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 3 | return [ jinja => $text, 'template' ]; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | # the lines of --- and the sections between them: the third and | ||||||||||||||||||||||||||||
| 38 | # the following are in the data | ||||||||||||||||||||||||||||
| 39 | 9 | my @line = split /^/, $text; | |||||||||||||||||||||||||||
| 40 | 9 | my @part = ([ undef, shift @line ]); | |||||||||||||||||||||||||||
| 41 | 9 | my @section = (''); | |||||||||||||||||||||||||||
| 42 | 9 | ▶ | while (defined(my $line = shift @line)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 55 | ▶ | if (@section < 5 and $line =~ /\A\h*---\h*$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@section < 5 and $line =~ /\A\h*---\h*$/u
MC/DC100%2/2
@section < 5 and $line =~ /\A\h*---\h*$/u
@section < 5
$line =~ /\A\h*---\h*$/u
Truth table100%3/3
A and B
A= @section < 5B= $line =~ /\A\h*---\h*$/u
| |||||||||||||||||||||||||||||
| 44 | 13 | push @section, $line, ''; | |||||||||||||||||||||||||||
| 45 | } else { | ||||||||||||||||||||||||||||
| 46 | 42 | $section[-1] .= $line; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | 9 | my($yaml, $sep1, $template, $sep2, $data) = @section; | |||||||||||||||||||||||||||
| 50 | 9 | ▶ | $format //= $1 if $yaml =~ /^format:\h*["']?(\w+)/m; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$format //= $1
MC/DC0%0/2
$format //= $1
$format
$1
Truth table33%1/3
A //= B
A= $formatB= $1
| |||||||||||||||||||||||||||||
| 51 | 9 | ▶ | $as ||= $yaml =~ /^(?:as|template):/m; | ||||||||||||||||||||||||||
|
Condition100%3/3
$as ||= $yaml =~ /^(?:as|template):/mu
MC/DC100%2/2
$as ||= $yaml =~ /^(?:as|template):/mu
$as
$yaml =~ /^(?:as|template):/mu
Truth table100%3/3
A ||= B
A= $asB= $yaml =~ /^(?:as|template):/mu
| |||||||||||||||||||||||||||||
| 52 | # the section after YAML is the data when a template is used | ||||||||||||||||||||||||||||
| 53 | 9 | ▶ | my @middle = ($as and not defined $sep2) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$as and not defined $sep2
MC/DC100%2/2
$as and not defined $sep2
$as
not defined $sep2
Truth table100%3/3
A and not(B)
A= $asB= not defined $sep2
| |||||||||||||||||||||||||||||
| 54 | ? (_data($format), 'data') : ('jinja', 'template'); | ||||||||||||||||||||||||||||
| 55 | 9 | ▶ | push @part, | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 56 | [ yaml => $yaml, 'config' ], | ||||||||||||||||||||||||||||
| 57 | defined $sep1 ? ([ undef, $sep1 ], [ $middle[0], $template, $middle[1] ]) : (), | ||||||||||||||||||||||||||||
| 58 | defined $sep2 ? ([ undef, $sep2 ], [ _data($format), $data, 'data' ]) : (); | ||||||||||||||||||||||||||||
| 59 | 9 | grep { $_->[1] ne '' } @part; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 9 | ▶ | sub _data { | ||||||||||||||||||||||||||
|
Subroutine
_data: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 63 | 9 | ▶ | my $format = shift // return undef; | ||||||||||||||||||||||||||
|
Condition100%2/2
shift() // (return undef)
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 64 | 5 | $FORMAT{lc $format}; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 1 | 1; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | __END__ | ||||||||||||||||||||||||||||