Files
oddmuse/modules/grep.pl

50 lines
1.3 KiB
Perl
Raw Normal View History

# Copyright (C) 2006 Alex Schroeder <alex@emacswiki.org>
2006-02-15 07:24:10 +00:00
#
# 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
2006-02-15 07:24:10 +00:00
# (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/>.
2006-02-15 07:24:10 +00:00
use strict;
use v5.10;
AddModuleDescription('grep.pl');
2006-02-15 07:24:10 +00:00
2015-04-10 13:31:28 +03:00
our ($q, @MyRules);
2006-02-15 07:24:10 +00:00
push(@MyRules, \&GrepRule);
sub GrepRule {
if (/\G(&lt;grep "(.*?)"&gt;)/cgis) {
# <search "regexp">
Clean(CloseHtmlEnvironments());
Dirty($1);
my $oldpos = pos;
print '<ul class="grep">';
PrintGrep($2);
print '</ul>';
pos = $oldpos; # restore \G after searching
return '';
2006-02-15 07:24:10 +00:00
}
return;
2006-02-15 07:24:10 +00:00
}
sub PrintGrep {
my $regexp = shift;
foreach my $id (AllPagesList()) {
my $text = GetPageContent($id);
next if (TextIsFile($text)); # skip files
while ($text =~ m{($regexp)}gi) {
2006-02-15 07:24:10 +00:00
print $q->li(GetPageLink($id) . ': ' . $1);
}
}
}