Exemplo n.º 1
0
 def test_replace_digits(self):
     """
     It should not match single digits
     """
     txt = '#*0123456789'
     res = replace(txt, lambda emoji: '')
     self.assertEqual(res, txt)
Exemplo n.º 2
0
 def test_replace_text_variations(self):
     """
     It should not match emojis with text variation
     """
     txt = '\u203C\uFE0E'
     res = replace(txt, lambda emoji: '')
     self.assertEqual(res, txt)
Exemplo n.º 3
0
 def test_replace_text_variations(self):
     """
     It should not match emojis with text variation
     """
     txt = '\u203C\uFE0E'
     res = replace(txt, lambda emoji: '')
     self.assertEqual(res, txt)
Exemplo n.º 4
0
def replace_emoji(effect, style):
    # t = text.encode('unicode-escape')
    # Würfel Icon
    # Figure icon
    # Alle bauen/roten icons für general/sage
    # Replace text
    # TODO Case insensitive

    try:
        t = emoji_unicode.replace(
            effect,
            # lambda e: u"<img src='images/{filename}.svg' valign='middle' width = '20' height = '20' alt= '{raw}' />".format(filename=emoji_dict[e.code_points], raw=e.unicode)
            lambda e: u"<img src='images/{filename}.png' valign='middle' width = '20' height = '20' />".format(filename=emoji_dict[e.code_points])
        )
        t = replace_with_emoji(t, style.fontSize)
    except KeyError:
        print("Key Error")
#        t = emoji_unicode.replace(
#            text,
#            # lambda e: u"<img src='images/{filename}.svg' valign='middle' width = '20' height = '20' alt= '{raw}' />".format(filename=emoji_dict[e.code_points], raw=e.unicode)
#            lambda e: u"<font name=Symbola>{raw}</font>".format(raw=e.unicode)
#        )
        # t = replace_with_emoji_pdf(Emoji.to_image(text), style.fontSize)
        t = replace_with_emoji(effect, style.fontSize)
    return(t)
Exemplo n.º 5
0
 def test_replace_digits(self):
     """
     It should not match single digits
     """
     txt = '#*0123456789'
     res = replace(txt, lambda emoji: '')
     self.assertEqual(res, txt)
Exemplo n.º 6
0
def replace_emoji(effect, style):
    # t = text.encode('unicode-escape')
    # Würfel Icon
    # Figure icon
    # Alle bauen/roten icons für general/sage
    # Replace text
    # TODO Case insensitive

    try:
        t = emoji_unicode.replace(
            effect,
            # lambda e: u"<img src='images/{filename}.svg' valign='middle' width = '20' height = '20' alt= '{raw}' />".format(filename=emoji_dict[e.code_points], raw=e.unicode)
            lambda e: u"<img src='images/{filename}.png' valign='middle' width = '20' height = '20' />".format(filename=emoji_dict[e.code_points])
        )
        t = replace_with_emoji(t, style.fontSize)
    except KeyError:
        print("Key Error")
#        t = emoji_unicode.replace(
#            text,
#            # lambda e: u"<img src='images/{filename}.svg' valign='middle' width = '20' height = '20' alt= '{raw}' />".format(filename=emoji_dict[e.code_points], raw=e.unicode)
#            lambda e: u"<font name=Symbola>{raw}</font>".format(raw=e.unicode)
#        )
        # t = replace_with_emoji_pdf(Emoji.to_image(text), style.fontSize)
        t = replace_with_emoji(effect, style.fontSize)
    return(t)
Exemplo n.º 7
0
    def test_replace(self):
        """
        It should replace all emojis
        """
        emojis = get_emojis()

        # With no spaces will fail due to fitzpatrick tone being a modifier and also a emoji
        txt = ' '.join(get_emojis_unicode())
        txt_code_points = ' '.join(normalize(e['code_point']) for e in emojis)
        res = replace(txt, lambda emoji: emoji.code_points)
        self.assertEqual(res, txt_code_points)
Exemplo n.º 8
0
    def test_replace(self):
        """
        It should replace all emojis
        """
        emojis = get_emojis()

        # With no spaces will fail due to fitzpatrick tone being a modifier and also a emoji
        txt = ' '.join(get_emojis_unicode())
        txt_code_points = ' '.join(normalize(e['code_point']) for e in emojis)
        res = replace(txt, lambda emoji: emoji.code_points)
        self.assertEqual(res, txt_code_points)
Exemplo n.º 9
0
 def test_replace_with_no_fitz(self):
     """
     It should replace no-spaced emojis, excluding fitzpatrick tone emojis
     """
     emojis = get_emojis()
     txt = ''.join(e['unicode'] for e in emojis
                   if 'skin-tone' not in e['short_name'])
     txt_code_points = ''.join(
         normalize(e['code_point']) for e in emojis
         if 'skin-tone' not in e['short_name'])
     res = replace(txt, lambda emoji: emoji.code_points)
     self.assertEqual(res, txt_code_points)
Exemplo n.º 10
0
 def test_replace_with_no_fitz(self):
     """
     It should replace no-spaced emojis, excluding fitzpatrick tone emojis
     """
     emojis = get_emojis()
     txt = ''.join(
         e['unicode']
         for e in emojis
         if 'skin-tone' not in e['short_name']
     )
     txt_code_points = ''.join(
         normalize(e['code_point'])
         for e in emojis
         if 'skin-tone' not in e['short_name']
     )
     res = replace(txt, lambda emoji: emoji.code_points)
     self.assertEqual(res, txt_code_points)
Exemplo n.º 11
0
def convert(content: str):
    """Perform actual code conversion to add presentation capabilities."""
    soup = BeautifulSoup(content)

    tag = soup.new_tag('style')
    with open('presentation.css', 'r') as f:
        tag.string = f.read()

    soup.style.insert_before(tag)

    content = str(soup)

    content = emoji_unicode.replace(
        content,
        lambda e: u'<img class="emoji" src="noto-emoji/png/128/emoji_u{filename}.png" data-alt="{raw}">'.format(
            filename=e.code_points, raw=e.unicode)
    )

    return content
Exemplo n.º 12
0
 def test_replace_remove(self):
     txt = ''.join(get_emojis_unicode())
     res = replace(txt, lambda emoji: '')
     self.assertEqual(res, '')
Exemplo n.º 13
0
def emojify(text):
    return emoji_unicode.replace(
        text,
        lambda e: EMOJI_TPL.format(filename=e.code_points, raw=e.unicode))
Exemplo n.º 14
0
def clean(html):
    out = clean_html(html)
    return emoji_unicode.replace(
        out, lambda e: EMOJI_TPL.format(filename=e.code_points, raw=e.unicode))
Exemplo n.º 15
0
 def test_replace_remove(self):
     txt = ''.join(get_emojis_unicode())
     res = replace(txt, lambda emoji: '')
     self.assertEqual(res, '')