diff --git a/app/logical/d_text.rb b/app/logical/d_text.rb index 2e7ef8714..68c0990bd 100644 --- a/app/logical/d_text.rb +++ b/app/logical/d_text.rb @@ -377,13 +377,13 @@ class DText case element.name when "text" - element.content + element.content.gsub(/(?:\r|\n)+$/, "") when "br" "\n" - when "p" - from_html(element.inner_html, &block) + "\n\n" + when "p", "ul", "ol" + from_html(element.inner_html, &block).strip + "\n\n" when "blockquote" - "[quote]#{from_html(element.inner_html, &block)}[/quote]" if element.inner_html.present? + "[quote]#{from_html(element.inner_html, &block).strip}[/quote]\n\n" if element.inner_html.present? when "small", "sub" "[tn]#{from_html(element.inner_html, &block)}[/tn]" if element.inner_html.present? when "b", "strong" @@ -395,13 +395,13 @@ class DText when "s", "strike" "[s]#{from_html(element.inner_html, &block)}[/s]" if element.inner_html.present? when "li" - "* #{from_html(element.inner_html, &block)}" if element.inner_html.present? + "* #{from_html(element.inner_html, &block)}\n" if element.inner_html.present? when "h1", "h2", "h3", "h4", "h5", "h6" hN = element.name title = from_html(element.inner_html, &block) - "#{hN}. #{title}\n" + "#{hN}. #{title}\n\n" when "a" - title = from_html(element.inner_html, &block) + title = from_html(element.inner_html, &block).strip url = element["href"] %("#{title}":[#{url}]) if title.present? && url.present? when "img" diff --git a/app/logical/sources/strategies/tumblr.rb b/app/logical/sources/strategies/tumblr.rb index d9d7062a7..d8ae683fe 100644 --- a/app/logical/sources/strategies/tumblr.rb +++ b/app/logical/sources/strategies/tumblr.rb @@ -53,6 +53,10 @@ module Sources::Strategies end end + def dtext_artist_commentary_desc + DText.from_html(artist_commentary_desc).strip + end + def image_url image_urls.first end diff --git a/test/unit/sources/deviantart_test.rb b/test/unit/sources/deviantart_test.rb index ba5aedc68..a28305057 100644 --- a/test/unit/sources/deviantart_test.rb +++ b/test/unit/sources/deviantart_test.rb @@ -35,14 +35,11 @@ module Sources should "get the dtext-ified commentary" do desc = <<-EOS.strip_heredoc.chomp blah blah - "test link":[http://www.google.com] - - h1. lol - + [b]blah[/b] [i]blah[/i] [u]blah[/u] [s]blah[/s] herp derp @@ -53,7 +50,6 @@ module Sources * two * three - * one * two * three diff --git a/test/unit/sources/tumblr_test.rb b/test/unit/sources/tumblr_test.rb index 4f89e4a93..a117ed3e8 100644 --- a/test/unit/sources/tumblr_test.rb +++ b/test/unit/sources/tumblr_test.rb @@ -42,6 +42,26 @@ module Sources assert_equal(desc, @site.artist_commentary_desc) end + should "get the dtext-ified commentary" do + desc = <<-EOS.strip_heredoc.chomp + h2. header + + plain [b]bold[/b] [i]italics[/i] [s]strike[/s] + + * one + * two + + * one + * two + + [quote]quote[/quote] + + "link":[http://www.google.com] + EOS + + assert_equal(desc, @site.dtext_artist_commentary_desc) + end + should "get the image url" do assert_equal("http://data.tumblr.com/3bbfcbf075ddf969c996641b264086fd/tumblr_os2buiIOt51wsfqepo1_raw.png", @site.image_url) end