<commit_before># Emoticon extension for python-markdown
# Original version :
# https://gist.github.com/insin/815656/raw/a68516f1ffc03df465730b3ddef6de0a11b7e9a5/mdx_emoticons.py
#
# Patched by cgabard for supporting newer python-markdown version and extend for support multi-extensions

import re
import markdown
from markdown.inlinepatterns import Pattern
from markdown.util import etree

class EmoticonExtension(markdown.Extension):
    def __init__ (self, configs):
        self.config = {
            'EMOTICONS': [{
                ":)" : "test.png",
                }, 'A mapping from emoticon symbols to image names.'],
            }

        for key, value in configs.iteritems() :
            self.config[key][0] = value

    def extendMarkdown(self, md, md_globals):
        self.md = md
        EMOTICON_RE = r'(^|\s)(?P<emoticon>%s)(\s|$)' % '|'.join(
            [re.escape(emoticon) for emoticon in self.getConfig('EMOTICONS').keys()])
        md.inlinePatterns.add('emoticons', EmoticonPattern(EMOTICON_RE, self),">not_strong")

class EmoticonPattern(Pattern):
    def __init__ (self, pattern, emoticons):
        Pattern.__init__(self, pattern)
        self.emoticons = emoticons

    def handleMatch(self, m):
        try:
            emoticon = m.group('emoticon')
        except IndexError:
            return None
        el = etree.Element('img')
        el.set('src', '%s' % (self.emoticons.getConfig('EMOTICONS')[emoticon],))
        el.set('alt', emoticon)
        return el

def makeExtension(configs=None) :
    return EmoticonExtension(configs=configs)

<commit_msg>Update emoticons.py<commit_after># Emoticon extension for python-markdown
# Original version :
# https://gist.github.com/insin/815656/raw/a68516f1ffc03df465730b3ddef6de0a11b7e9a5/mdx_emoticons.py
#
# Patched by cgabard for supporting newer python-markdown version and extend for support multi-extensions

import re
import markdown
from markdown.inlinepatterns import Pattern
from markdown.util import etree

class EmoticonExtension(markdown.Extension):
    def __init__ (self, configs):
        self.config = {
            'EMOTICONS': [{
                ":)" : "test.png",
                }, 'A mapping from emoticon symbols to image names.'],
            }

        for key, value in configs.iteritems() :
            self.config[key][0] = value

    def extendMarkdown(self, md, md_globals):
        self.md = md
        EMOTICON_RE = r'(^|(?<=\s))(?P<emoticon>{0})((?=\s)|$)'.format('|'.join(
            [re.escape(emoticon) for emoticon in self.getConfig('EMOTICONS').keys()]))
        md.inlinePatterns.add('emoticons', EmoticonPattern(EMOTICON_RE, self),">not_strong")

class EmoticonPattern(Pattern):
    def __init__ (self, pattern, emoticons):
        Pattern.__init__(self, pattern)
        self.emoticons = emoticons

    def handleMatch(self, m):
        try:
            emoticon = m.group('emoticon')
        except IndexError:
            return None
        el = etree.Element('img')
        el.set('src', '%s' % (self.emoticons.getConfig('EMOTICONS')[emoticon],))
        el.set('alt', emoticon)
        return el

def makeExtension(configs=None) :
    return EmoticonExtension(configs=configs)


{'fraction_non_alphanumeric': 0.12562344139650872, 'fraction_numerical': 0.01839152119700748, 'mean_word_length': 2.9617283950617286, 'pattern_counts': {'":': 2, '<': 6, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4129939', 'n_tokens_mistral': 1078, 'n_tokens_neox': 1037, 'n_words': 216}