Skip to content

Commit

Permalink
Merge pull request soundasleep#15 from mscrivo/master
Browse files Browse the repository at this point in the history
FIX: Parsing nodes with no name
  • Loading branch information
soundasleep authored Sep 23, 2020
2 parents c883f6c + a6d7569 commit 0485f6d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/html2text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,20 @@ def iterate_over(node)

output << prefix_whitespace(node)
output += node.children.map do |child|
iterate_over(child)
if !child.name.nil?
iterate_over(child)
end
end
output << suffix_whitespace(node)

output = output.compact.join("") || ""

if node.name.downcase == "a"
output = wrap_link(node, output)
elsif node.name.downcase == "img"
output = image_text(node)
if !node.name.nil?
if node.name.downcase == "a"
output = wrap_link(node, output)
elsif node.name.downcase == "img"
output = image_text(node)
end
end

return output
Expand Down
52 changes: 52 additions & 0 deletions spec/examples/malformed-style.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>title</title>
</head>
<body>
<!DOCTYPE >
<style type="text/css">
body,
p,
span,
h1,
h2,
h3,
h4,
h5,
h6,
tr,
td,
a,
label,
div,
button,
input,
caption,
input,
textarea,
legend,
li,
ol,
select,
summary,
table,
td,
tbody,
th,
thead,
ul {
font-family: Arial !important;
}</style
><!--[if mso
]><style type="text/css">
body,
table,
td {
font-family: Arial, Helvetica, sans-serif !important;
}
</style><!
[endif]-->
<p>Some body</p>
</body>
</html>
1 change: 1 addition & 0 deletions spec/examples/malformed-style.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Some body

0 comments on commit 0485f6d

Please sign in to comment.