summaryrefslogtreecommitdiff
path: root/perl/IkiWiki/Plugin/h1title.pm
blob: 2d5d05f079d78dd842728d0e9aa22467a4cd34a6 (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki::Plugin::h1title;
  3. use warnings;
  4. use strict;
  5. use IkiWiki 2.00;
  6. sub import {
  7. hook(type => "filter", id => "h1title", call => \&filter);
  8. }
  9. sub filter(@) {
  10. my %params = @_;
  11. my $page = $params{page};
  12. my $content = $params{content};
  13. if ($content =~ s/^\#(?=>[^#])[ \t]*(.*?)[ \t]*\#*\n//) {
  14. $pagestate{$page}{meta}{title} = $1;
  15. }
  16. return $content;
  17. }
  18. 1
  19. __END__
  20. =head1 NAME
  21. ikiwiki Plug-in: h1title
  22. =head1 SYNOPSIS
  23. If there is a level 1 Markdown atx-style (hash mark) header on the first line,
  24. this plugin uses it to set the page title and removes it from the page body so
  25. that it won't be rendered twice. Level 1 headers in the remainder of the page
  26. will be ignored.
  27. For example, the following page will have title "My Title" and the rendered
  28. page body will begin with the level two header "Introduction."
  29. # My Title
  30. ## Introduction
  31. Introductory text with a list:
  32. * Item 1
  33. * Item 2
  34. ## Second header
  35. Second section
  36. This plugin can be used with page templates that use <h1> tags for the page
  37. title to produce a consistent header hierarchy in rendered pages while keeping
  38. the Markdown source clean and free of meta directives.
  39. =head1 AUTHOR
  40. Jason Blevins <jrblevin@sdf.lonestar.org>,
  41. =head1 SEE ALSO
  42. ikiwiki Homepage:
  43. http://ikiwiki.info/
  44. ikiwiki Plugin Documentation:
  45. http://ikiwiki.info/plugins/write/
  46. =head1 LICENSE
  47. Copyright (C) 2008 Jason Blevins
  48. This program is free software; you can redistribute it and/or modify
  49. it under the terms of the GNU General Public License as published by
  50. the Free Software Foundation; either version 2 of the License, or
  51. (at your option) any later version.
  52. This program is distributed in the hope that it will be useful,
  53. but WITHOUT ANY WARRANTY; without even the implied warranty of
  54. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  55. GNU General Public License for more details.
  56. You should have received a copy of the GNU General Public License along
  57. with this program; if not, write to the Free Software Foundation, Inc.,
  58. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.