package Pandoc::Filter;
use strict;
use warnings;
use 5.010;
our $VERSION = '0.34';
use JSON;
use Carp;
use Scalar::Util 'reftype';
use List::Util;
use Pandoc::Walker;
use Pandoc::Elements qw(Image
## no critic
my $filter = Pandoc::Filter->new(@_);
my $ast = Pandoc::Elements::pandoc_json(<STDIN>);
binmode STDOUT, ':encoding(UTF-8)';
$filter->apply( $ast->content, @ARGV ? $ARG
e STDOUT UTF-8
my $json = JSON->new->allow_blessed->convert_blessed->encode($ast);
#my $json = $ast->to_json; # does not want binmode STDOUT UTF-8
say STDOUT $json;
}
sub pandoc_filter_
'Pandoc::Filter';
our @EXPORT_OK = (qw(find_filter apply_filter));
use Pandoc::Elements 'pandoc_json';
use Pandoc;
use IPC::Cmd 'can_run';
use IPC::Run3;
sub new {
bless { }, shift;
}
sub appl
$name\n");
}
sub apply_filter {
my ($doc, $format, @filter) = @_;
my $stdin = $doc->to_json;
my $stdout = "";
my $stderr = "";
run3 [@filter, $format // ''], \$stdin, \$stdout,
:',@filter)."\n$stderr";
}
my $transformed = eval { pandoc_json($stdout) };
die join(' ','filter emitted no valid JSON:',@filter)."\n" if $@;
# modify original document
$doc->meta($tr
uments
=head1 SYNOPSIS
use Pandoc::Walker;
use Pandoc::Elements qw(pandoc_json);
my $ast = pandoc_json(<>);
# extract all links and image URLs
my $links = query $ast, 'Link|Ima
itSubroutinePrototypes)
use warnings;
use 5.010001;
our $VERSION = '0.38';
use Carp;
use JSON qw(decode_json);
use Scalar::Util qw(blessed reftype);
use Pandoc::Walker qw(walk);
use Pandoc::Version;
EXPORT = (
keys %ELEMENTS,
qw(Document attributes metadata citation pandoc_version pandoc_json pandoc_query)
);
our @EXPORT_OK = ( @EXPORT, 'element' );
# create constructor functions
foreach
from_json;
my $arg = do {
if ( @_ == 1 ) {
$from_json = 1;
my $reftype = reftype $_[0] // '';
if ( $reftype eq 'ARRAY') {
# old JSON for
ocument::VERSION;
use JSON ();
use Scalar::Util qw(reftype blessed);
use Pandoc::Walker ();
use subs qw(walk query transform); # Silence syntax warnings
sub to_json {
JSON->new->utf8->canonica
l->convert_blessed->encode( $_[0] );
}
sub TO_JSON {
# Run everything thru this method so arrays/hashes are cloned
# and objects without TO_JSON methods are stringified.
# Required to en
ed ) = @_;
if ( $maybe_blessed && blessed $ast ) {
return $ast if $ast->can('TO_JSON'); # JSON.pm will convert
# may have overloaded stringification! Should we check?
ict;
use warnings;
use 5.010001;
use Pandoc::Elements;
use Scalar::Util qw(blessed reftype);
use JSON::PP;
use Carp;
# # For Pandoc::Metadata::Error
# use Carp qw(shortmess longmess);
# packages and
Document::Metadata;
{
no warnings 'once';
*to_json = \&Pandoc::Document::Element::to_json;
}
sub TO_JSON {
return { %{ $_[0] } }
}
sub value {
my
'FALSE' ? 1 : 0;
}
sub Pandoc::Document::MetaBool::TO_JSON {
return {
t => 'MetaBool',
c => $_[0]->{c} ? JSON::true() : JSON::false(),
};
}
sub Pandoc::Document::MetaBool::va