UseModWiki | WikiPatches | RecentChanges | Preferences

This patch translates smilies such as :-) into HTML code as follows:

    <img src="/pics/smile.png" alt=":-)">

You can test it on the EmacsWiki:SandBox.

You can get the icons I used from http://www.emacswiki.org/pics. These are from the Gnus distribution and under the GPL. -- AlexSchroeder

You can get more icons from: http://helios.wmid.amu.edu.pl/~sheep/pictures/Smilies%20-%20scalable.html




New variables:

   # Configuration/constant variables:
   use vars qw(... $UseSmilies %Smilies);

New minor option:

    # Minor options:
    $UseSmilies  = 1;       # 1 = use smily pictures  0 = do not change :-) etc. 

Init the Smilies variable at the end of InitLinkPatterns:

    sub InitLinkPatterns {
      if ($UseSmilies) {
          %Smilies = (
              ":-?\\)(?=\\W)"    => "/pics/smile.png",
              ";-?\\)(?=\\W)"    => "/pics/blink.png",
              ":-?](?=\\W)"     => "/pics/forced.png",
              "8-?\\)(?=\\W)"    => "/pics/braindamaged.png",
              ":-\\|(?=\\W)"     => "/pics/indifferent.png",
              ":-?[/\\\\](?=\\W)"  => "/pics/wry.png",
              ":-?\\((?=\\W)"     => "/pics/sad.png",
              ":-?\\((?=\\W)"     => "/pics/frown.png",

And in the middle of CommonMarkup, do the stuff:

    sub CommonMarkup {
        if ($ThinLine) {
          s/----+/<hr noshade size=1>/g;
          s/====+/<hr noshade size=2>/g;
        } else {
        if ($UseSmilies) {
            foreach my $regexp (keys %Smilies) {
                s/$regexp/<img src="$Smilies{$regexp}" alt="$&">/g;
      if ($doLines) { # 0 = no line-oriented, 1 or 2 = do line-oriented
        # The quote markup patterns avoid overlapping tags (with 5 quotes)
        # by matching the inner quotes for the strong pattern.


I've added a bunch of new smilies to that list, but there is one particular one that is failing. I've added ":-?\\>(?=\\W)" as a key to the list but it never converts :> or :-> to a smile. Can anybody explain to me why Perl refuses to parse a smile with a > in it? I'm kind of new at this. I'm guessing Perl is confusing the < and > as part of some sort of reference or assignment? ~SL

This is probably because the characters '<', '>' and '&' have already been converted to their HTML-escaped equivalents '&lt;', '&gt;' and '&amp;' before the smiley translation is done. You will therefore have to allow for this for any smilies containing these characters e.g. your example would be ":-?\\&gt;(?=\\W)" --DavidClaughton.
What is "$&" at: s/$regexp/<img src="$Smilies{$regexp}" alt="$&">/g;? --JuanmaMP (2009.11.21)

$& refers to the entire matched string, here by $regexp. Here this will be the smiley. Also see "man perlre". -- MarkusLude

It seems not to work well on my local wiki but, at least, now I know what the output should be. Thanks for the information on documentation. -- JuanmaMP

UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited December 15, 2010 5:30 pm by JuanmaMP (diff)