diff --git a/lib/html_to_markdown.rb b/lib/html_to_markdown.rb
index 21a3cded140..6edf93555e3 100644
--- a/lib/html_to_markdown.rb
+++ b/lib/html_to_markdown.rb
@@ -186,18 +186,22 @@ class HtmlToMarkdown
end
def visit_strong(node)
+ return if node.text.blank?
delimiter = node.text["*"] ? "__" : "**"
@stack[-1].markdown << delimiter
traverse(node)
+ @stack[-1].markdown.chomp!
@stack[-1].markdown << delimiter
end
alias :visit_b :visit_strong
def visit_em(node)
+ return if node.text.blank?
delimiter = node.text["*"] ? "_" : "*"
@stack[-1].markdown << delimiter
traverse(node)
+ @stack[-1].markdown.chomp!
@stack[-1].markdown << delimiter
end
diff --git a/spec/components/html_to_markdown_spec.rb b/spec/components/html_to_markdown_spec.rb
index 21aa1822d27..9b425035273 100644
--- a/spec/components/html_to_markdown_spec.rb
+++ b/spec/components/html_to_markdown_spec.rb
@@ -228,4 +228,32 @@ describe HtmlToMarkdown do
expect(html_to_markdown(html)).to eq("1st paragraph\n2nd paragraph")
end
+ context "with an oddly placed
" do
+
+ it "handles " do
+ expect(html_to_markdown("Bold
")).to eq("**Bold**")
+ expect(html_to_markdown("Bold
text")).to eq("**Bold\ntext**")
+ end
+
+ it "handles " do
+ expect(html_to_markdown("Italic
")).to eq("*Italic*")
+ expect(html_to_markdown("Italic
text")).to eq("*Italic\ntext*")
+ end
+
+ end
+
+ context "with an empty tag" do
+
+ it "handles " do
+ expect(html_to_markdown("")).to eq("")
+ expect(html_to_markdown(" ")).to eq("")
+ end
+
+ it "handles " do
+ expect(html_to_markdown("")).to eq("")
+ expect(html_to_markdown(" ")).to eq("")
+ end
+
+ end
+
end