]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/camelcase.pm
po: add comments
[git.ikiwiki.info.git] / IkiWiki / Plugin / camelcase.pm
1 #!/usr/bin/perl
2 # CamelCase links
3 package IkiWiki::Plugin::camelcase;
5 use warnings;
6 use strict;
7 use IkiWiki 2.00;
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;
25 sub import { #{{{
26         hook(type => "getsetup", id => "camelcase", call => \&getsetup);
27         hook(type => "linkify", id => "camelcase", call => \&linkify);
28         hook(type => "scan", id => "camelcase", call => \&scan);
29 } # }}}
31 sub getsetup () { #{{{
32         return
33                 plugin => {
34                         safe => 1,
35                         rebuild => undef,
36                 };
37 } #}}}
39 sub linkify (@) { #{{{
40         my %params=@_;
41         my $page=$params{page};
42         my $destpage=$params{destpage};
44         $params{content}=~s{$link_regexp}{
45                 htmllink($page, $destpage, linkpage($1))
46         }eg;
48         return $params{content};
49 } #}}}
51 sub scan (@) { #{{{
52         my %params=@_;
53         my $page=$params{page};
54         my $content=$params{content};
56         while ($content =~ /$link_regexp/g) {
57                 push @{$links{$page}}, linkpage($1);
58         }
59 }
61 1