示例#1
0
def test_should_convert_all_the_things():
    ptext = 'hello\tdolly #stuff @blah http://me.com   nice'
    htext = convert2html(ptext, True,
                         'https://twitter/hashtags/{hashtag}',
                         'https://twitter/users/{mention}')
    print(htext)
    assert htext == 'hello    dolly ' + \
        '<a href="https://twitter/hashtags/stuff">#stuff</a> ' + \
        '<a href="https://twitter/users/blah">@blah</a> ' + \
        '<a href="http://me.com">http://me.com</a> &nbsp;&nbsp;nice'
示例#2
0
def test_hashtag_processed_if_template_given():
    ptext = 'hello #stuff'
    htext = convert2html(ptext, False, 'https://twitter/hashtags/{hashtag}')
    assert htext == 'hello <a href="https://twitter/hashtags/stuff">#stuff</a>'
示例#3
0
def test_hashtag_not_processed_if_template_empty():
    ptext = 'hello #stuff'
    htext = convert2html(ptext, False, None)
    assert htext == 'hello #stuff'
示例#4
0
def test_links_autolinked_if_url_linking_on():
    ptext = 'hello http://example.com'
    htext = convert2html(ptext, True)
    assert htext == 'hello <a href="http://example.com">http://example.com</a>'
示例#5
0
def test_links_not_autolinked_if_url_linking_off():
    ptext = 'hello http://example.com'
    htext = convert2html(ptext, False)
    print(htext)
    assert htext == 'hello http://example.com'
示例#6
0
def test_newline_and_cr_converted_to_br():
    assert convert2html('hello\nthere') == 'hello<br/>there'
    assert convert2html('hello\r\nthere') == 'hello<br/>there'
    assert convert2html('hello\r\n\nthere') == 'hello<br/><br/>there'
示例#7
0
def test_one_space_does_not_get_converted():
    assert convert2html('hello there') == 'hello there'
示例#8
0
def test_two_spaces_or_more_get_converted():
    assert convert2html('hello  there') == 'hello &nbsp;there'
    assert convert2html('hello   there') == 'hello &nbsp;&nbsp;there'
示例#9
0
def test_tabs_should_be_four_spaces():
    assert convert2html('hello\tdolly') == 'hello &nbsp;&nbsp;&nbsp;dolly'
示例#10
0
def test_mention_processed_if_template_given():
    ptext = 'hello @stuff'
    htext = convert2html(ptext, False, None, 'https://twitter/users/{mention}')
    assert htext == 'hello <a href="https://twitter/users/stuff">@stuff</a>'
示例#11
0
def test_mention_not_processed_if_template_empty():
    ptext = 'hello @stuff'
    htext = convert2html(ptext, False, None, None)
    assert htext == 'hello @stuff'
示例#12
0
def notedown(text, settings):
    url_linking_disabled = settings.get('NOTEDOWN_DISABLE_URL_AUTOLINKING')
    hashtag_template = settings.get('NOTEDOWN_HASHTAG_TEMPLATE')
    mention_template = settings.get('NOTEDOWN_MENTION_TEMPLATE')
    return convert2html(text, not url_linking_disabled, hashtag_template,
                        mention_template)