2 package IkiWiki::Plugin::smiley;
12 add_underlay("smiley");
13 hook(type => "filter", id => "smiley", call => \&filter);
16 sub build_regexp () { #{{{
17 my $list=readfile(srcfile("smileys.mdwn"));
18 while ($list =~ m/^\s*\*\s+\\([^\s]+)\s+\[\[([^]]+)\]\]/mg) {
23 debug(gettext("failed to parse any smileys"));
28 # sort and reverse so that substrings come after longer strings
29 # that contain them, in most cases.
30 $smiley_regexp='('.join('|', map { quotemeta }
31 reverse sort keys %smileys).')';
32 #debug($smiley_regexp);
38 build_regexp() unless defined $smiley_regexp;
41 return $_ unless length $smiley_regexp;
43 MATCH: while (m{(?:^|(?<=\s))(\\?)$smiley_regexp(?:(?=\s)|$)}g) {
49 # Smilies are not allowed inside <pre> or <code>.
50 # For each tag in turn, match forward to find the next <tag>
51 # or </tag> after the smiley.
53 foreach my $tag ("pre", "code") {
54 if (m/.*?<(\/)?\s*$tag\s*>/isg && defined $1) {
55 # </tag> found first, so the smiley is
56 # inside the tag, so do not expand it.
59 # Reset pos back to where it was before this test.
65 substr($_, $epos, 1)="";
68 # Replace the smiley with its expanded value.
69 substr($_, $spos, length($smiley))=
70 htmllink($params{page}, $params{destpage},
71 $smileys{$smiley}, linktext => $smiley);