comparison test/test_templating.py @ 6280:6ed5152a92d0

issue2551096 - enable markdown autolink for email and bare url's. Modify raw markdown adding appropriate link markers '<' and '>' on the fly so bare urls and email addreses are recognized as explicit links by markdown backends. Patch by Cedric Krier.
author John Rouillard <rouilj@ieee.org>
date Thu, 29 Oct 2020 23:15:31 -0400
parents 9ec3a9bc4ea5
children d30501bafdfb
comparison
equal deleted inserted replaced
6279:9ec3a9bc4ea5 6280:6ed5152a92d0
491 self.client.db.config['MARKDOWN_BREAK_ON_NEWLINE'] = False 491 self.client.db.config['MARKDOWN_BREAK_ON_NEWLINE'] = False
492 492
493 m = p.markdown() 493 m = p.markdown()
494 self.assertEqual(0, m.count('<br')) 494 self.assertEqual(0, m.count('<br'))
495 495
496 def test_markdown_hyperlinked_url(self):
497 # classic markdown does not emit a \n at end of rendered string
498 # so rstrip \n.
499 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'http://example.com/'))
500 m = p.markdown(hyperlink=1)
501 self.assertEqual(m.rstrip('\n'), '<p><a href="http://example.com/">http://example.com/</a></p>')
502
503 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'<http://example.com/>'))
504 m = p.markdown(hyperlink=1)
505 self.assertEqual(m.rstrip('\n'), '<p><a href="http://example.com/">http://example.com/</a></p>')
506
507 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'![](http://example.com/)'))
508 m = p.markdown(hyperlink=1)
509 self.assertIn(m, [
510 '<p><img src="http://example.com/" alt=""/></p>\n',
511 '<p><img src="http://example.com/" alt="" /></p>\n',
512 '<p><img src="http://example.com/" alt=""></p>\n',
513 '<p><img alt="" src="http://example.com/" /></p>', # markdown
514 ])
515
516 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'An URL http://example.com/ with text'))
517 m = p.markdown(hyperlink=1)
518 self.assertEqual(m.rstrip('\n'), '<p>An URL <a href="http://example.com/">http://example.com/</a> with text</p>')
519
520 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'An URL https://example.com/path with text'))
521 m = p.markdown(hyperlink=1)
522 self.assertEqual(m.rstrip('\n'), '<p>An URL <a href="https://example.com/path">https://example.com/path</a> with text</p>')
496 523
497 @skip_mistune 524 @skip_mistune
498 class MistuneTestCase(TemplatingTestCase, MarkdownTests) : 525 class MistuneTestCase(TemplatingTestCase, MarkdownTests) :
499 def setUp(self): 526 def setUp(self):
500 TemplatingTestCase.setUp(self) 527 TemplatingTestCase.setUp(self)

Roundup Issue Tracker: http://roundup-tracker.org/