summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2015-01-15 16:50:38 +0100
committerJonas Smedegaard <dr@jones.dk>2015-01-15 16:50:38 +0100
commit479bae5fc69ef0c35f102ef569d1b4356f8ebd32 (patch)
treedad8f24a7d50c12548ed1fe833b1b2cb2da62b37
parent41dc80865d81cb939618b49424f7950f767eb9f3 (diff)
Refactor memoir filter, using (not yet released) fixed Pandoc::Filter.
-rwxr-xr-xpandoc-memoir65
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 {