Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions markdownify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
8 changes: 8 additions & 0 deletions tests/test_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ def test_a_in_code():
assert md('<pre><a href="https://google.com">Google</a></pre>') == '\n\n```\nGoogle\n```\n\n'


def test_a_parentheses_in_url():
html = ('<a href="http://en.wiktionary.org/wiki/)">close-paren on wiktionary</a>'
'<br/><a href="http://en.wiktionary.org/wiki/(">open-paren on wiktionary</a>')
expected = ('[close-paren on wiktionary](http://en.wiktionary.org/wiki/%29) \n'
'[open-paren on wiktionary](http://en.wiktionary.org/wiki/%28)')
assert md(html) == expected


def test_b():
assert md('<b>Hello</b>') == '**Hello**'

Expand Down