diff --git a/lib/html_to_markdown.rb b/lib/html_to_markdown.rb index 99563379aea..3f362e6f945 100644 --- a/lib/html_to_markdown.rb +++ b/lib/html_to_markdown.rb @@ -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) diff --git a/spec/components/html_to_markdown_spec.rb b/spec/components/html_to_markdown_spec.rb index 352547215dd..486baf40a19 100644 --- a/spec/components/html_to_markdown_spec.rb +++ b/spec/components/html_to_markdown_spec.rb @@ -191,6 +191,10 @@ describe HtmlToMarkdown do expect(html_to_markdown(%Q{
var foo = 'bar';
})).to eq("```javascript\nvar foo = 'bar';\n```")
end
+ it "supports inside" do + expect(html_to_markdown("")).to eq("> ```\n> var foo = 'bar';\n> ```") + end + it "works" do expect(html_to_markdown("var foo = 'bar';
")).to eq("- A list item with a blockquote:\n\n > This is a **blockquote**\n > inside a list item.") end
A list item with a blockquote:
This is a blockquote
inside a list item.