Skip to content

Commit

Permalink
Merge pull request #64 from alawibaba/master
Browse files Browse the repository at this point in the history
Proper handling of anchors with content that starts with tags that
Fixes #63 #24

Thanks Ali Mohammad @alawibaba
  • Loading branch information
Alir3z4 committed Jun 3, 2015
2 parents da3d3a8 + 897a207 commit f980ad1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions html2text/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,13 @@ def handle_tag(self, tag, attrs, start):
else:
attrs = dict(attrs)

# first thing inside the anchor tag is another tag that produces some output
if start and not self.maybe_automatic_link is None and \
tag not in ['p', 'div', 'style', 'dl', 'dt'] and (tag != "img" or self.ignore_images):
self.o("[")
self.maybe_automatic_link = None
self.empty_link = False

if self.google_doc:
# the attrs parameter is empty for a closing tag. in addition, we
# need the attributes of the parent nodes in order to get a
Expand Down
7 changes: 7 additions & 0 deletions test/anchors.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<h1>Processing hyperlinks</h1>

<p>Additional hyperlink tests!</p>

<a href="http://some.link"><b>Bold Link</b></a>
<a href="http://some.link/filename.py"><code>filename.py</code></a>
<a href="http://some.link/magicsources.py">The source code is called <code>magic.py</code></a>
8 changes: 8 additions & 0 deletions test/anchors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Processing hyperlinks

Additional hyperlink tests!

[**Bold Link**](http://some.link)
[`filename.py`](http://some.link/filename.py) [The source code is called
`magic.py`](http://some.link/magicsources.py)

0 comments on commit f980ad1

Please sign in to comment.