div-foo.pl 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Copyright (C) 2014 Alex-Daniel Jakimenko <alex.jakimenko@gmail.com>
  2. #
  3. # This program is free software: you can redistribute it and/or modify it under
  4. # the terms of the GNU General Public License as published by the Free Software
  5. # Foundation, either version 3 of the License, or (at your option) any later
  6. # version.
  7. #
  8. # This program is distributed in the hope that it will be useful, but WITHOUT
  9. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License along with
  13. # this program. If not, see <http://www.gnu.org/licenses/>.
  14. use strict;
  15. use v5.10;
  16. AddModuleDescription('div-foo.pl', 'Div Foo Extension');
  17. our (@MyRules);
  18. our ($DivFooPrefix);
  19. our (%RuleOrder);
  20. $DivFooPrefix = 'foo_';
  21. push(@MyRules, \&DivFooRule);
  22. # conflicts with <nowiki> and other such rules by usemod.pl
  23. $RuleOrder{\&DivFooRule} = 200;
  24. sub DivFooRule {
  25. if (m/\G \&lt; ([a-z_-][a-z0-9 _-]+[a-z0-9_-]) \&gt; \s*\n /cgx) {
  26. return CloseHtmlEnvironment('p') . AddHtmlEnvironment('div', 'class="' . join(' ', map {"$DivFooPrefix$_"} split /\s+/, $1) . '"');
  27. }
  28. if (m/\G \&lt; ([a-z_-][a-z0-9 _-]+[a-z0-9_-]) (\?(.*?(?=\&gt;)))? \&gt; /cgx) {
  29. my $title = $3 ? ' title="' . QuoteHtml($3) . '"' : '';
  30. return AddHtmlEnvironment('span', 'class="' . join(' ', map {"$DivFooPrefix$_"} split /\s+/, $1) . '"' . $title);
  31. }
  32. if (m/\G \&lt; \/ \/ \&gt; /cgx) {
  33. return CloseHtmlEnvironment('div') . (InElement('div') ? '' : AddHtmlEnvironment('p'));
  34. }
  35. if (m/\G \&lt; \/ \&gt; /cgx) {
  36. return CloseHtmlEnvironment('span');
  37. }
  38. return;
  39. }