diff --git a/html2text/__init__.py b/html2text/__init__.py index 621fa74..b436bf4 100644 --- a/html2text/__init__.py +++ b/html2text/__init__.py @@ -499,7 +499,10 @@ def handle_tag( def link_url(self: HTML2Text, link: str, title: str = "") -> None: url = urlparse.urljoin(self.baseurl, link) - title = ' "{}"'.format(title) if title.strip() else "" + if title.strip(): + title = ' "{}"'.format(title.replace('"', '\\"')) + else: + title = "" self.o("]({url}{title})".format(url=escape_md(url), title=title)) if tag == "a" and not self.ignore_links: diff --git a/test/link_title_with_quotes.html b/test/link_title_with_quotes.html new file mode 100644 index 0000000..cfa5dc9 --- /dev/null +++ b/test/link_title_with_quotes.html @@ -0,0 +1 @@ +link diff --git a/test/link_title_with_quotes.md b/test/link_title_with_quotes.md new file mode 100644 index 0000000..c7747c9 --- /dev/null +++ b/test/link_title_with_quotes.md @@ -0,0 +1 @@ +[link](http://example.com "foo \"bar\" baz")