summaryrefslogtreecommitdiff
path: root/pandoc-memoir
blob: 174337ca13a7190275ba01ae92447a63f31e3561 (plain)
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use Pandoc::Filter;
  5. use Pandoc::Elements;
  6. # FIXME: avoid eating content past tweaked headers
  7. pandoc_filter(
  8. \&frontmatter,
  9. \&mainmatter,
  10. \&backmatter,
  11. \&toc,
  12. );
  13. # FIXME: use Header (not latex RawBlock) - why does it hang?!?
  14. sub header {
  15. my $label = shift;
  16. # Header( 1, attributes {}, [ Str $label ], );
  17. RawBlock( 'latex', '\\chapter{'.$label.'}' );
  18. };
  19. sub frontmatter {
  20. my $self = shift;
  21. return [ RawBlock( 'latex', '\\frontmatter' ), header('About'), ]
  22. if ( $self->name eq 'Header' and $self->level >= 1
  23. and stringify($self) eq 'About' );
  24. return;
  25. }
  26. sub mainmatter {
  27. my $self = shift;
  28. return [ RawBlock( 'latex', '\\mainmatter' ), header(stringify($self)), ]
  29. if ( $self->name eq 'Header' and $self->level == 1
  30. and stringify($self) =~ /^Scope/ );
  31. return;
  32. }
  33. sub backmatter {
  34. my $self = shift;
  35. return [ RawBlock( 'latex', '\\backmatter' ), header('References'), ]
  36. if ( $self->name eq 'Header' and $self->level == 1
  37. and stringify($self) =~ /^Notes/ );
  38. return;
  39. }
  40. sub toc {
  41. my $self = shift;
  42. return RawBlock( 'latex',
  43. '{\\hypersetup{linkcolor=black}\\setcounter{tocdepth}{3}\\clearpage\\tableofcontents}'
  44. )
  45. if ( $self->name eq 'Header' and $self->level == 1
  46. and stringify($self) =~ /^Table/ );
  47. return []
  48. if ( $self->name eq 'Para' and stringify($self) =~ /__TOC__/ );
  49. return;
  50. }