Add shortcut link syntax
This commit is contained in:
@@ -82,6 +82,9 @@ class MarkdownConverter(object):
|
|||||||
def convert_a(self, el, text):
|
def convert_a(self, el, text):
|
||||||
href = el.get('href')
|
href = el.get('href')
|
||||||
title = el.get('title')
|
title = el.get('title')
|
||||||
|
if text == href and not title:
|
||||||
|
# Shortcut syntax
|
||||||
|
return '<%s>' % href
|
||||||
title_part = ' "%s"' % title.replace('"', r'\"') if title else ''
|
title_part = ' "%s"' % title.replace('"', r'\"') if title else ''
|
||||||
return '[%s](%s%s)' % (text or '', href, title_part) if href else text or ''
|
return '[%s](%s%s)' % (text or '', href, title_part) if href else text or ''
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,11 @@ def test_a_with_title():
|
|||||||
assert text == r'[Google](http://google.com "The \"Goog\"")'
|
assert text == r'[Google](http://google.com "The \"Goog\"")'
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_shortcut():
|
||||||
|
text = md('<a href="http://google.com">http://google.com</a>')
|
||||||
|
assert text == r'<http://google.com>'
|
||||||
|
|
||||||
|
|
||||||
def test_b():
|
def test_b():
|
||||||
assert md('<b>Hello</b>') == '**Hello**'
|
assert md('<b>Hello</b>') == '**Hello**'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user