mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
DEV: Apply syntax_tree formatting to spec/*
This commit is contained in:
@ -1,10 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'nokogiri/xml/parse_options'
|
||||
require "nokogiri/xml/parse_options"
|
||||
RSpec::Matchers.define :match_html do |expected|
|
||||
match do |actual|
|
||||
make_canonical_html(expected).eql? make_canonical_html(actual)
|
||||
end
|
||||
match { |actual| make_canonical_html(expected).eql? make_canonical_html(actual) }
|
||||
|
||||
failure_message do |actual|
|
||||
"after sanitizing for extra white space and compactness, expected:\n#{actual}\n to match:\n#{expected}"
|
||||
@ -15,17 +13,16 @@ RSpec::Matchers.define :match_html do |expected|
|
||||
end
|
||||
|
||||
def make_canonical_html(html)
|
||||
doc = Nokogiri::HTML5(html) do |config|
|
||||
config[:options] = Nokogiri::XML::ParseOptions::NOBLANKS | Nokogiri::XML::ParseOptions::COMPACT
|
||||
end
|
||||
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
|
||||
node.content = node.content.gsub(/\s+/, " ").strip if node.node_name&.downcase == "text"
|
||||
end
|
||||
|
||||
doc.to_html
|
||||
end
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user