Skip to content
Merged
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
14 changes: 12 additions & 2 deletions lib/html2markdown/converter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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)

Expand Down
32 changes: 32 additions & 0 deletions test/html2markdown_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
<em>Emphasis</em> normal text
"""

expected = "*Emphasis* normal text"

assert Html2Markdown.convert(html) == expected
end

test "strong tag" do
html = """
<strong>Bold</strong> normal text
"""

expected = "**Bold** normal text"

assert Html2Markdown.convert(html) == expected
end

test "span tag" do
html = """
<span>Span text</span> normal text
"""

expected = "Span text normal text"

assert Html2Markdown.convert(html) == expected
end
end
end
4 changes: 1 addition & 3 deletions test/support/fixtures/elixir.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ Here is an example of **strong text** and *emphasized text*.

Subscript: H <sub>2</sub> O

Superscript: E = mc <sup>2</sup>


Superscript: E = mc <sup>2</sup>

---

Expand Down
Loading