summaryrefslogtreecommitdiff
path: root/pandoc-memoir
blob: cb02d62b9b9074d28fdebe091e8e43f6c15a887d (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. my ( $frontmatter_seen, $mainmatter_seen, $backmatter_seen);
  9. pandoc_filter(
  10. \&matter,
  11. \&toc,
  12. );
  13. sub matter {
  14. my $self = shift;
  15. return unless ( $self->name eq 'Header' );
  16. return unless ( $self->level == 1 );
  17. given (stringify($self)) {
  18. when ( /^Table/ and not $frontmatter_seen++ ) {
  19. return [
  20. # RawBlock( 'latex', '\\frontmatter' ),
  21. RawBlock( 'latex',
  22. '{\\hypersetup{linkcolor=black}\\setcounter{tocdepth}{3}\\cleartorecto\\tableofcontents}'
  23. ),
  24. ] };
  25. when ( /^Scope/ and not $mainmatter_seen++ ) {
  26. return [
  27. RawBlock( 'latex', '\\mainmatter' ),
  28. $self,
  29. ] };
  30. when ( /^Notes/ and not $backmatter_seen++ ) {
  31. return [
  32. RawBlock( 'latex', '\\backmatter' ),
  33. Header( 1, attributes {},
  34. [ Str 'References' ] ),
  35. ] };
  36. default { return };
  37. }
  38. }
  39. sub toc {
  40. my $self = shift;
  41. return []
  42. if ( $self->name eq 'Para' and stringify($self) =~ /__TOC__/ );
  43. return;
  44. }