mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 10:31:10 +08:00
FIX: skip <br> inside <p> if next character is \n
This commit is contained in:
@ -572,4 +572,4 @@ DEPENDENCIES
|
|||||||
webpush
|
webpush
|
||||||
|
|
||||||
BUNDLED WITH
|
BUNDLED WITH
|
||||||
1.17.3
|
2.0.1
|
||||||
|
@ -185,6 +185,7 @@ class HtmlToMarkdown
|
|||||||
|
|
||||||
def visit_br(node)
|
def visit_br(node)
|
||||||
return if node.previous_sibling.nil? && EMPHASIS.include?(node.parent.name)
|
return if node.previous_sibling.nil? && EMPHASIS.include?(node.parent.name)
|
||||||
|
return if node.parent.name == "p" && (node.next_sibling&.text || "").start_with?("\n")
|
||||||
@stack[-1].markdown << "\n"
|
@stack[-1].markdown << "\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -103,6 +103,10 @@ describe HtmlToMarkdown do
|
|||||||
expect(html_to_markdown("Before<br>Inside<br>After")).to eq("Before\nInside\nAfter")
|
expect(html_to_markdown("Before<br>Inside<br>After")).to eq("Before\nInside\nAfter")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "skips <br> inside <p> if next character is \n" do
|
||||||
|
expect(html_to_markdown("<p>Before<br>\nInside<br>After</p>")).to eq("Before\nInside\nAfter")
|
||||||
|
end
|
||||||
|
|
||||||
it "converts <hr>" do
|
it "converts <hr>" do
|
||||||
expect(html_to_markdown("Before<hr>Inside<hr>After")).to eq("Before\n\n---\n\nInside\n\n---\n\nAfter")
|
expect(html_to_markdown("Before<hr>Inside<hr>After")).to eq("Before\n\n---\n\nInside\n\n---\n\nAfter")
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user