def test_url_callback_constructor_kwargs(self): def rewrite_links_func(url): if url.startswith('/'): return 'http://example.com%s' % url md = Markdown( '[a](/a.html)', rewrite_links_func=rewrite_links_func ) html = md.get_html_content() self.assertEqual( html, '<p><a href="http://example.com/a.html">a</a></p>' ) def link_attrs_func(url): if url.startswith('http'): return 'target="_blank"' md = Markdown( '[a](/a.html)\n[b](http://example.com/b.html)', link_attrs_func=link_attrs_func ) html = md.get_html_content() self.assertEqual( html, '<p>' '<a href="/a.html">a</a>\n' '<a href="http://example.com/b.html" target="_blank">b</a>' '</p>' )
def transform(self, text, entry, *args): mkd = Markdown(text.encode('utf-8'), autolink=True, safelink=True, ignore_header=True) return mkd.get_html_content().decode('utf-8')
def transform(self, text, entry, *args): mkd = Markdown(text.encode(entry.encoding), autolink=True, safelink=True, ignore_header=True) return mkd.get_html_content().decode(entry.encoding, errors='replace')
def test_input_file_get_html_content(self): i = tempfile.TemporaryFile('r+w') i.write('`test`') i.seek(0) md = Markdown(i) html = md.get_html_content() i.close() self.assertEqual(html, '<p><code>test</code></p>')
def test_empty_document_renders(self): md = Markdown('') html = md.get_html_content() self.assertEqual(html, '') md = Markdown(' \t \n ') html = md.get_html_content() self.assertEqual(html, '') i = tempfile.TemporaryFile('r+w') md = Markdown(i) html = md.get_html_content() i.close() self.assertEqual(html, '') i = tempfile.TemporaryFile('r+w') i.write(' \t \n ') i.seek(0) md = Markdown(i) html = md.get_html_content() i.close() self.assertEqual(html, '')
def test_rewrite_links_as_method(self): def rewrite_links_func(url): if url.startswith('/'): return 'http://example.com%s' % url md = Markdown('[a](/a.html)') md.rewrite_links(rewrite_links_func) html = md.get_html_content() self.assertEqual( html, '<p><a href="http://example.com/a.html">a</a></p>' )
def test_link_attrs_as_method(self): def link_attrs_func(url): if url.startswith('http'): return 'target="_blank"' md = Markdown('[a](/a.html)\n[b](http://example.com/b.html)') md.link_attrs(link_attrs_func) html = md.get_html_content() self.assertEqual( html, '<p>' '<a href="/a.html">a</a>\n' '<a href="http://example.com/b.html" target="_blank">b</a>' '</p>' )
def test_input_string_get_html_content(self): md = Markdown('`test`') html = md.get_html_content() self.assertEqual(html, '<p><code>test</code></p>')