summaryrefslogtreecommitdiff
path: root/perl/IkiWiki/Plugin
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2010-09-16 01:09:59 +0200
committerJonas Smedegaard <dr@jones.dk>2010-09-16 01:09:59 +0200
commita21cc64a856898d66c9a2a3b2ca53dbde6a12d61 (patch)
tree20b55a8e23d95b94461628ebb088da8c651393f2 /perl/IkiWiki/Plugin
parentbd56e079facdecce4acc8dd7cc15c702f05547b7 (diff)
parent18ee76fd6e02aa439b1308719ea2f077a3e75f19 (diff)
Merge branch '_da' into da
Diffstat (limited to 'perl/IkiWiki/Plugin')
-rw-r--r--perl/IkiWiki/Plugin/h1title.pm87
1 files changed, 87 insertions, 0 deletions
diff --git a/perl/IkiWiki/Plugin/h1title.pm b/perl/IkiWiki/Plugin/h1title.pm
new file mode 100644
index 0000000..be29216
--- /dev/null
+++ b/perl/IkiWiki/Plugin/h1title.pm
@@ -0,0 +1,87 @@
+#!/usr/bin/perl
+
+package IkiWiki::Plugin::h1title;
+
+use warnings;
+use strict;
+use IkiWiki 2.00;
+
+sub import {
+ hook(type => "filter", id => "h1title", call => \&filter);
+}
+
+sub filter(@) {
+ my %params = @_;
+ my $page = $params{page};
+ my $content = $params{content};
+
+ if ($content =~ s/^\#[ \t]+(.*?)[ \t]*\#*\n//) {
+ $pagestate{$page}{meta}{title} = $1;
+ }
+ return $content;
+}
+
+1
+
+__END__
+
+=head1 NAME
+
+ikiwiki Plug-in: h1title
+
+=head1 SYNOPSIS
+
+If there is a level 1 Markdown atx-style (hash mark) header on the first line,
+this plugin uses it to set the page title and removes it from the page body so
+that it won't be rendered twice. Level 1 headers in the remainder of the page
+will be ignored.
+
+For example, the following page will have title "My Title" and the rendered
+page body will begin with the level two header "Introduction."
+
+ # My Title
+
+ ## Introduction
+
+ Introductory text with a list:
+
+ * Item 1
+ * Item 2
+
+ ## Second header
+
+ Second section
+
+This plugin can be used with page templates that use <h1> tags for the page
+title to produce a consistent header hierarchy in rendered pages while keeping
+the Markdown source clean and free of meta directives.
+
+=head1 AUTHOR
+
+Jason Blevins <jrblevin@sdf.lonestar.org>,
+
+=head1 SEE ALSO
+
+ikiwiki Homepage:
+http://ikiwiki.info/
+
+ikiwiki Plugin Documentation:
+http://ikiwiki.info/plugins/write/
+
+=head1 LICENSE
+
+Copyright (C) 2008 Jason Blevins
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.