2 次代碼提交 104a1395e7 ... cd9246ebed

作者 SHA1 備註 提交日期
  Alex Schroeder cd9246ebed Add Cooklang extension 3 年之前
  Alex Schroeder f7b23d854f ban-contributors: test Net::IP use 3 年之前
共有 2 個文件被更改,包括 74 次插入0 次删除
  1. 66 0
      modules/cook-lang.pl
  2. 8 0
      t/ban-contributors.t

+ 66 - 0
modules/cook-lang.pl

@@ -0,0 +1,66 @@
+# Copyright (C) 2021  Alex Schroeder <alex@gnu.org>
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 3 of the License, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program. If not, see <http://www.gnu.org/licenses/>.
+
+use strict;
+use v5.10;
+
+AddModuleDescription('cook-lang.pl', 'Cooklang Extension');
+
+our ($q, $bol, @MyRules);
+
+push(@MyRules, \&CookLangRule);
+
+sub CookLangRule {
+  if (/\G#([^\n#\@\{\}]+)\{(?:([^\n%\}]+)(?:%([^\n\}]+))?)?\}/cg) {
+    # #canning funnel{}
+    my $html = "";
+    $html .= $q->strong({-title=>"number"}, $2) if $2;
+    $html .= " " if $2 and $3;
+    $html .= $q->strong({-title=>"unit"}, $3) if $3;
+    $html .= " " if $1 and ($2 or $3);
+    $html .= $q->strong({-title=>"cookware"}, $1);
+    return $html;
+  } elsif (/\G#(\w+)/cg) {
+    # #pot
+    return $q->strong({-title=>"cookware"}, $1);
+  } elsif (/\G\@([^\n#\@\{\}]+)\{(?:([^\n%\}]+)(?:%([^\n\}]+))?)?\}/cg) {
+    # @ground black pepper{}
+    my $html = "";
+    $html .= $q->strong({-title=>"number"}, $2) if $2;
+    $html .= " " if $2 and $3;
+    $html .= $q->strong({-title=>"unit"}, $3) if $3;
+    $html .= " " if $1 and ($2 or $3);
+    $html .= $q->strong({-title=>"ingredient"}, $1);
+    return $html;
+  } elsif (/\G\@(\w+)/cg) {
+    # @salt
+    return $q->strong({-title=>"ingredient"}, $1);
+  } elsif (/\G\~\{([^\n%\}]+)(?:%([^\n\}]+))?\}/cg) {
+    # ~{25%minutes}
+    my $html = $q->strong({-title=>"number"}, $1);
+    $html .= " " if $1 and $2;
+    $html .= $q->strong({-title=>"unit"}, $2) if $2;
+    return $html;
+  } elsif (/\G\/\/\s*(.*)/cg) {
+    # // Don't burn the roux!
+    return $q->em({-title=>"comment"}, $1);
+  } elsif ($bol and /\G&gt;&gt;\s*(.*)/cg) {
+    # // Don't burn the roux!
+    return CloseHtmlEnvironments()
+	. $q->blockquote({-title=>"meta"}, $1)
+	. AddHtmlEnvironment('p');
+  }
+  # no match
+  return;
+}

+ 8 - 0
t/ban-contributors.t

@@ -15,6 +15,7 @@
 require './t/test.pl';
 package OddMuse;
 use Test::More;
+use Net::IP;
 
 add_module('ban-contributors.pl');
 
@@ -43,6 +44,13 @@ is(BanContributors::get_regexp_ip('45.87.2.128', '45.87.2.255'),
    '^45\.87\.2\.(12[8-9]|1[3-9][0-9]|2[0-4][0-9]|25[0-5])',
    '45.87.2.128 - 45.87.2.255');
 
+# 191.101.0.0/16
+# verify that Net::IP works as intended
+my $ip = Net::IP->new('191.101.0.0/16');
+ok($ip, 'Net::IP parsed CIDR');
+is($ip->ip, '191.101.0.0', 'First IP in range');
+is($ip->last_ip, '191.101.255.255', 'Last IP in range');
+
 $localhost = '127.0.0.1';
 $ENV{'REMOTE_ADDR'} = $localhost;