line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Pandoc::Filter; |
2
|
7
|
|
|
7
|
|
203250
|
use strict; |
|
7
|
|
|
|
|
44
|
|
|
7
|
|
|
|
|
247
|
|
3
|
7
|
|
|
7
|
|
33
|
use warnings; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
207
|
|
4
|
7
|
|
|
7
|
|
132
|
use 5.010; |
|
7
|
|
|
|
|
26
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.34'; |
7
|
|
|
|
|
|
|
|
8
|
7
|
|
|
7
|
|
2326
|
use JSON; |
|
7
|
|
|
|
|
45541
|
|
|
7
|
|
|
|
|
53
|
|
9
|
7
|
|
|
7
|
|
991
|
use Carp; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
440
|
|
10
|
7
|
|
|
7
|
|
45
|
use Scalar::Util 'reftype'; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
298
|
|
11
|
7
|
|
|
7
|
|
40
|
use List::Util; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
446
|
|
12
|
7
|
|
|
7
|
|
1169
|
use Pandoc::Walker; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
397
|
|
13
|
7
|
|
|
7
|
|
2107
|
use Pandoc::Elements qw(Image Str); |
|
7
|
|
|
|
|
21
|
|
|
7
|
|
|
|
|
1490
|
|
14
|
|
|
|
|
|
|
|
15
|
7
|
|
|
7
|
|
53
|
use parent 'Exporter'; |
|
7
|
|
|
|
|
22
|
|
|
7
|
|
|
|
|
51
|
|
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
|
672
|
my $filter = Pandoc::Filter->new(@_); |
22
|
3
|
|
|
|
|
30
|
my $ast = Pandoc::Elements::pandoc_json(); |
23
|
3
|
|
|
2
|
|
72
|
binmode STDOUT, ':encoding(UTF-8)'; |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
14
|
|
24
|
3
|
50
|
|
|
|
10374
|
$filter->apply( $ast->content, @ARGV ? $ARGV[0] : '', $ast->meta ); |
25
|
3
|
|
|
|
|
24
|
return $ast; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _pod2usage_if_help { |
29
|
2
|
|
|
2
|
|
801
|
require Getopt::Long; |
30
|
2
|
|
|
|
|
10547
|
my %opt; |
31
|
2
|
|
|
|
|
9
|
Getopt::Long::GetOptions(\%opt, 'help|?'); |
32
|
2
|
50
|
|
|
|
255
|
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
|
1987
|
_pod2usage_if_help(); |
44
|
|
|
|
|
|
|
|
45
|
2
|
|
|
|
|
7
|
my $ast = pandoc_walk(@_); # implies binmode STDOUT UTF-8 |
46
|
2
|
|
|
|
|
49
|
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
|
|
|
|
|
147
|
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
|
2403
|
my $class = shift; |
66
|
10
|
100
|
66
|
|
|
91
|
my $action = (@_ < 2 or @_ % 2 or ref $_[0]) |
67
|
|
|
|
|
|
|
? Pandoc::Walker::action(@_) # @actions |
68
|
|
|
|
|
|
|
: Pandoc::Walker::action({ @_ }); # %actions |
69
|
10
|
|
|
|
|
63
|
bless { |
70
|
|
|
|
|
|
|
action => $action, |
71
|
|
|
|
|
|
|
error => '', |
72
|
|
|
|
|
|
|
}, $class; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub action { |
76
|
11
|
|
|
11
|
1
|
55
|
$_[0]->{action}; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub apply { |
80
|
10
|
|
|
10
|
1
|
42
|
my ( $self, $ast, $format, $meta ) = @_; |
81
|
10
|
|
100
|
|
|
48
|
$format ||= ''; |
82
|
10
|
|
100
|
|
|
38
|
$meta ||= eval { $ast->meta } || {}; |
|
|
|
66
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
10
|
|
|
|
|
30
|
Pandoc::Walker::transform( $ast, $self->action, $format, $meta ); |
85
|
|
|
|
|
|
|
|
86
|
10
|
|
|
|
|
58
|
$ast; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
__END__ |