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