test document
}, 'to_pandoc'; } { my $html = $doc->to_pandoc( '-t' => 'html', '--standalone' ); ok $html =~ qr{^to_markdown, $doc->to_pandoc( '-t' => 'markdown' ), 'to_markdown'; } { my $to_latex = new_ok Pandoc => [ '-t' => 'latex' ], 'to-latex-object'; is $doc->to_pandoc( $to_latex ), $doc->to_latex,'to latex with custom Pandoc'; } done_testing; attributes.t 100644 001750 001750 3743 13347276615 16125 0 ustar 00voj voj 000000 000000 Pandoc-Elements-0.38/t use strict; use v5.10; use Test::More; use Pandoc::Elements; use Hash::MultiValue; my $attr_hash = { class => [qw(x x y)], answer => 42, id => 0 }; is_deeply attributes {}, [ '', [], [] ], 'empty attributes'; is_deeply attributes(undef), [ '', [], [] ], 'empty attributes (undef)'; is_deeply attributes $attr_hash, [ '0', [qw(x x y)], [ [ answer => '42' ] ] ], 'classes and id'; my $e = Code attributes {}, ''; is_deeply [], [ $e->keyvals->flatten ], 'empty attributes'; $e = Code attributes $attr_hash, ''; is_deeply [ id => '0', class => 'x x y', answer => '42', ], [ $e->keyvals->flatten ], 'keyvals'; $e = Code [ '', [], [ [ foo => '1' ], [ bar => '2' ], [ foo => '3' ] ] ], ''; is_deeply [ $e->keyvals->flatten ], [ foo => 1, bar => 2, foo => 3 ], 'keyvals'; $e->keyvals( Hash::MultiValue->new( foo => 9, id => 0, bar => 8, foo => 7, class => 'a', class => 'b c', ) ); is_deeply [ '0', [qw(a b c)], [ [ foo => 9 ], [ bar => 8 ], [ foo => 7 ] ] ], $e->attr, 'attributes via Hash::MultiValue'; $e->keyvals({ foo => 3, class => 'x y' }); is_deeply [ '0', [qw(x y)], [ [ foo => 3 ] ] ], $e->attr, 'keyvals as setter'; $e->keyvals({ }); is_deeply [ '0', [qw(x y)], [ ] ], $e->attr, 'keyvals as setter (no class)'; $e->keyvals( id => undef, class => undef ); is_deeply [ '', [], [ ] ], $e->attr, 'keyvals to remove id and classes'; $e->id(2); is '2', $e->id, 'id setter'; $e->class('q r', 's ', [qw(x y)]); is_deeply 'q r s x y', $e->class, 'class setter'; $e->keyvals( a => 1, class => ['s'], a => 2 ); is_deeply [ '2', ['s'], [ [ a => 1 ], [ a => 2 ] ] ], $e->attr, 'keyvals as setter'; my @class_hashes = ( { class => [qw(foo bar doz)] }, { class => 'foo bar doz ' }, { class => " foo\t bar\n doz " }, ); foreach (@class_hashes) { $e = CodeBlock attributes $_, ''; is_deeply $e->class, 'foo bar doz', 'class(es) attributes'; } foreach (qw(foo bar doz)) { ok $e->match(".$_"), 'class match'; } ok !$e->match('.baz'), 'class selector'; done_testing; meta-filter.t 100644 001750 001750 1752 13347276615 16146 0 ustar 00voj voj 000000 000000 Pandoc-Elements-0.38/t use strict; use 5.010; use Test::More; use Pandoc::Filter; use Pandoc::Elements; my $json = '[{"unMeta":{"foo":{"c":[{"c":"bar","t":"Str"}],"t":"MetaInlines"}}},[{"c":[{"c":"doz","t":"Str"}],"t":"Para"}]]'; my $allcaps = '[{"unMeta":{"foo":{"c":[{"c":"BAR","t":"Str"}],"t":"MetaInlines"}}},[{"c":[{"c":"DOZ","t":"Str"}],"t":"Para"}]]'; my $contentcaps = '[{"unMeta":{"foo":{"c":[{"c":"bar","t":"Str"}],"t":"MetaInlines"}}},[{"c":[{"c":"DOZ","t":"Str"}],"t":"Para"}]]'; my $filter = Pandoc::Filter->new( Str => sub { Str(uc $_->content) } ); my $doc = pandoc_json($json); $doc->transform($filter), is $doc->to_json, $allcaps, 'transform with metadata element'; $doc = pandoc_json($json); $filter->apply($doc->content); is $doc->to_json, $contentcaps, 'apply document content only'; { open my $stdin, '<', \$json; local *STDIN = $stdin; my $doc = pandoc_walk Str => sub { Str(uc $_->content) }; is $doc->to_json, $contentcaps, 'pandoc_walk document content only'; } done_testing; multifilter.t 100644 001750 001750 5033 13347276615 16271 0 ustar 00voj voj 000000 000000 Pandoc-Elements-0.38/t use strict; use Test::More; use Test::Exception; use Pandoc::Elements; use Pandoc::Filter::Multifilter qw(find_filter apply_filter); use IPC::Cmd 'can_run'; use Pandoc; # used to test ~/.pandoc/filters as default filter location # this does not work on Windows because of symlinks my ($PANDOC_SYMLINK) = grep { -d $_ } ('t/.pandoc'); # find_filter( ... ) { my @tests = ( { input => ['script/multifilter'], expected => ['script/multifilter'], name => 'absolute path', skip => 'MSWin32', }, { input => ['t/pandoc/filters/empty.pl'], expected => [ 'perl', 't/pandoc/filters/empty.pl' ], name => 'known extension', }, { input => ['perl'], expected => [ can_run('perl') ], name => 'executable in $PATH', }, ); local $ENV{HOME} = 't'; if ( $PANDOC_SYMLINK ) { push @tests, ( { input => ['empty.pl'], expected => [ 'perl', 't/.pandoc/filters/empty.pl' ], name => 'known extension in DATADIR', }, { input => ['caps'], expected => ['t/.pandoc/filters/caps'], name => 'executable in DATADIR', skip => 'MSWin32', }, ); } while ( my $test = shift @tests ) { SKIP: { skip 'find_filter: ' . $test->{name} . ' on ' . $^O, 1 if $^O eq ($test->{skip} || '-'); my @filter = find_filter( @{ $test->{input} } ); is_deeply \@filter, $test->{expected}, join ' ', 'find_filter: ' . $test->{name}; } } my $notfound = '0c9703d020ded30c97682e812636c9ef'; throws_ok { find_filter($notfound) } qr/^filter not found: $notfound/; } if ( $ENV{RELEASE_TESTING} and pandoc and pandoc->version('1.12') ) { my $in = Document {}, [ Para [ Str 'hi' ] ]; my $out = apply_filter( $in, 'html', find_filter( 'caps', 't/pandoc' ) ); is $out->string, 'HI', 'apply_filter'; throws_ok { apply_filter( $in, 'html', find_filter( 'empty.pl', 't/pandoc' ) ); } qr{^filter emitted no valid JSON}; if ( $PANDOC_SYMLINK ) { $in->meta( { multifilter => MetaList [ MetaInlines [ Str 'caps' ] ] } ); local $ENV{HOME} = 't'; Pandoc::Filter::Multifilter->new->apply($in)->to_json; is $in->string, 'HI', 'apply_filter'; } } else { note "Skipping detailed testing of Pandoc::Filter::Multifilter"; } done_testing; examples 000755 001750 001750 0 13347276615 14756 5 ustar 00voj voj 000000 000000 Pandoc-Elements-0.38 caps.pl 100755 001750 001750 1210 13347276615 16376 0 ustar 00voj voj 000000 000000 Pandoc-Elements-0.38/examples #!/usr/bin/env perl use strict; =head1 DESCRIPTION Pandoc filter to convert all regular text to uppercase. Code, link URLs, etc. are not affected. =cut use Pandoc::Filter; use Pandoc::Elements qw(Str); pandoc_filter Str => sub { return Str(uc $_->content); # alternatively to modify in-place (comment out previous line to enable) $_->content(uc($_->content)); return }; =head1 SYNOPSIS pandoc --filter caps.pl -o output.html < input.md =head1 SEE ALSO This is a port of L