mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
FIX: Make Oneboxer#apply insert block Oneboxes correctly (#11449)
It used to insert block Oneboxes inside paragraphs which resulted in invalid HTML. This needed an additional parsing for removal of empty paragraphs and the resulting HTML could still be invalid. This commit ensure that block Oneboxes are inserted correctly, by splitting the paragraph containing the link and putting the block between the two. Paragraphs left with nothing but whitespaces will be removed. Follow up to 7f3a30d79fa63aca063e4186a21f983e23d759e8.
This commit is contained in:
@ -3,9 +3,7 @@
|
||||
require 'nokogiri/xml/parse_options'
|
||||
RSpec::Matchers.define :match_html do |expected|
|
||||
match do |actual|
|
||||
a = make_canonical_html(expected).to_html.gsub(/\s+/, " ").strip
|
||||
b = make_canonical_html(actual).to_html.gsub(/\s+/, " ").strip
|
||||
a.eql? b
|
||||
make_canonical_html(expected).eql? make_canonical_html(actual)
|
||||
end
|
||||
|
||||
failure_message do |actual|
|
||||
@ -17,7 +15,17 @@ RSpec::Matchers.define :match_html do |expected|
|
||||
end
|
||||
|
||||
def make_canonical_html(html)
|
||||
Nokogiri::HTML5(html) { |config| config[:options] = Nokogiri::XML::ParseOptions::NOBLANKS | Nokogiri::XML::ParseOptions::COMPACT }
|
||||
doc = Nokogiri::HTML5(html) do |config|
|
||||
config[:options] = Nokogiri::XML::ParseOptions::NOBLANKS | Nokogiri::XML::ParseOptions::COMPACT
|
||||
end
|
||||
|
||||
doc.traverse do |node|
|
||||
if node.node_name&.downcase == "text"
|
||||
node.content = node.content.gsub(/\s+/, ' ').strip
|
||||
end
|
||||
end
|
||||
|
||||
doc.to_html
|
||||
end
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user