FIX: handle <pre> inside <blockquote> in html_to_markdown

This commit is contained in:
Régis Hanol 2018-02-26 23:28:02 +01:00
parent 382dbfbb8a
commit 26d5ae61dd
2 changed files with 8 additions and 3 deletions

View File

@ -75,11 +75,12 @@ class HtmlToMarkdown
code = node.children.find { |c| c.name == "code" }
code_class = code ? code["class"] : ""
lang = code_class ? code_class[/lang-(\w+)/, 1] : ""
@stack << Block.new("pre")
@markdown << "```#{lang}\n"
pre = Block.new("pre")
pre.markdown = "```#{lang}\n"
@stack << pre
traverse(node)
pre.markdown << "\n```\n"
@markdown << format_block
@markdown << "```\n"
end
def visit_blockquote(node)

View File

@ -191,6 +191,10 @@ describe HtmlToMarkdown do
expect(html_to_markdown(%Q{<pre><code class="lang-javascript">var foo = 'bar';</code></pre>})).to eq("```javascript\nvar foo = 'bar';\n```")
end
it "supports <pre> inside <blockquote>" do
expect(html_to_markdown("<blockquote><pre><code>var foo = 'bar';</code></pre></blockquote>")).to eq("> ```\n> var foo = 'bar';\n> ```")
end
it "works" do
expect(html_to_markdown("<ul><li><p>A list item with a blockquote:</p><blockquote><p>This is a <strong>blockquote</strong><br>inside a list item.</p></blockquote></li></ul>")).to eq("- A list item with a blockquote:\n\n > This is a **blockquote**\n > inside a list item.")
end