diff options
Diffstat (limited to 'pandoc-memoir')
-rwxr-xr-x | pandoc-memoir | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/pandoc-memoir b/pandoc-memoir index cb02d62..6954877 100755 --- a/pandoc-memoir +++ b/pandoc-memoir @@ -9,7 +9,7 @@ no if $] >= 5.018, warnings => "experimental::smartmatch"; use Pandoc::Filter 0.06; use Pandoc::Elements; -my ( $frontmatter_seen, $mainmatter_seen, $backmatter_seen); +my ( $frontmatter_seen, $mainmatter_seen, $backmatter_seen, $toc_seen); pandoc_filter( \&matter, @@ -20,27 +20,29 @@ sub matter { my $self = shift; return unless ( $self->name eq 'Header' ); return unless ( $self->level == 1 ); + my (@replace, @prepend); +# push @prepend, RawBlock( 'latex', '\\frontmatter' ) +# unless ($toc_seen++); given (stringify($self)) { when ( /^Table/ and not $frontmatter_seen++ ) { - return [ -# RawBlock( 'latex', '\\frontmatter' ), - RawBlock( 'latex', - '{\\hypersetup{linkcolor=black}\\setcounter{tocdepth}{3}\\cleartorecto\\tableofcontents}' - ), - ] }; + push @replace, RawBlock( 'latex', + '{\\hypersetup{linkcolor=black}\\setcounter{tocdepth}{3}\\cleartorecto\\tableofcontents}' + ); + }; when ( /^Scope/ and not $mainmatter_seen++ ) { - return [ - RawBlock( 'latex', '\\mainmatter' ), - $self, - ] }; + push @prepend, RawBlock( 'latex', '\\mainmatter' ); + }; when ( /^Notes/ and not $backmatter_seen++ ) { - return [ - RawBlock( 'latex', '\\backmatter' ), - Header( 1, attributes {}, - [ Str 'References' ] ), - ] }; + push @prepend, RawBlock( 'latex', '\\backmatter' ); + push @replace, Header( 1, attributes {}, + [ Str 'References' ] ); + }; default { return }; } + + return unless ( @replace or @prepend ); + return [ @prepend, $self ] unless (@replace); + return [ @prepend, @replace ]; } sub toc { |