-
Notifications
You must be signed in to change notification settings - Fork 5
/
pod.pm
105 lines (83 loc) · 2.01 KB
/
pod.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/perl
# POD as a wiki page type.
# See plugins/contrib/pod for documentation.
package IkiWiki::Plugin::pod;
use warnings;
use strict;
=head1 NAME
IkiWiki::Plugin::pod - process pages written in POD format.
=head1 VERSION
This describes version B<1.20100519> of IkiWiki::Plugin::pod
=cut
our $VERSION = '1.20100519';
=head1 PREREQUISITES
IkiWiki
Pod::Xhtml
IO::String
=head1 AUTHOR
Kathryn Andersen (RUBYKAT)
http://github.com/rubykat
=head1 COPYRIGHT
Copyright (c) 2009 Kathryn Andersen
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=cut
use IkiWiki 3.00;
use Pod::Xhtml;
use IO::String;
sub import {
hook(type => "getsetup", id => "pod", call => \&getsetup);
hook(type => "checkconfig", id => "pod", call => \&checkconfig);
hook(type => "htmlize", id => "pod", call => \&htmlize);
hook(type => "htmlize", id => "pm", call => \&htmlize);
}
sub getsetup () {
return
plugin => {
description => "process pages written in POD format",
safe => 1,
rebuild => undef,
},
pod_index => {
type => "boolean",
example => "0",
description => "if true, make an index for the page",
safe => 0,
rebuild => 0,
},
pod_toplink => {
type => "string",
example => "Top",
description => "label for link to top of page",
safe => 0,
rebuild => 0,
},
}
sub checkconfig () {
if (!defined $config{pod_index})
{
$config{pod_index} = 1;
}
if (!defined $config{pod_toplink})
{
$config{pod_toplink} = '';
}
return 1;
}
sub htmlize (@) {
my %params=@_;
my $page = $params{page};
my $toplink = $config{pod_toplink} ?
sprintf '<p><a href="#TOP" class="toplink">%s</a></p>',
$config{pod_toplink} : '';
my $parser = new Pod::Xhtml(
StringMode => 1,
FragmentOnly => 1,
MakeIndex => $config{pod_index},
TopLinks => $toplink,
);
my $io = IO::String->new($params{content});
$parser->parse_from_filehandle($io);
return $parser->asString;
}
1;