line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Pandoc::Filter; |
2
|
7
|
|
|
7
|
|
257699
|
use strict; |
|
7
|
|
|
|
|
54
|
|
|
7
|
|
|
|
|
232
|
|
3
|
7
|
|
|
7
|
|
47
|
use warnings; |
|
7
|
|
|
|
|
19
|
|
|
7
|
|
|
|
|
204
|
|
4
|
7
|
|
|
7
|
|
145
|
use 5.010; |
|
7
|
|
|
|
|
29
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.34'; |
7
|
|
|
|
|
|
|
|
8
|
7
|
|
|
7
|
|
2738
|
use JSON; |
|
7
|
|
|
|
|
59239
|
|
|
7
|
|
|
|
|
53
|
|
9
|
7
|
|
|
7
|
|
1119
|
use Carp; |
|
7
|
|
|
|
|
18
|
|
|
7
|
|
|
|
|
485
|
|
10
|
7
|
|
|
7
|
|
55
|
use Scalar::Util 'reftype'; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
371
|
|
11
|
7
|
|
|
7
|
|
54
|
use List::Util; |
|
7
|
|
|
|
|
17
|
|
|
7
|
|
|
|
|
515
|
|
12
|
7
|
|
|
7
|
|
1486
|
use Pandoc::Walker; |
|
7
|
|
|
|
|
21
|
|
|
7
|
|
|
|
|
481
|
|
13
|
7
|
|
|
7
|
|
2365
|
use Pandoc::Elements qw(Image Str); |
|
7
|
|
|
|
|
30
|
|
|
7
|
|
|
|
|
936
|
|
14
|
|
|
|
|
|
|
|
15
|
7
|
|
|
7
|
|
61
|
use parent 'Exporter'; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
66
|
|
16
|
|
|
|
|
|
|
our @EXPORT = qw(pandoc_filter pandoc_filter_document pandoc_walk); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# FUNCTIONS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub pandoc_walk(@) { ## no critic |
21
|
3
|
|
|
3
|
0
|
990
|
my $filter = Pandoc::Filter->new(@_); |
22
|
3
|
|
|
|
|
34
|
my $ast = Pandoc::Elements::pandoc_json(); |
23
|
3
|
|
|
2
|
|
87
|
binmode STDOUT, ':encoding(UTF-8)'; |
|
2
|
|
|
|
|
18
|
|
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
16
|
|
24
|
3
|
50
|
|
|
|
16282
|
$filter->apply( $ast->content, @ARGV ? $ARGV[0] : '', $ast->meta ); |
25
|
3
|
|
|
|
|
36
|
return $ast; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _pod2usage_if_help { |
29
|
2
|
|
|
2
|
|
844
|
require Getopt::Long; |
30
|
2
|
|
|
|
|
13440
|
my %opt; |
31
|
2
|
|
|
|
|
10
|
Getopt::Long::GetOptions(\%opt, 'help|?'); |
32
|
2
|
50
|
|
|
|
327
|
return unless $opt{help}; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
## no critic |
35
|
0
|
0
|
|
|
|
0
|
my $module = -t STDOUT ? 'Pod::Text::Termcap' : 'Pod::Text'; |
36
|
0
|
0
|
|
|
|
0
|
eval "require $module" or die "Can't locate $module in \@INC\n"; |
37
|
0
|
|
|
|
|
0
|
$module->new( indent => 2, nourls => 1 )->parse_file($0); |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
0
|
exit; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub pandoc_filter(@) { ## no critic |
43
|
2
|
|
|
2
|
1
|
2405
|
_pod2usage_if_help(); |
44
|
|
|
|
|
|
|
|
45
|
2
|
|
|
|
|
9
|
my $ast = pandoc_walk(@_); # implies binmode STDOUT UTF-8 |
46
|
2
|
|
|
|
|
59
|
my $json = JSON->new->allow_blessed->convert_blessed->encode($ast); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
#my $json = $ast->to_json; # does not want binmode STDOUT UTF-8 |
49
|
2
|
|
|
|
|
148
|
say STDOUT $json; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub pandoc_filter_document($) { ## no critic |
53
|
0
|
|
|
0
|
0
|
0
|
_pod2usage_if_help(); |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
0
|
my $filter = shift; |
56
|
0
|
|
|
|
|
0
|
my $doc = Pandoc::Elements::pandoc_json(); |
57
|
0
|
|
|
|
|
0
|
$filter->apply( $doc, $ARGV[0] ); |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
0
|
say $doc->to_json; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# METHODS |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub new { |
65
|
10
|
|
|
10
|
1
|
3185
|
my $class = shift; |
66
|
10
|
100
|
66
|
|
|
119
|
my $action = (@_ < 2 or @_ % 2 or ref $_[0]) |
67
|
|
|
|
|
|
|
? Pandoc::Walker::action(@_) # @actions |
68
|
|
|
|
|
|
|
: Pandoc::Walker::action({ @_ }); # %actions |
69
|
10
|
|
|
|
|
107
|
bless { |
70
|
|
|
|
|
|
|
action => $action, |
71
|
|
|
|
|
|
|
error => '', |
72
|
|
|
|
|
|
|
}, $class; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub action { |
76
|
11
|
|
|
11
|
1
|
84
|
$_[0]->{action}; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub apply { |
80
|
10
|
|
|
10
|
1
|
45
|
my ( $self, $ast, $format, $meta ) = @_; |
81
|
10
|
|
100
|
|
|
68
|
$format ||= ''; |
82
|
10
|
|
100
|
|
|
49
|
$meta ||= eval { $ast->meta } || {}; |
|
|
|
66
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
10
|
|
|
|
|
42
|
Pandoc::Walker::transform( $ast, $self->action, $format, $meta ); |
85
|
|
|
|
|
|
|
|
86
|
10
|
|
|
|
|
58
|
$ast; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
__END__ |