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