Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't append newlines inside a span #87

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 8 additions & 2 deletions html2text.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
"""html2text: Turn HTML into equivalent Markdown-structured text."""
__version__ = "3.200.3"
__version__ = "3.200.4"
__author__ = "Aaron Swartz ([email protected])"
__copyright__ = "(C) 2004-2008 Aaron Swartz. GNU GPL 3."
__contributors__ = ["Martin 'Joey' Schulze", "Ricardo Reyes", "Kevin Jay North"]
Expand Down Expand Up @@ -238,6 +238,7 @@ def __init__(self, out=None, baseurl=''):
self.abbr_data = None # last inner HTML (for abbr being defined)
self.abbr_list = {} # stack of abbreviations to write later
self.baseurl = baseurl
self.in_span = False

try: del unifiable_n[name2cp('nbsp')]
except KeyError: pass
Expand Down Expand Up @@ -413,7 +414,8 @@ def handle_tag(self, tag, attrs, start):
else:
self.soft_br()
else:
self.p()
if start == 1 or not self.in_span:
self.p()

if tag == "br" and start: self.o(" \n")

Expand Down Expand Up @@ -492,12 +494,14 @@ def handle_tag(self, tag, attrs, start):
a['outcount'] = self.outcount
self.a.append(a)
self.o("][" + str(a['count']) + "]")
self.in_span = False

if tag == "img" and start and not self.ignore_images:
if has_key(attrs, 'src'):
attrs['href'] = attrs['src']
alt = attrs.get('alt', '')
self.o("![" + escape_md(alt) + "]")
self.in_span = False

if self.inline_links:
self.o("(" + escape_md(attrs['href']) + ")")
Expand All @@ -511,6 +515,7 @@ def handle_tag(self, tag, attrs, start):
attrs['outcount'] = self.outcount
self.a.append(attrs)
self.o("[" + str(attrs['count']) + "]")
self.in_span = False

if tag == 'dl' and start: self.p()
if tag == 'dt' and not start: self.pbr()
Expand Down Expand Up @@ -670,6 +675,7 @@ def handle_data(self, data):
return
else:
self.o("[")
self.in_span = True
self.maybe_automatic_link = None

if not self.code and not self.pre:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name = "html2text",
version = "3.200.3",
version = "3.200.4",
description = "Turn HTML into equivalent Markdown-structured text.",
author = "Aaron Swartz",
author_email = "[email protected]",
Expand Down