2006-07-26 23:54:44 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# CamelCase links
|
|
|
|
package IkiWiki::Plugin::camelcase;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
2007-04-27 04:55:52 +02:00
|
|
|
use IkiWiki 2.00;
|
2006-07-26 23:54:44 +02:00
|
|
|
|
2008-02-12 05:04:19 +01:00
|
|
|
# This regexp is based on the one in Text::WikiFormat.
|
|
|
|
my $link_regexp=qr{
|
|
|
|
(?<![^A-Za-z0-9\s]) # try to avoid expanding non-links with a
|
|
|
|
# zero width negative lookbehind for
|
|
|
|
# characters that suggest it's not a link
|
|
|
|
\b # word boundry
|
|
|
|
(
|
|
|
|
(?:
|
|
|
|
[A-Z] # Uppercase start
|
|
|
|
[a-z0-9] # followed by lowercase
|
|
|
|
\w* # and rest of word
|
|
|
|
)
|
|
|
|
{2,} # repeated twice
|
|
|
|
)
|
|
|
|
}x;
|
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub import {
|
2008-08-03 22:40:12 +02:00
|
|
|
hook(type => "getsetup", id => "camelcase", call => \&getsetup);
|
2008-02-12 05:04:19 +01:00
|
|
|
hook(type => "linkify", id => "camelcase", call => \&linkify);
|
|
|
|
hook(type => "scan", id => "camelcase", call => \&scan);
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2006-07-26 23:54:44 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub getsetup () {
|
2008-08-03 22:40:12 +02:00
|
|
|
return
|
|
|
|
plugin => {
|
|
|
|
safe => 1,
|
|
|
|
rebuild => undef,
|
2008-12-24 01:11:03 +01:00
|
|
|
},
|
|
|
|
camelcase_ignore => {
|
|
|
|
type => "string",
|
|
|
|
example => [],
|
|
|
|
description => "list of words to not turn into links",
|
|
|
|
safe => 1,
|
|
|
|
rebuild => undef, # might change links
|
|
|
|
},
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2008-08-03 22:40:12 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub linkify (@) {
|
2006-07-26 23:54:44 +02:00
|
|
|
my %params=@_;
|
2008-02-12 05:04:19 +01:00
|
|
|
my $page=$params{page};
|
|
|
|
my $destpage=$params{destpage};
|
2006-07-26 23:54:44 +02:00
|
|
|
|
2008-02-12 05:04:19 +01:00
|
|
|
$params{content}=~s{$link_regexp}{
|
2008-12-24 01:11:03 +01:00
|
|
|
ignored($1) ? $1 : htmllink($page, $destpage, linkpage($1))
|
2008-02-12 05:04:19 +01:00
|
|
|
}eg;
|
2006-07-26 23:54:44 +02:00
|
|
|
|
|
|
|
return $params{content};
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2006-07-26 23:54:44 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub scan (@) {
|
2008-02-12 05:04:19 +01:00
|
|
|
my %params=@_;
|
|
|
|
my $page=$params{page};
|
|
|
|
my $content=$params{content};
|
|
|
|
|
|
|
|
while ($content =~ /$link_regexp/g) {
|
2008-12-24 01:11:03 +01:00
|
|
|
push @{$links{$page}}, linkpage($1) unless ignored($1)
|
2008-02-12 05:04:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-24 01:11:03 +01:00
|
|
|
sub ignored ($) {
|
|
|
|
my $word=lc shift;
|
|
|
|
grep { $word eq lc $_ } @{$config{'camelcase_ignore'}}
|
|
|
|
}
|
|
|
|
|
2006-07-26 23:54:44 +02:00
|
|
|
1
|