Modify

Opened 16 years ago

Last modified 11 years ago

#2123 new defect

Installing Emoticons Can Damage Existing Text (i.e. Dialing codes '(8)' )

Reported by: ryan.gossink@… Owned by: Olemis Lang
Priority: normal Component: EmoticonsPlugin
Severity: normal Keywords:
Cc: Trac Release: 0.10

Description

The following change addreses his by requiring emoticons be encapsulated in square brackets before being parsed by the plugin:

# -*- coding: utf-8 -*-
#
# Copyright (C) 2005 Christopher Lenz <cmlenz@gmx.de>
#
# 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 2 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, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

import re
from pkg_resources import resource_filename

from trac.core import *
from trac.util import escape
from trac.web.chrome import ITemplateProvider
from trac.wiki import IWikiSyntaxProvider

EMOTICONS = {
    ':/': 'annoyed.png', ':-/': 'annoyed.png',
    '8)': 'cool.png', '8-)': 'cool.png', 'B)': 'cool.png', 'B-)': 'cool.png',
    ':(': 'frown.png', ':-(': 'frown.png',
    ':D': 'happy.png', ':-D': 'happy.png',
    ':P': 'razz.png', ':-P': 'razz.png',
    ':)': 'smile.png', ':-)': 'smile.png',
    ':|': 'stoic.png', ':-|': 'stoic.png',
    ':O': 'suprised.png', ':o': 'suprised.png', ':-O': 'suprised.png',
    ':-o': 'suprised.png',
    ';)': 'wink.png', ';-)': 'wink.png'
}


class EmoticonsSupport(Component):
    """Provides support for graphical emoticons in wiki-formatted text."""

    implements(ITemplateProvider, IWikiSyntaxProvider)

    # ITemplateProvider methods

    def get_htdocs_dirs(self):
        """Return the directories containing static resources."""
        return [('emoticons', resource_filename(__name__, 'icons'))]

    def get_templates_dirs(self):
        return []

    # IWikiSyntaxProvider methods

    def get_wiki_syntax(self):
        """Replace textual patterns representing emoticons with the
        corresponding icon."""
        def _replace(formatter, namespace, match):
            src = self.env.href.chrome('emoticons', EMOTICONS[match.group(0)[1:-1]])
            return '<img src="%s" alt="%s" class="emoticon" width="18" ' \
                   'height="18" style="vertical-align: middle" />' % (
                   escape(src), escape(match.group(0)))
        pattern = '|'.join([re.escape('[' + pattern + ']') for pattern in EMOTICONS])
        yield '\b' + pattern + '\b', _replace

    def get_link_resolvers(self):
        return []

Attachments (0)

Change History (4)

comment:1 Changed 13 years ago by Ryan J Ollos

Reporter: changed from anonymousryan.gossink@… to ryan.gossink@…

comment:2 Changed 13 years ago by Ryan J Ollos

Owner: changed from Christopher Lenz to Ryan J Ollos
Status: newassigned

comment:3 Changed 12 years ago by Ryan J Ollos

Owner: changed from Ryan J Ollos to anonymous
Status: assignednew

comment:4 Changed 11 years ago by Ryan J Ollos

Owner: changed from anonymous to Olemis Lang

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The owner will remain Olemis Lang.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.