From 1fead8f9e7c47f09fb2825c97f1b982cef876997 Mon Sep 17 00:00:00 2001 From: Matthew Tretter Date: Fri, 29 Jun 2012 13:54:29 -0400 Subject: [PATCH] Title support for a tags --- markdownify/__init__.py | 4 +++- tests.py | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/markdownify/__init__.py b/markdownify/__init__.py index 296924b..68f7615 100644 --- a/markdownify/__init__.py +++ b/markdownify/__init__.py @@ -69,7 +69,9 @@ class MarkdownConverter(object): def convert_a(self, el): href = el.get('href') - return '[%s](%s)' % (el.text or '', href) if href else el.text or '' + title = el.get('title') + title_part = ' "%s"' % title.replace('"', r'\"') if title else '' + return '[%s](%s%s)' % (el.text or '', href, title_part) if href else el.text or '' def convert_b(self, el): return self.convert_strong(el) diff --git a/tests.py b/tests.py index 2f8328b..cde2d4f 100644 --- a/tests.py +++ b/tests.py @@ -25,6 +25,12 @@ class ConversionTests(unittest.TestCase): '[Google](http://google.com)' ) + def test_a_with_title(self): + self.assertEqual( + md('Google'), + r'[Google](http://google.com "The \"Goog\"")' + ) + def test_b(self): self.assertEqual(md('Hello'), '**Hello**')