root/Kwiki-Footnote/trunk/lib/Kwiki/Footnote.pm

Revision 1536 (checked in by miyagawa, 15 years ago)

import

  • Property svn:keywords set to Id Revision
Line 
1 package Kwiki::Footnote;
2
3 use strict;
4 our $VERSION = '0.01';
5 use Kwiki::Plugin '-Base';
6 use Kwiki::Installer '-Base';
7
8 const class_id    => 'footnote';
9 const class_title => 'Footnote Wafl';
10 const css_file    => 'footnote.css';
11
12 field footnotes => [];
13
14 sub register {
15     my $registry = shift;
16     $registry->add(wafl => footnote => "Kwiki::Footnote::Footnote");
17     $registry->add(wafl => footnotelist => "Kwiki::Footnote::FootnoteList");
18 }
19
20 package Kwiki::Footnote::Footnote;
21 use base 'Spoon::Formatter::WaflPhrase';
22
23 sub html {
24     my $text = $self->arguments;
25     my $footnotes = $self->hub->footnote->footnotes;
26     push @$footnotes, $text;
27     my $num = @$footnotes;
28     return <<EOF;
29 <sup id="fb$num"><a href="#fn$num" title="@{[$self->html_escape($text)]}">$num</a></sup>
30 EOF
31 }
32
33 package Kwiki::Footnote::FootnoteList;
34 use base 'Spoon::Formatter::WaflPhrase';
35
36 sub html {
37     my @footnotes = @{$self->hub->footnote->footnotes};
38     my $html = qq(<ul class="footnotelist">\n);
39     for my $idx (0..$#footnotes) {
40         my $text = $footnotes[$idx];
41         my $num  = $idx + 1;
42         $html .= <<EOF
43 <li class="footnote"><cite id="fn$num"><a href="#fb$num">*$num</a></cite>: @{[$self->hub->formatter->text_to_html($text)]}</li>
44 EOF
45     ;
46     }
47     $html .= "</ul>\n";
48     return $html;
49 }
50
51 package Kwiki::Footnote;
52 1;
53 __DATA__
54
55 =head1 NAME
56
57 Kwiki::Footnote - Footnote plugin for Kwiki
58
59 =head1 SYNOPSIS
60
61   This Wiki is powered by Kwiki {footnote: Kwiki is Spoon and Spiffy}
62
63   ....
64
65   {footnotelist}
66
67 =head1 DESCRIPTION
68
69 Kwiki::Footnote allows you to add footnotes with inline Wafl.
70
71 =head1 WANT-TODO
72
73 =over 4
74
75 =item *
76
77 Writing {footnotelist} by hand seems like a pain. Are there any way to automatically insert footnote listing after the page body using some hook?
78
79 =back
80
81 =head1 AUTHOR
82
83 Tatsuhiko Miyagawa E<lt>miyagawa@bulknews.netE<gt>
84
85 This library is free software; you can redistribute it and/or modify
86 it under the same terms as Perl itself.
87
88 =head1 SEE ALSO
89
90 L<Kwiki::AnchorLink>
91
92 =cut
93
94 __css/footnote.css__
95 ul.footnotelist {
96   margin-left: 0;
97 }
98 li.footnote {
99   margin-left: 0;
100 }
Note: See TracBrowser for help on using the browser.