Pandoc::Filter - process Pandoc abstract syntax tree
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 ]; };
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.
Create a new filter with one or more action functions, given as code reference(s).
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).
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;
Walks the ast and returns concatenated string content, leaving out all formatting.
Copyright 2014- Jakob Voß
GNU General Public License, Version 2
This module is heavily based on Pandoc by John MacFarlane.
To install Pandoc::Elements, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Pandoc::Elements
CPAN shell
perl -MCPAN -e shell install Pandoc::Elements
For more information on module installation, please visit the detailed CPAN module installation guide.