summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/camelcase.pm
blob: dc89f1b90ec8c039a6ce3adbe8ee03cb60ae30df (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. (?<![[|"/>=]) # try to avoid expanding non-links
  16. # with a zero width negative lookbehind for
  17. # characters that suggest it's not a link
  18. \b # word boundry
  19. (
  20. (?:
  21. [A-Z] # Uppercase start
  22. [a-z0-9] # followed by lowercase
  23. \w* # and rest of word
  24. )
  25. {2,} # repeated twice
  26. )
  27. }{[[$1]]}gx;
  28. return $params{content};
  29. } #}}}
  30. 1