From 1ef4dd14683db7fb1c457ddc36d71aa7f9fdcb02 Mon Sep 17 00:00:00 2001 From: Matthew Tretter Date: Wed, 31 Jul 2013 19:22:41 -0400 Subject: [PATCH] Add shortcut link syntax --- markdownify/__init__.py | 3 +++ tests/test_conversions.py | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/markdownify/__init__.py b/markdownify/__init__.py index b43c7d1..c2888f3 100644 --- a/markdownify/__init__.py +++ b/markdownify/__init__.py @@ -82,6 +82,9 @@ class MarkdownConverter(object): def convert_a(self, el, text): href = el.get('href') title = el.get('title') + if text == href and not title: + # Shortcut syntax + return '<%s>' % href title_part = ' "%s"' % title.replace('"', r'\"') if title else '' return '[%s](%s%s)' % (text or '', href, title_part) if href else text or '' diff --git a/tests/test_conversions.py b/tests/test_conversions.py index 3edb50d..12bf631 100644 --- a/tests/test_conversions.py +++ b/tests/test_conversions.py @@ -10,6 +10,11 @@ def test_a_with_title(): assert text == r'[Google](http://google.com "The \"Goog\"")' +def test_a_shortcut(): + text = md('http://google.com') + assert text == r'' + + def test_b(): assert md('Hello') == '**Hello**'