/usr/bin/pandocwalk is in libpandoc-elements-perl 0.24-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | #!/usr/bin/env perl
use strict;
use 5.010;
our $VERSION = '0.15';
use Pod::Usage;
pod2usage(1) unless @ARGV;
my $script = pop @ARGV;
my $pipe;
if ( -f $script ) {
$pipe = sub {
exec($script) or die "can't exec $script\n";
};
}
else {
use Pandoc::Filter::Lazy;
my $filter = Pandoc::Filter::Lazy->new($script);
if ( $filter->error ) {
say STDERR "Failed to compile filter code:\n";
say STDERR $filter->code( indent => ' ' ) . "\n";
say STDERR $filter->error;
exit 1;
}
$pipe = sub {
my $json = <STDIN>;
exit 1 if substr( $json, 0, 1 ) ne '[';
my $ast = Pandoc::Elements::pandoc_json($json);
$filter->apply($ast);
};
}
my $pid = open( STDIN, "-|" ) // die "cannot fork: $!\n";
if ( $pid == 0 ) {
exec( 'pandoc', @ARGV, '-t', 'json' ) or die "can't exec pandoc: $!\n";
}
else {
binmode STDOUT, ':encoding(UTF-8)';
$pipe->();
}
=head1 NAME
pandocwalk - parse document with pandoc and process abstract syntax tree
=head1 SYNOPSIS
pandocwalk [ options ] [ SCRIPT | 'SELECTOR => ACTION' ]
Calls pandoc with given options to parse a document and process its abstract
syntax tree. A processing script must be given as executable file or as Perl
code to filter the document. See L<Pandoc::Filter::Lazy> for filter syntax.
=head2 EXAMPLES
Extract all URLs from a HTML file:
pandocwalk document.html 'Link => say $_->url'
Extract table of contents from a LaTeX file:
pandocwalk document.tex 'Header => say " " x $_->level, $_->string'
=cut
|