add paths to plugin files in copyright
[ikiwiki.git] / IkiWiki / Plugin / camelcase.pm
blob088447d6b4d133d0197e6bc3c1df57fd9c3292e8
1 #!/usr/bin/perl
2 # CamelCase links
3 package IkiWiki::Plugin::camelcase;
5 use warnings;
6 use strict;
7 use IkiWiki 3.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
16 (?:
17 [A-Z] # Uppercase start
18 [a-z0-9] # followed by lowercase
19 \w* # and rest of word
21 {2,} # repeated twice
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);
31 sub getsetup () {
32 return
33 plugin => {
34 safe => 1,
35 rebuild => undef,
37 camelcase_ignore => {
38 type => "string",
39 example => [],
40 description => "list of words to not turn into links",
41 safe => 1,
42 rebuild => undef, # might change links
46 sub linkify (@) {
47 my %params=@_;
48 my $page=$params{page};
49 my $destpage=$params{destpage};
51 $params{content}=~s{$link_regexp}{
52 ignored($1) ? $1 : htmllink($page, $destpage, linkpage($1))
53 }eg;
55 return $params{content};
58 sub scan (@) {
59 my %params=@_;
60 my $page=$params{page};
61 my $content=$params{content};
63 while ($content =~ /$link_regexp/g) {
64 add_link($page, linkpage($1)) unless ignored($1)
68 sub ignored ($) {
69 my $word=lc shift;
70 grep { $word eq lc $_ } @{$config{'camelcase_ignore'}}