Example #1
0
 def test_replace_digits(self):
     """
     It should not match single digits
     """
     txt = '#*0123456789'
     res = replace(txt, lambda emoji: '')
     self.assertEqual(res, txt)
Example #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)
 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)
Example #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)
 def test_replace_digits(self):
     """
     It should not match single digits
     """
     txt = '#*0123456789'
     res = replace(txt, lambda emoji: '')
     self.assertEqual(res, txt)
Example #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)
Example #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)
    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)
 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)
Example #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)
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
Example #12
0
 def test_replace_remove(self):
     txt = ''.join(get_emojis_unicode())
     res = replace(txt, lambda emoji: '')
     self.assertEqual(res, '')
Example #13
0
def emojify(text):
    return emoji_unicode.replace(
        text,
        lambda e: EMOJI_TPL.format(filename=e.code_points, raw=e.unicode))
Example #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))
 def test_replace_remove(self):
     txt = ''.join(get_emojis_unicode())
     res = replace(txt, lambda emoji: '')
     self.assertEqual(res, '')