summaryrefslogtreecommitdiff
path: root/pandoc-filter-sections
blob: f0bb5a55a6aa4b38f281a67281f81668cc5e3e80 (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 unless ( $self->name eq 'Header' and $self->level == 1
  43. and stringify($self) =~ /^Table/ );
  44. return RawBlock( 'latex',
  45. '{\\hypersetup{linkcolor=black}\\setcounter{tocdepth}{3}\\tableofcontents}'
  46. );
  47. }