summaryrefslogtreecommitdiff
path: root/perl/IkiWiki/Plugin/h1title.pm
blob: be292165065a91f6212abc7aad94f8a8a2b0f574 (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.     
  32.     Introductory text with a list:
  33.     
  34.      * Item 1
  35.      * Item 2
  36.     ## Second header
  37.     Second section
  38. This plugin can be used with page templates that use <h1> tags for the page
  39. title to produce a consistent header hierarchy in rendered pages while keeping
  40. the Markdown source clean and free of meta directives.
  41. =head1 AUTHOR
  42. Jason Blevins <jrblevin@sdf.lonestar.org>,
  43. =head1 SEE ALSO
  44. ikiwiki Homepage:
  45. http://ikiwiki.info/
  46. ikiwiki Plugin Documentation:
  47. http://ikiwiki.info/plugins/write/
  48. =head1 LICENSE
  49. Copyright (C) 2008 Jason Blevins
  50. This program is free software; you can redistribute it and/or modify
  51. it under the terms of the GNU General Public License as published by
  52. the Free Software Foundation; either version 2 of the License, or
  53. (at your option) any later version.
  54. This program is distributed in the hope that it will be useful,
  55. but WITHOUT ANY WARRANTY; without even the implied warranty of
  56. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  57. GNU General Public License for more details.
  58. You should have received a copy of the GNU General Public License along
  59. with this program; if not, write to the Free Software Foundation, Inc.,
  60. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.