summaryrefslogtreecommitdiff
path: root/pandoc-memoir
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2015-01-16 22:42:25 +0100
committerJonas Smedegaard <dr@jones.dk>2015-01-16 22:42:25 +0100
commitef223f21633b1c8b0f0565ff25d91161d6476aec (patch)
tree1337d83028299603f8e3cc72295695bb71041c30 /pandoc-memoir
parent5d5cc53911e989349033645790ae9b3997e17b51 (diff)
Tidy memoir filter.
Diffstat (limited to 'pandoc-memoir')
-rwxr-xr-xpandoc-memoir34
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 {