Add "autolinks" option
This option allows you to disable the creation of "autolink" style links.
This commit is contained in:
@@ -23,6 +23,7 @@ class MarkdownConverter(object):
|
|||||||
class DefaultOptions:
|
class DefaultOptions:
|
||||||
strip = None
|
strip = None
|
||||||
convert = None
|
convert = None
|
||||||
|
autolinks = True
|
||||||
|
|
||||||
class Options(DefaultOptions):
|
class Options(DefaultOptions):
|
||||||
pass
|
pass
|
||||||
@@ -98,7 +99,7 @@ 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:
|
if self.options['autolinks'] and text == href and not title:
|
||||||
# Shortcut syntax
|
# Shortcut syntax
|
||||||
return '<%s>' % href
|
return '<%s>' % href
|
||||||
title_part = ' "%s"' % title.replace('"', r'\"') if title else ''
|
title_part = ' "%s"' % title.replace('"', r'\"') if title else ''
|
||||||
|
|||||||
@@ -15,6 +15,11 @@ def test_a_shortcut():
|
|||||||
assert text == r'<http://google.com>'
|
assert text == r'<http://google.com>'
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_no_autolinks():
|
||||||
|
text = md('<a href="http://google.com">http://google.com</a>', autolinks=False)
|
||||||
|
assert text == '[http://google.com](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