From f60d910335420a52eb17a1ae70e2e220c3f4871c Mon Sep 17 00:00:00 2001 From: Matthew Tretter Date: Wed, 31 Jul 2013 21:58:48 -0400 Subject: [PATCH] Add "autolinks" option This option allows you to disable the creation of "autolink" style links. --- markdownify/__init__.py | 3 ++- tests/test_conversions.py | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/markdownify/__init__.py b/markdownify/__init__.py index b2f208c..32c397c 100644 --- a/markdownify/__init__.py +++ b/markdownify/__init__.py @@ -23,6 +23,7 @@ class MarkdownConverter(object): class DefaultOptions: strip = None convert = None + autolinks = True class Options(DefaultOptions): pass @@ -98,7 +99,7 @@ class MarkdownConverter(object): def convert_a(self, el, text): href = el.get('href') title = el.get('title') - if text == href and not title: + if self.options['autolinks'] and text == href and not title: # Shortcut syntax return '<%s>' % href title_part = ' "%s"' % title.replace('"', r'\"') if title else '' diff --git a/tests/test_conversions.py b/tests/test_conversions.py index 12bf631..abbbdd5 100644 --- a/tests/test_conversions.py +++ b/tests/test_conversions.py @@ -15,6 +15,11 @@ def test_a_shortcut(): assert text == r'' +def test_a_no_autolinks(): + text = md('http://google.com', autolinks=False) + assert text == '[http://google.com](http://google.com)' + + def test_b(): assert md('Hello') == '**Hello**'