cook-lang.pl 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # Copyright (C) 2021 Alex Schroeder <alex@gnu.org>
  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('cook-lang.pl', 'Cooklang Extension');
  17. our ($q, $bol, @MyRules);
  18. push(@MyRules, \&CookLangRule);
  19. sub CookLangRule {
  20. if (/\G#([^\n#\@\{\}]+)\{(?:([^\n%\}]+)(?:%([^\n\}]+))?)?\}/cg) {
  21. # #canning funnel{}
  22. my $html = "";
  23. $html .= $q->strong({-title=>"number"}, $2) if $2;
  24. $html .= " " if $2 and $3;
  25. $html .= $q->strong({-title=>"unit"}, $3) if $3;
  26. $html .= " " if $1 and ($2 or $3);
  27. $html .= $q->strong({-title=>"cookware"}, $1);
  28. return $html;
  29. } elsif (/\G#(\w+)/cg) {
  30. # #pot
  31. return $q->strong({-title=>"cookware"}, $1);
  32. } elsif (/\G\@([^\n#\@\{\}]+)\{(?:([^\n%\}]+)(?:%([^\n\}]+))?)?\}/cg) {
  33. # @ground black pepper{}
  34. my $html = "";
  35. $html .= $q->strong({-title=>"number"}, $2) if $2;
  36. $html .= " " if $2 and $3;
  37. $html .= $q->strong({-title=>"unit"}, $3) if $3;
  38. $html .= " " if $1 and ($2 or $3);
  39. $html .= $q->strong({-title=>"ingredient"}, $1);
  40. return $html;
  41. } elsif (/\G\@(\w+)/cg) {
  42. # @salt
  43. return $q->strong({-title=>"ingredient"}, $1);
  44. } elsif (/\G\~\{([^\n%\}]+)(?:%([^\n\}]+))?\}/cg) {
  45. # ~{25%minutes}
  46. my $html = $q->strong({-title=>"number"}, $1);
  47. $html .= " " if $1 and $2;
  48. $html .= $q->strong({-title=>"unit"}, $2) if $2;
  49. return $html;
  50. } elsif (/\G\/\/\s*(.*)/cg) {
  51. # // Don't burn the roux!
  52. return $q->em({-title=>"comment"}, $1);
  53. } elsif ($bol and /\G&gt;&gt;\s*(.*)/cg) {
  54. # // Don't burn the roux!
  55. return CloseHtmlEnvironments()
  56. . $q->blockquote({-title=>"meta"}, $1)
  57. . AddHtmlEnvironment('p');
  58. }
  59. # no match
  60. return;
  61. }