Example #1
0
def format_markdown_as_tweet(data):
    def to_twitter_handle(contact, nick):
        """Attempt to replace friendly @name with the official @twitter
        username
        """
        if contact and contact.social:
            nick = contact.social.get('twitter') or nick
        return '@' + nick

    html = util.markdown_filter(data)
    html = util.process_people(to_twitter_handle, html)
    return util.format_as_text(html)
Example #2
0
def format_markdown_as_tweet(data):
    def to_twitter_handle(contact, nick):
        """Attempt to replace friendly @name with the official @twitter
        username
        """
        if contact:
            for url in contact.social:
                m = util.TWITTER_PROFILE_RE.match(url)
                if m:
                    nick = m.group(1)
                    break
        return '@' + nick

    html = util.markdown_filter(data)
    html = util.process_people(to_twitter_handle, html)
    return util.format_as_text(html)
Example #3
0
def format_markdown_as_tweet(data):
    def to_twitter_handle(contact, nick):
        """Attempt to replace friendly @name with the official @twitter
        username
        """
        if contact:
            for url in contact.social:
                m = util.TWITTER_PROFILE_RE.match(url)
                if m:
                    nick = m.group(1)
                    break
        return '@' + nick

    html = util.markdown_filter(data)
    html = util.process_people(to_twitter_handle, html)
    return util.format_as_text(html)
Example #4
0
def test_autolink_people(db):
    """Exercise the @-name matching regex, without contacts
    """
    def simple_name_marker(contact, nick):
        return '<' + nick + '>'

    test_cases = [
        ('@han should be linked', '<han> should be linked'),
        ('[email protected] should not be',
         '[email protected] should not be'),
        ('@leia @luke @han', '<leia> <luke> <han>'),
        ('@leia@luke@han', '@leia@luke@han'),
        ('match a name at the end @kylewm',
         'match a name at the end <kylewm>'),
        ('match a name followed by a period @kylewm.',
         'match a name followed by a period <kylewm>.'),
        ('followed by a @comma, right?', 'followed by a <comma>, right?'),
    ]

    for inp, out in test_cases:
        assert out == util.process_people(simple_name_marker, inp)
Example #5
0
def test_autolink_people(db):
    """Exercise the @-name matching regex, without contacts
    """
    def simple_name_marker(contact, nick):
        return '<' + nick + '>'

    test_cases = [
        ('@han should be linked', '<han> should be linked'),
        ('[email protected] should not be',
         '[email protected] should not be'),
        ('@leia @luke @han', '<leia> <luke> <han>'),
        ('@leia@luke@han', '@leia@luke@han'),
        ('match a name at the end @kylewm',
         'match a name at the end <kylewm>'),
        ('match a name followed by a period @kylewm.',
         'match a name followed by a period <kylewm>.'),
        ('followed by a @comma, right?',
         'followed by a <comma>, right?'),
    ]

    for inp, out in test_cases:
        assert out == util.process_people(simple_name_marker, inp)