styled-pages.pl 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Copyright (C) 2014-2017
  2. # Aleks-Daniel Jakimenko-Aleksejev <alex.jakimenko@gmail.com>
  3. #
  4. # This program is free software: you can redistribute it and/or modify it under
  5. # the terms of the GNU General Public License as published by the Free Software
  6. # Foundation, either version 3 of the License, or (at your option) any later
  7. # version.
  8. #
  9. # This program is distributed in the hope that it will be useful, but WITHOUT
  10. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License along with
  14. # this program. If not, see <http://www.gnu.org/licenses/>.
  15. use strict;
  16. use v5.10;
  17. AddModuleDescription('styled-pages.pl', 'Styled Pages Extension');
  18. our (@MyRules);
  19. our ($StyledPagesPrefix);
  20. $StyledPagesPrefix = 'style_';
  21. push(@MyRules, \&StyledPagesRule);
  22. my $StyledPage = '';
  23. sub StyledPagesRule {
  24. if (!$StyledPage and m/\G (^|\n)? \#STYLE [ \t]+ ([a-z_-][a-z0-9 _-]+[a-z0-9_-]) \s*(\n+|$) /cgx) {
  25. $StyledPage = 1;
  26. return CloseHtmlEnvironments()
  27. . '<div class="' . join(' ', map {"$StyledPagesPrefix$_"} split /\s+/, $2) . '">'
  28. . AddHtmlEnvironment('p');
  29. }
  30. if ($StyledPage and m/\G $/cgx) {
  31. return CloseHtmlEnvironments() . '</div>';
  32. }
  33. return;
  34. }