]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/camelcase.pm
cherry-pick uri security fix
[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 sub import { #{{{
10         hook(type => "filter", id => "camelcase", call => \&filter);
11 } # }}}
13 sub filter (@) { #{{{
14         my %params=@_;
16         # Make CamelCase links work by promoting them to fullfledged
17         # WikiLinks. This regexp is based on the one in Text::WikiFormat.
18         $params{content}=~s{
19                 (?<![^A-Za-z0-9\s])     # try to avoid expanding non-links
20                                         # with a zero width negative
21                                         # lookbehind for characters that
22                                         # suggest it's not a link
23                 \b                      # word boundry
24                 (
25                         (?:
26                                 [A-Z]           # Uppercase start
27                                 [a-z0-9]        # followed by lowercase
28                                 \w*             # and rest of word
29                         )
30                         {2,}                    # repeated twice
31                 )
32         }{[[$1]]}gx;
34         return $params{content};
35 } #}}}
37 1