]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/camelcase.pm
touchups
[ikiwiki.git] / IkiWiki / Plugin / camelcase.pm
1 #!/usr/bin/perl
2 # CamelCase links
3 package IkiWiki::Plugin::camelcase;
4
5 use warnings;
6 use strict;
7 use IkiWiki 2.00;
8
9 # This regexp is based on the one in Text::WikiFormat.
10 my $link_regexp=qr{
11         (?<![^A-Za-z0-9\s])     # try to avoid expanding non-links with a
12                                 # zero width negative lookbehind for
13                                 # characters that suggest it's not a link
14         \b                      # word boundry
15         (
16                 (?:
17                         [A-Z]           # Uppercase start
18                         [a-z0-9]        # followed by lowercase
19                         \w*             # and rest of word
20                 )
21                 {2,}                    # repeated twice
22         )
23 }x;
24
25 sub import { #{{{
26         hook(type => "linkify", id => "camelcase", call => \&linkify);
27         hook(type => "scan", id => "camelcase", call => \&scan);
28 } # }}}
29
30 sub linkify (@) { #{{{
31         my %params=@_;
32         my $page=$params{page};
33         my $destpage=$params{destpage};
34
35         $params{content}=~s{$link_regexp}{
36                 htmllink($page, $destpage, IkiWiki::linkpage($1))
37         }eg;
38
39         return $params{content};
40 } #}}}
41
42 sub scan (@) { #{{{
43         my %params=@_;
44         my $page=$params{page};
45         my $content=$params{content};
46
47         while ($content =~ /$link_regexp/g) {
48                 push @{$links{$page}}, IkiWiki::linkpage($1);
49         }
50 }
51
52 1