A platform for community discussion. Free, open, simple.
FIX: non-oneboxed links on separate lines should stay on separate lines
Régis Hanol3c8b43bb011d
diff --git a/lib/oneboxer.rb b/lib/oneboxer.rbindex b8394f16901..dc5b6491572 100644--- a/lib/oneboxer.rb+++ b/lib/oneboxer.rb@@ -77,6 +77,8 @@ module Oneboxerdocend+ HTML5_BLOCK_ELEMENTS ||= %w{address article aside blockquote canvas center dd div dl dt fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 header hgroup hr li main nav noscript ol output p pre section table tfoot ul video}+def self.apply(string_or_doc, args = nil)doc = string_or_docdoc = Nokogiri::HTML::fragment(doc) if doc.is_a?(String)@@ -88,8 +90,9 @@ module Oneboxerparsed_onebox = Nokogiri::HTML::fragment(onebox)next unless parsed_onebox.children.count > 0- # special logic to strip empty p elements- if element&.parent&.node_name&.downcase == "p" && element&.parent&.children&.count == 1+ if element&.parent&.node_name&.downcase == "p" &&+ element.parent.children.count == 1 &&+ HTML5_BLOCK_ELEMENTS.include?(parsed_onebox.children[0].node_name.downcase)element = element.parentend@@ -98,6 +101,9 @@ module Oneboxerendend+ # strip empty <p> elements+ doc.css("p").each { |p| p.remove if p.children.empty? }+Result.new(doc, changed)enddiff --git a/spec/components/oneboxer_spec.rb b/spec/components/oneboxer_spec.rbindex 601af265fc9..b5ebd305ce2 100644--- a/spec/components/oneboxer_spec.rb+++ b/spec/components/oneboxer_spec.rb@@ -103,7 +103,7 @@ describe Oneboxer dopost = Fabricate(:post, raw: Discourse.base_url + "/new?'class=black")cpp = CookedPostProcessor.new(post, invalidate_oneboxes: true)cpp.post_process_oneboxes- expect(cpp.html).to eq("<a href=\"#{Discourse.base_url}/new?%27class=black\">http://test.localhost/new?%27class=black</a>")+ expect(cpp.html).to eq("<p><a href=\"#{Discourse.base_url}/new?%27class=black\">http://test.localhost/new?%27class=black</a></p>")endend