mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 03:10:46 -06:00
FIX: supports bare <li> when converting html to markdown
This commit is contained in:
parent
92036616db
commit
a1b8a3b52b
@ -114,7 +114,7 @@ class HtmlToMarkdown
|
||||
|
||||
def visit_li(node)
|
||||
parent = @stack.reverse.find { |n| n.name[/ul|ol|menu/] }
|
||||
prefix = parent.name == "ol" ? "1. " : "- "
|
||||
prefix = parent&.name == "ol" ? "1. " : "- "
|
||||
@stack << Block.new("li", prefix, " ")
|
||||
traverse(node)
|
||||
@markdown << format_block
|
||||
@ -209,7 +209,6 @@ class HtmlToMarkdown
|
||||
end
|
||||
|
||||
def format_block
|
||||
|
||||
lines = @stack[-1].markdown.each_line.map do |line|
|
||||
prefix = @stack.map { |b| b.opened ? b.body : b.head }.join
|
||||
@stack.each { |b| b.opened = true }
|
||||
|
@ -181,6 +181,10 @@ describe HtmlToMarkdown do
|
||||
)).to eq("- Fruits\n - 🍏\n - 🍐\n - 🍌\n- Vegetables\n - 🍆\n - 🍅\n - 🍄")
|
||||
end
|
||||
|
||||
it "supports bare <li>" do
|
||||
expect(html_to_markdown("<li>I'm alone</li>")).to eq("- I'm alone")
|
||||
end
|
||||
|
||||
it "supports <pre>" do
|
||||
expect(html_to_markdown("<pre>var foo = 'bar';</pre>")).to eq("```\nvar foo = 'bar';\n```")
|
||||
expect(html_to_markdown("<pre><code>var foo = 'bar';</code></pre>")).to eq("```\nvar foo = 'bar';\n```")
|
||||
|
Loading…
Reference in New Issue
Block a user