NAME
Pandoc::Filter - process Pandoc abstract syntax tree
SYNOPSIS
The following filter, adopted from pandoc scripting documentation converts level 2+ headers to regular paragraphs.
use Pandoc::Filter;
use Pandoc::Elements;
pandoc_filter sub {
return unless ($_[0]->name eq 'Header' and $_[0]->level >= 2);
return Para [ Emph $_[0]->content ];
};
DESCRIPTION
Pandoc::Filter is a port of pandocfilters from Python to modern Perl. The module provide provides functions to aid writing Perl scripts that process a Pandoc abstract syntax tree (AST) serialized as JSON. See Pandoc::Elements for documentation of AST elements.
In most cases you better use the function interface in Pandoc::Walker which this module is based on.
METHODS
new( @action )
Create a new filter with one or more action functions, given as code reference(s).
apply( $ast [, $format [ $metadata ] ] )
Apply all actions to a given abstract syntax tree (AST). The AST is modified in place and also returned for convenience. Additional argument format and metadata are also passed to the action function. Metadata is taken from the Document by default (if the AST is a Document root).
FUNCTIONS
pandoc_filter( @action )
Read a single line of JSON from STDIN, apply actions and print the resulting AST as single line of JSON. This function is roughly equivalent to
my $ast = Pandoc::Elements::from_json(<>);
Pandoc::Filter->new(@action)->apply($ast);
say $ast->to_json;
stringify( $ast )
Walks the ast and returns concatenated string content, leaving out all formatting.
COPYRIGHT AND LICENSE
Copyright 2014- Jakob Voß
GNU General Public License, Version 2
This module is heavily based on Pandoc by John MacFarlane.