From 51ee49aad2ba54990829b4755e78ecf994d36ad4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Fri, 28 Apr 2017 22:02:20 +0200 Subject: [PATCH] FIX: properly support HTML document when converting to markdown --- lib/html_to_markdown.rb | 2 +- spec/components/html_to_markdown_spec.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/html_to_markdown.rb b/lib/html_to_markdown.rb index 6a5112c8270..2bc60f6015f 100644 --- a/lib/html_to_markdown.rb +++ b/lib/html_to_markdown.rb @@ -7,7 +7,7 @@ class HtmlToMarkdown end def initialize(html) - @doc = Nokogiri::HTML.fragment(html) + @doc = Nokogiri::HTML(html) remove_whitespaces! end diff --git a/spec/components/html_to_markdown_spec.rb b/spec/components/html_to_markdown_spec.rb index f71c0e0efc4..15af2dcef34 100644 --- a/spec/components/html_to_markdown_spec.rb +++ b/spec/components/html_to_markdown_spec.rb @@ -142,6 +142,10 @@ describe HtmlToMarkdown do expect(html_to_markdown("")).to eq("- A list item with a blockquote:\n\n > This is a **blockquote**\n > inside a list item.") end + it "supports html document" do + expect(html_to_markdown("Hello
World
")).to eq("Hello\nWorld") + end + it "handles

" do expect(html_to_markdown("

1st paragraph

2nd paragraph

")).to eq("1st paragraph\n\n2nd paragraph") end