From bfa5ef45aa4392e62b0a47ae44bb89113bfdb857 Mon Sep 17 00:00:00 2001 From: unknown <1463567152@qq.com> Date: Sun, 19 Jul 2026 15:00:42 +0800 Subject: [PATCH] =?UTF-8?q?markdown=E9=93=BE=E6=8E=A5=E8=BD=AC=E4=B9=89?= =?UTF-8?q?=E6=8B=AC=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- markdownify/__init__.py | 3 +++ tests/test_conversions.py | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/markdownify/__init__.py b/markdownify/__init__.py index 28cdaf6..e3d6810 100644 --- a/markdownify/__init__.py +++ b/markdownify/__init__.py @@ -442,6 +442,9 @@ def convert_a(self, el, text, parent_tags): if not text: return '' href = el.get('href') + # Escape parentheses in URLs to prevent breaking markdown link syntax + if href: + href = href.replace('(', '%28').replace(')', '%29') title = el.get('title') # For the replacement see #29: text nodes underscores are escaped if (self.options['autolinks'] diff --git a/tests/test_conversions.py b/tests/test_conversions.py index c95483c..5e02e7b 100644 --- a/tests/test_conversions.py +++ b/tests/test_conversions.py @@ -45,6 +45,14 @@ def test_a_in_code(): assert md('