line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Pandoc::Filter; |
2
|
7
|
|
|
7
|
|
239197
|
use strict; |
|
7
|
|
|
|
|
46
|
|
|
7
|
|
|
|
|
256
|
|
3
|
7
|
|
|
7
|
|
44
|
use warnings; |
|
7
|
|
|
|
|
18
|
|
|
7
|
|
|
|
|
209
|
|
4
|
7
|
|
|
7
|
|
160
|
use 5.010; |
|
7
|
|
|
|
|
24
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.34'; |
7
|
|
|
|
|
|
|
|
8
|
7
|
|
|
7
|
|
2796
|
use JSON; |
|
7
|
|
|
|
|
53452
|
|
|
7
|
|
|
|
|
64
|
|
9
|
7
|
|
|
7
|
|
1179
|
use Carp; |
|
7
|
|
|
|
|
18
|
|
|
7
|
|
|
|
|
525
|
|
10
|
7
|
|
|
7
|
|
56
|
use Scalar::Util 'reftype'; |
|
7
|
|
|
|
|
18
|
|
|
7
|
|
|
|
|
402
|
|
11
|
7
|
|
|
7
|
|
51
|
use List::Util; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
513
|
|
12
|
7
|
|
|
7
|
|
1505
|
use Pandoc::Walker; |
|
7
|
|
|
|
|
20
|
|
|
7
|
|
|
|
|
462
|
|
13
|
7
|
|
|
7
|
|
2331
|
use Pandoc::Elements qw(Image Str); |
|
7
|
|
|
|
|
29
|
|
|
7
|
|
|
|
|
977
|
|
14
|
|
|
|
|
|
|
|
15
|
7
|
|
|
7
|
|
62
|
use parent 'Exporter'; |
|
7
|
|
|
|
|
18
|
|
|
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
|
1071
|
my $filter = Pandoc::Filter->new(@_); |
22
|
3
|
|
|
|
|
44
|
my $ast = Pandoc::Elements::pandoc_json(); |
23
|
3
|
|
|
2
|
|
96
|
binmode STDOUT, ':encoding(UTF-8)'; |
|
2
|
|
|
|
|
18
|
|
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
14
|
|
24
|
3
|
50
|
|
|
|
14890
|
$filter->apply( $ast->content, @ARGV ? $ARGV[0] : '', $ast->meta ); |
25
|
3
|
|
|
|
|
34
|
return $ast; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _pod2usage_if_help { |
29
|
2
|
|
|
2
|
|
941
|
require Getopt::Long; |
30
|
2
|
|
|
|
|
16301
|
my %opt; |
31
|
2
|
|
|
|
|
13
|
Getopt::Long::GetOptions(\%opt, 'help|?'); |
32
|
2
|
50
|
|
|
|
411
|
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
|
2747
|
_pod2usage_if_help(); |
44
|
|
|
|
|
|
|
|
45
|
2
|
|
|
|
|
11
|
my $ast = pandoc_walk(@_); # implies binmode STDOUT UTF-8 |
46
|
2
|
|
|
|
|
84
|
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
|
|
|
|
|
246
|
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
|
2660
|
my $class = shift; |
66
|
10
|
100
|
66
|
|
|
158
|
my $action = (@_ < 2 or @_ % 2 or ref $_[0]) |
67
|
|
|
|
|
|
|
? Pandoc::Walker::action(@_) # @actions |
68
|
|
|
|
|
|
|
: Pandoc::Walker::action({ @_ }); # %actions |
69
|
10
|
|
|
|
|
77
|
bless { |
70
|
|
|
|
|
|
|
action => $action, |
71
|
|
|
|
|
|
|
error => '', |
72
|
|
|
|
|
|
|
}, $class; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub action { |
76
|
11
|
|
|
11
|
1
|
83
|
$_[0]->{action}; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub apply { |
80
|
10
|
|
|
10
|
1
|
46
|
my ( $self, $ast, $format, $meta ) = @_; |
81
|
10
|
|
100
|
|
|
69
|
$format ||= ''; |
82
|
10
|
|
100
|
|
|
48
|
$meta ||= eval { $ast->meta } || {}; |
|
|
|
66
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
10
|
|
|
|
|
45
|
Pandoc::Walker::transform( $ast, $self->action, $format, $meta ); |
85
|
|
|
|
|
|
|
|
86
|
10
|
|
|
|
|
68
|
$ast; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
__END__ |