diff --git a/lib/html2markdown/converter.ex b/lib/html2markdown/converter.ex
index 6cdf3f1..337c467 100644
--- a/lib/html2markdown/converter.ex
+++ b/lib/html2markdown/converter.ex
@@ -49,12 +49,22 @@ defmodule Html2Markdown.Converter do
if acc == [] do
[iodata]
else
- [acc, "\n\n", iodata]
+ [acc, get_spacing_between_elements(node), iodata]
end
end
end)
end
+ defp get_spacing_between_elements({tag, _, _}) when is_binary(tag) do
+ if ElementTypes.block_element?(tag) do
+ "\n\n"
+ else
+ " "
+ end
+ end
+
+ defp get_spacing_between_elements(_node), do: " "
+
# Process nodes to iolist for better performance
defp process_node_to_iolist({"h1", _, children}, opts),
do: ["# ", process_children_to_iolist(children, opts)]
@@ -426,7 +436,7 @@ defmodule Html2Markdown.Converter do
defp process_ordered_list_item_to_iolist(other, _index, opts),
do: process_node_to_iolist(other, opts)
- # Context-aware processing for better spacing control
+ # Context-aware processing for better spacing control
defp process_children_with_context(children, opts, context) do
final_context = determine_context(children, context)
diff --git a/test/html2markdown_test.exs b/test/html2markdown_test.exs
index 8edc0c6..4fa09e9 100644
--- a/test/html2markdown_test.exs
+++ b/test/html2markdown_test.exs
@@ -543,4 +543,36 @@ defmodule Html2MarkdownTest do
assert Html2Markdown.convert(html) == expected
end
end
+
+ describe "HTML tags with normal text" do
+ test "emphasis tag" do
+ html = """
+ Emphasis normal text
+ """
+
+ expected = "*Emphasis* normal text"
+
+ assert Html2Markdown.convert(html) == expected
+ end
+
+ test "strong tag" do
+ html = """
+ Bold normal text
+ """
+
+ expected = "**Bold** normal text"
+
+ assert Html2Markdown.convert(html) == expected
+ end
+
+ test "span tag" do
+ html = """
+ Span text normal text
+ """
+
+ expected = "Span text normal text"
+
+ assert Html2Markdown.convert(html) == expected
+ end
+ end
end
diff --git a/test/support/fixtures/elixir.md b/test/support/fixtures/elixir.md
index 4bda3cc..a45b2bd 100644
--- a/test/support/fixtures/elixir.md
+++ b/test/support/fixtures/elixir.md
@@ -79,9 +79,7 @@ Here is an example of **strong text** and *emphasized text*.
Subscript: H 2 O
-Superscript: E = mc 2
-
-
+Superscript: E = mc 2
---