diff options
-rwxr-xr-x | pandoc-memoir | 65 |
1 files changed, 28 insertions, 37 deletions
diff --git a/pandoc-memoir b/pandoc-memoir index e28e16a..b4158e7 100755 --- a/pandoc-memoir +++ b/pandoc-memoir @@ -3,14 +3,14 @@ use warnings; use strict; -use Pandoc::Filter 0.05; +use feature qw(switch); +no if $] >= 5.018, warnings => "experimental::smartmatch"; + +use Pandoc::Filter 0.06; use Pandoc::Elements; -# FIXME: avoid eating content past tweaked headers pandoc_filter( - \&frontmatter, - \&mainmatter, - \&backmatter, + \&matter, \&toc, ); @@ -21,39 +21,30 @@ sub header { RawBlock( 'latex', '\\chapter{'.$label.'}' ); }; -sub frontmatter { - my $self = shift; - return [ -# RawBlock( 'latex', '\\frontmatter' ), - RawBlock( 'latex', - '{\\hypersetup{linkcolor=black}\\setcounter{tocdepth}{3}\\cleartorecto\\tableofcontents}' - ), - ] - if ( $self->name eq 'Header' and $self->level == 1 - and stringify($self) =~ /^Table/ ); - return; -} - -sub mainmatter { +sub matter { my $self = shift; - return [ - RawBlock( 'latex', '\\mainmatter' ), - header(stringify($self)), - ] - if ( $self->name eq 'Header' and $self->level == 1 - and stringify($self) =~ /^Scope/ ); - return; -} - -sub backmatter { - my $self = shift; - return [ - RawBlock( 'latex', '\\backmatter' ), - header('References'), - ] - if ( $self->name eq 'Header' and $self->level == 1 - and stringify($self) =~ /^Notes/ ); - return; + 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 { |