- #!/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;
- my ( $frontmatter_seen, $mainmatter_seen, $backmatter_seen);
- pandoc_filter(
- \&matter,
- \&toc,
- );
- sub matter {
- my $self = shift;
- return unless ( $self->name eq 'Header' );
- return unless ( $self->level == 1 );
- given (stringify($self)) {
- when ( /^Table/ and not $frontmatter_seen++ ) {
- return [
- # RawBlock( 'latex', '\\frontmatter' ),
- RawBlock( 'latex',
- '{\\hypersetup{linkcolor=black}\\setcounter{tocdepth}{3}\\cleartorecto\\tableofcontents}'
- ),
- ] };
- when ( /^Scope/ and not $mainmatter_seen++ ) {
- return [
- RawBlock( 'latex', '\\mainmatter' ),
- $self,
- ] };
- when ( /^Notes/ and not $backmatter_seen++ ) {
- return [
- RawBlock( 'latex', '\\backmatter' ),
- Header( 1, attributes {},
- [ Str 'References' ] ),
- ] };
- default { return };
- }
- }
- sub toc {
- my $self = shift;
- return []
- if ( $self->name eq 'Para' and stringify($self) =~ /__TOC__/ );
- return;
- }
|