From 26d5ae61dd6fc494075b56d44061e5283777236c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 26 Feb 2018 23:28:02 +0100 Subject: [PATCH] FIX: handle
 inside 
in html_to_markdown --- lib/html_to_markdown.rb | 7 ++++--- spec/components/html_to_markdown_spec.rb | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) 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("
var foo = 'bar';
")).to eq("> ```\n> var foo = 'bar';\n> ```") + end + it "works" do expect(html_to_markdown("
  • A list item with a blockquote:

    This is a blockquote
    inside a list item.

")).to eq("- A list item with a blockquote:\n\n > This is a **blockquote**\n > inside a list item.") end