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