- #!/usr/bin/perl
- use warnings;
- use strict;
- use feature qw(switch);
- no if $] >= 5.018, warnings => "experimental::smartmatch";
- use Pandoc::Filter 0.06;
- use Pandoc::Elements;
- pandoc_filter(
- \&matter,
- \&toc,
- );
- # FIXME: use Header (not latex RawBlock) - why does it hang?!?
- sub header {
- my $label = shift;
- # Header( 1, attributes {}, [ Str $label ], );
- RawBlock( 'latex', '\\chapter{'.$label.'}' );
- };
- sub matter {
- my $self = shift;
- return unless ( $self->name eq 'Header' );
- return unless ( $self->level == 1 );
- given (stringify($self)) {
- when (/^Table/) {
- return [
- # RawBlock( 'latex', '\\frontmatter' ),
- RawBlock( 'latex',
- '{\\hypersetup{linkcolor=black}\\setcounter{tocdepth}{3}\\cleartorecto\\tableofcontents}'
- ),
- ] };
- when (/^Scope/) {
- return [
- RawBlock( 'latex', '\\mainmatter' ),
- header(stringify($self)),
- ] };
- when (/^Notes/) {
- return [
- RawBlock( 'latex', '\\backmatter' ),
- header('References'),
- ] };
- default { return };
- }
- }
- sub toc {
- my $self = shift;
- return []
- if ( $self->name eq 'Para' and stringify($self) =~ /__TOC__/ );
- return;
- }
|