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> nice'
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>'
def test_hashtag_not_processed_if_template_empty(): ptext = 'hello #stuff' htext = convert2html(ptext, False, None) assert htext == 'hello #stuff'
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>'
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'
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'
def test_one_space_does_not_get_converted(): assert convert2html('hello there') == 'hello there'
def test_two_spaces_or_more_get_converted(): assert convert2html('hello there') == 'hello there' assert convert2html('hello there') == 'hello there'
def test_tabs_should_be_four_spaces(): assert convert2html('hello\tdolly') == 'hello dolly'
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>'
def test_mention_not_processed_if_template_empty(): ptext = 'hello @stuff' htext = convert2html(ptext, False, None, None) assert htext == 'hello @stuff'
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)