From 453b6040962713ef90f6272c6984a5a19ec9d636 Mon Sep 17 00:00:00 2001 From: AlexVonB Date: Sat, 2 Jan 2021 17:22:27 +0100 Subject: [PATCH 1/2] Fixing autolinks When checking a links href and text for equality, first un-escape the underscores in the text -- because six escapes them. This should fix #29. --- markdownify/__init__.py | 3 ++- tests/test_conversions.py | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/markdownify/__init__.py b/markdownify/__init__.py index 2cd8fc8..c2e2ec0 100644 --- a/markdownify/__init__.py +++ b/markdownify/__init__.py @@ -131,7 +131,8 @@ class MarkdownConverter(object): return text href = el.get('href') title = el.get('title') - if self.options['autolinks'] and text == href and not title: + # For the replacement see #29: text nodes underscores are escaped + if self.options['autolinks'] and text.replace(r'\_', '_') == 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 f5fc1c2..2896322 100644 --- a/tests/test_conversions.py +++ b/tests/test_conversions.py @@ -34,7 +34,11 @@ def test_chomp(): def test_a(): - assert md('Google') == '[Google](http://google.com)' + assert md('Google') == '[Google](https://google.com)' + assert md('https://google.com', autolinks=False) == '[https://google.com](https://google.com)' + assert md('https://google.com') == '' + assert md('https://community.kde.org/Get_Involved') == '' + assert md('https://community.kde.org/Get_Involved', autolinks=False) == '[https://community.kde.org/Get\\_Involved](https://community.kde.org/Get_Involved)' def test_a_spaces(): From b7e1ab889d986330009fe6092723bc836e2f70a0 Mon Sep 17 00:00:00 2001 From: AlexVonB Date: Mon, 4 Jan 2021 10:21:27 +0100 Subject: [PATCH 2/2] bump to v0.6.1 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 8740fc4..ec7dea2 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ read = lambda filepath: codecs.open(filepath, 'r', 'utf-8').read() pkgmeta = { '__title__': 'markdownify', '__author__': 'Matthew Tretter', - '__version__': '0.6.0', + '__version__': '0.6.1', }