def test_block_quotes_preceded_by_spaces(self): markdown = self.r( 'A wise man once said:\n\n' \ ' > Isn\'t it wonderful just to be alive.\n') ok(markdown).diff( '<p>A wise man once said:</p>\n\n' \ '<blockquote>\n<p>Isn't it wonderful just to be alive.</p>\n</blockquote>\n')
def test_tables(self): text = ' aaa | bbbb\n' \ '-----|------\n' \ 'hello|sailor\n' ok(self.render_with(text)).not_contains('<table') ok(self.render_with(text, extensions=EXT_TABLES)).contains('<table')
def test_html_block_end_tag_on_same_line(self): markdown = self.r( 'Para 1\n\n<div><pre>HTML block\n</pre></div>\n\nPara 2 [Link](#anchor)' ) ok(markdown).diff( '<p>Para 1</p>\n\n<div><pre>HTML block\n</pre></div>\n\n<p>Para 2 <a href=\"#anchor\">Link</a></p>\n' )
def test_autolinking_with_ent_chars(self): markdown = self.render_with( 'This a stupid link: https://github.com/rtomayko/tilt/issues?milestone=1&state=open', extensions=EXT_AUTOLINK) ok(markdown).diff( '<p>This a stupid link: <a href=\"https://github.com/rtomayko/tilt/issues?milestone=1&state=open\">https://github.com/rtomayko/tilt/issues?milestone=1&state=open</a></p>\n' )
def test_whitespace_after_urls(self): markdown = self.render_with( 'Japan: http://www.abc.net.au/news/events/japan-quake-2011/beforeafter.htm (yes, japan)', extensions=EXT_AUTOLINK) ok(markdown).diff( '<p>Japan: <a href="http://www.abc.net.au/news/events/japan-quake-2011/beforeafter.htm">http://www.abc.net.au/news/events/japan-quake-2011/beforeafter.htm</a> (yes, japan)</p>\n' )
def test_headings_with_trailing_space(self): markdown = self.render_with( 'The Ant-Sugar Tales \n' \ '=================== \n\n' \ 'By Candice Yellowflower \n', extensions=EXT_LAX_HTML_BLOCKS) ok(markdown).diff('<h1>The Ant-Sugar Tales </h1>\n\n<p>By Candice Yellowflower </p>\n')
def test_block_quotes(self): text = self.br.render( 'A wise man once said:\n\n' ' > Isn\'t it wonderful just to be alive.\n') ok(text).diff('<p>A wise man once said:</p>\n' '<blockquote cite="my">\n' '<p>Isn't it wonderful just to be alive.</p>\n</blockquote>')
def test_intra_emphasis(self): markdown = self.r('foo_bar_baz') ok(markdown).diff('<p>foo<em>bar</em>baz</p>\n') markdown = self.render_with('foo_bar_baz', extensions=EXT_NO_INTRA_EMPHASIS) ok(markdown).diff('<p>foo_bar_baz</p>\n')
def test_inline_markdown_start_end(self): markdown = self.render_with('_start _ foo_bar bar_baz _ end_ *italic* **bold** <a>_blah_</a>', extensions=EXT_NO_INTRA_EMPHASIS) ok(markdown).diff('<p><em>start _ foo_bar bar_baz _ end</em> <em>italic</em> <strong>bold</strong> <a><em>blah</em></a></p>\n') markdown = self.r('Run \'rake radiant:extensions:rbac_base:migrate\'') ok(markdown).diff('<p>Run 'rake radiant:extensions:rbac_base:migrate'</p>\n')
def test_whitespace_after_urls(self): markdown = self.render_with('Japan: http://www.abc.net.au/news/events/' 'japan-quake-2011/beforeafter.htm (yes, japan)', extensions=EXT_AUTOLINK) ok(markdown).diff('<p>Japan: <a href="http://www.abc.net.au/news/events/' 'japan-quake-2011/beforeafter.htm">http://www.abc.net.' 'au/news/events/japan-quake-2011/beforeafter.htm</a> (yes, japan)</p>\n')
def test_infinite_loop_in_header(self): markdown = self.render_with( '######\n' \ '#Body#\n' \ '######\n', extensions=EXT_LAX_HTML_BLOCKS) ok(markdown).diff('<h1>Body</h1>\n')
def test_html_block_not_wrapped_in_p(self): markdown = self.render_with( 'Things to watch out for\n\n' \ '<ul>\n<li>Blah</li>\n</ul>\n', extensions=EXT_LAX_SPACING) ok(markdown).diff( '<p>Things to watch out for</p>\n\n' \ '<ul>\n<li>Blah</li>\n</ul>\n')
def test_hard_wrap(self): markdown = self.render_with(HTML_HARD_WRAP, ''' Hello world, this is just a simple test With hard wraps and other *things*.''') ok(markdown).contains('<br>')
def test_autolinking_with_ent_chars(self): markdown = self.render_with('This a stupid link: https://github.com/' 'rtomayko/tilt/issues?milestone=1&state=open', extensions=EXT_AUTOLINK) ok(markdown).diff('<p>This a stupid link: <a href=\"https://github.com/' 'rtomayko/tilt/issues?milestone=1&state=open\">' 'https://github.com/rtomayko/tilt/issues?milestone=1' '&state=open</a></p>\n')
def test_html_block_not_wrapped_in_p(self): markdown = self.render_with( 'Things to watch out for\n' \ '<ul>\n<li>Blah</li>\n</ul>\n', extensions=EXT_LAX_HTML_BLOCKS) ok(markdown).diff( '<p>Things to watch out for</p>\n\n' \ '<ul>\n<li>Blah</li>\n</ul>\n')
def test_headings_with_trailing_space(self): markdown = self.render_with( 'The Ant-Sugar Tales \n' \ '=================== \n\n' \ 'By Candice Yellowflower \n') ok(markdown).diff( '<h1>The Ant-Sugar Tales </h1>\n\n<p>By Candice Yellowflower </p>\n' )
def test_hard_wrap(self): markdown = self.render_with( HTML_HARD_WRAP, ''' Hello world, this is just a simple test With hard wraps and other *things*.''') ok(markdown).contains('<br>')
def test_unicode(self): tests_dir = path.dirname(__file__) with codecs.open(path.join(tests_dir, 'unicode.txt'), 'r', encoding='utf-8') as fd: text = fd.read() with codecs.open(path.join(tests_dir, 'unicode.html'), 'r', encoding='utf-8') as fd: html = fd.read() markdown = self.r(text) ok(markdown).diff(html)
def test_inline_markdown_start_end(self): markdown = self.render_with( '_start _ foo_bar bar_baz _ end_ *italic* **bold** <a>_blah_</a>', extensions=EXT_NO_INTRA_EMPHASIS) ok(markdown).diff( '<p><em>start _ foo_bar bar_baz _ end</em> <em>italic</em> <strong>bold</strong> <a><em>blah</em></a></p>\n' ) markdown = self.r('Run \'rake radiant:extensions:rbac_base:migrate\'') ok(markdown).diff( '<p>Run 'rake radiant:extensions:rbac_base:migrate'</p>\n')
def test(): with codecs.open(text_path, 'r', encoding='utf-8') as fd: text = fd.read() with codecs.open(html_path, 'r', encoding='utf-8') as fd: expected_html = fd.read() actual_html = self.r(text) expected_result = clean_html(expected_html) actual_result = clean_html(actual_html) ok(actual_result).diff(expected_result)
def test_fenced_code_blocks(self): text = ''' This is a simple test ~~~~~ This is some awesome code with tabs and shit ~~~ ''' ok(self.render_with(text)).not_contains('<code') ok(self.render_with(text, extensions=EXT_FENCED_CODE)).contains('<code')
def test_escape_html(self): source = ''' Through <em>NO</em> <script>DOUBLE NO</script> <script>BAD</script> <img src="/favicon.ico" /> ''' expected = clean_html(''' <p>Through <em>NO</em> <script>DOUBLE NO</script></p> <p><script>BAD</script></p> <p><img src="/favicon.ico" /></p> ''') markdown = clean_html(self.render_with(HTML_ESCAPE, source)) ok(markdown).diff(expected)
def test_get_and_set(self): self.db.get('test_get_and_set', callback=self.stop) ok(self.wait()) == None self.db.set('test_get_and_set', 'value', callback=self.stop) ok(self.wait()) == 'OK' self.db.get('test_get_and_set', callback=self.stop) ok(self.wait()) == 'value'
def test_exists(self): self.db.set('test_exists', 'value', callback=self.stop) ok(self.wait()) == 'OK' self.db.exists('test_exists', callback=self.stop) ok(self.wait()) == 1 self.db.exists('test_not_exists', callback=self.stop) ok(self.wait()) == 0
def test_fenced_code_blocks_without_space(self): text = 'foo\nbar\n```\nsome\ncode\n```\nbaz' ok(self.render_with(text)).not_contains('<pre><code>') ok(self.render_with(text, extensions=EXT_FENCED_CODE | EXT_LAX_SPACING)).contains('<pre><code>')
def test_single_quotes_d(self): html = self.r('<p>what\'d you say?</p>\n') ok(html).diff('<p>what’d you say?</p>\n')
def test_single_quotes_ve(self): html = self.r('<p>I\'ve been meaning to tell you ..</p>\n') ok(html).diff('<p>I’ve been meaning to tell you ..</p>\n')
def test_single_quotes_ll(self): html = self.r('<p>Well that\'ll be the day</p>\n') ok(html).diff('<p>Well that’ll be the day</p>\n')
def test_spaced_headers(self): text = '#123 a header yes\n' ok(self.render_with(text, extensions=EXT_SPACE_HEADERS)).not_contains('<h1>')
def test_html_block_end_tag_on_same_line(self): markdown = self.r('Para 1\n\n<div><pre>HTML block\n</pre></div>\n\nPara 2 [Link](#anchor)') ok(markdown).diff('<p>Para 1</p>\n\n<div><pre>HTML block\n</pre></div>\n\n<p>Para 2 <a href=\"#anchor\">Link</a></p>\n')
def test_autolink(self): markdown = self.render_with('http://axr.vg/', extensions=EXT_AUTOLINK) ok(markdown).diff( '<p><a href=\"http://axr.vg/\">http://axr.vg/</a></p>\n')
def test_tags_with_dashes_and_underscored(self): markdown = self.r( 'foo <asdf-qwerty>bar</asdf-qwerty> and <a_b>baz</a_b>') ok(markdown).diff( '<p>foo <asdf-qwerty>bar</asdf-qwerty> and <a_b>baz</a_b></p>\n')
def test_linkable_headers(self): markdown = self.r('### Hello [GitHub](http://github.com)') ok(markdown).diff('<h3>Hello <a href=\"http://github.com\">GitHub</a></h3>\n')
def test_single_quotes_re(self): html = self.r('<p>They\'re not for sale.</p>\n') ok(html).diff('<p>They’re not for sale.</p>\n')
def test_double_quotes_to_curly_quotes(self): html = self.r('<p>"Quoted text"</p>\n') ok(html).diff('<p>“Quoted text”</p>\n')
def test_linkable_headers(self): markdown = self.r('### Hello [GitHub](http://github.com)') ok(markdown).diff( '<h3>Hello <a href=\"http://github.com\">GitHub</a></h3>\n')
def test_no_link_in_code_blocks(self): markdown = self.r( ' This is a code block\n This is a link [[1]] inside\n') ok(markdown).diff( '<pre><code>This is a code block\nThis is a link [[1]] inside\n</code></pre>\n' )
def test_autolink(self): markdown = self.render_with('http://axr.vg/', extensions=EXT_AUTOLINK) ok(markdown).diff('<p><a href=\"http://axr.vg/\">http://axr.vg/</a></p>\n')
def test_strikethrough(self): text = 'this is ~some~ striked ~~text~~' ok(self.render_with(text)).not_contains('<del') ok(self.render_with(text, extensions=EXT_STRIKETHROUGH)).contains('<del')
def test_infinite_loop_in_header(self): markdown = self.render_with( '######\n' \ '#Body#\n' \ '######\n') ok(markdown).diff('<h1>Body</h1>\n')
def test_no_link_in_code_blocks(self): markdown = self.r(' This is a code block\n This is a link [[1]] inside\n') ok(markdown).diff('<pre><code>This is a code block\nThis is a link [[1]] inside\n</code></pre>\n')
def test_single_quotes_m(self): html = self.r('<p>I\'m not kidding</p>\n') ok(html).diff('<p>I’m not kidding</p>\n')
def test_tags_with_dashes_and_underscored(self): markdown = self.r('foo <asdf-qwerty>bar</asdf-qwerty> and <a_b>baz</a_b>') ok(markdown).diff('<p>foo <asdf-qwerty>bar</asdf-qwerty> and <a_b>baz</a_b></p>\n')