diff --git a/Gemfile.lock b/Gemfile.lock index c82a4fb1..f8ab66bc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,6 +8,7 @@ PATH activesupport (>= 5.2, < 8) cable_ready (~> 5.0) nokogiri (~> 1.0) + nokogiri-html5-inference rack (>= 2, < 4) railties (>= 5.2, < 8) redis (>= 4.0, < 6.0) @@ -127,6 +128,8 @@ GEM racc (~> 1.4) nokogiri (1.16.2-x86_64-linux) racc (~> 1.4) + nokogiri-html5-inference (0.1.1) + nokogiri (~> 1.14) parallel (1.22.1) parser (3.2.1.0) ast (~> 2.4.1) diff --git a/lib/stimulus_reflex.rb b/lib/stimulus_reflex.rb index 35e9d001..94d3d170 100644 --- a/lib/stimulus_reflex.rb +++ b/lib/stimulus_reflex.rb @@ -8,6 +8,7 @@ require "action_cable" require "action_view" require "nokogiri" +require "nokogiri/html5/inference" require "cable_ready" require "stimulus_reflex/version" require "stimulus_reflex/open_struct_fix" diff --git a/lib/stimulus_reflex/html/document_fragment.rb b/lib/stimulus_reflex/html/document_fragment.rb index ea1b6a5b..846e5dda 100644 --- a/lib/stimulus_reflex/html/document_fragment.rb +++ b/lib/stimulus_reflex/html/document_fragment.rb @@ -4,7 +4,11 @@ module StimulusReflex module HTML class DocumentFragment < Document def parsing_class - Nokogiri + Nokogiri::HTML5::Inference + end + + def document_element + @document end end end diff --git a/stimulus_reflex.gemspec b/stimulus_reflex.gemspec index 5aed3d02..2e0b3789 100644 --- a/stimulus_reflex.gemspec +++ b/stimulus_reflex.gemspec @@ -50,6 +50,7 @@ Gem::Specification.new do |gem| gem.add_dependency "nokogiri", "~> 1.0" gem.add_dependency "rack", ">= 2", "< 4" gem.add_dependency "redis", ">= 4.0", "< 6.0" + gem.add_dependency "nokogiri-html5-inference" gem.add_development_dependency "bundler", "~> 2.0" gem.add_development_dependency "magic_frozen_string_literal", "~> 1.2" diff --git a/test/broadcasters/selector_broadcaster_test.rb b/test/broadcasters/selector_broadcaster_test.rb index ded2b4e8..bcb54a79 100644 --- a/test/broadcasters/selector_broadcaster_test.rb +++ b/test/broadcasters/selector_broadcaster_test.rb @@ -71,9 +71,7 @@ class SelectorBroadcasterTest < StimulusReflex::BroadcasterTestCase "operations" => [ { "selector" => "html", - # Nokogiri automatically adds a `` tag for the encoding - # See. https://github.com/sparklemotion/nokogiri/blob/6ea1449926ce97648bb2f7401c9e4fdcb0e261ba/lib/nokogiri/html4/document.rb#L34-L35 - "html" => "
1 |
---|
1 |
1 |
---|
1 |
1 |
---|
1 |
" do
+ html = "
1 | 2 | 1 | 2 | 1 | 2 | 1 | 2 | 1 | 2 | 1 | 2 | 1 | 2 | 1 | 2 | 1 | 2 | 1 | 2 |
-
+
After Input
Header), fragment.to_html.squish - assert_equal %(Header), fragment.outer_html.squish + assert_equal %(Header), fragment.to_html.squish + assert_equal %(Header), fragment.outer_html.squish end test " alongside inside with content" do @@ -363,8 +411,8 @@ class StimulusReflex::HTML::DocumentFragmentTest < ActiveSupport::TestCase ) fragment = StimulusReflex::HTML::DocumentFragment.new(html) - assert_equal %(Hello World), fragment.to_html.squish - assert_equal %(Hello World), fragment.outer_html.squish + assert_equal %(Hello World), fragment.to_html.squish + assert_equal %(Hello World), fragment.outer_html.squish end test " tag" do
@@ -472,8 +520,8 @@ class StimulusReflex::HTML::DocumentFragmentTest < ActiveSupport::TestCase
)
fragment = StimulusReflex::HTML::DocumentFragment.new(html)
- assert_equal %(), fragment.to_html.squish
- assert_equal %(), fragment.outer_html.squish
+ assert_equal %(), fragment.to_html.squish
+ assert_equal %(), fragment.outer_html.squish
end
test "boolean attribute on closed tag" do
@@ -482,8 +530,8 @@ class StimulusReflex::HTML::DocumentFragmentTest < ActiveSupport::TestCase
)
fragment = StimulusReflex::HTML::DocumentFragment.new(html)
- assert_equal %(), fragment.to_html.squish
- assert_equal %(), fragment.outer_html.squish
+ assert_equal %(), fragment.to_html.squish
+ assert_equal %(), fragment.outer_html.squish
end
test "boolean attribute with attribute name as value on non-closed tag" do
@@ -514,8 +562,8 @@ class StimulusReflex::HTML::DocumentFragmentTest < ActiveSupport::TestCase
fragment = StimulusReflex::HTML::DocumentFragment.new(html)
- assert_equal %( Content ), fragment.to_html.squish
- assert_equal %( Content ), fragment.outer_html.squish
+ assert_equal %( Content ), fragment.to_html.squish
+ assert_equal %( Content ), fragment.outer_html.squish
end
test "should parse comments with quotes" do
@@ -526,8 +574,8 @@ class StimulusReflex::HTML::DocumentFragmentTest < ActiveSupport::TestCase
fragment = StimulusReflex::HTML::DocumentFragment.new(html)
- assert_equal %( Content ), fragment.to_html.squish
- assert_equal %( Content ), fragment.outer_html.squish
+ assert_equal %( Content ), fragment.to_html.squish
+ assert_equal %( Content ), fragment.outer_html.squish
end
test "case-sensitive attributes" do
@@ -535,8 +583,8 @@ class StimulusReflex::HTML::DocumentFragmentTest < ActiveSupport::TestCase
fragment = StimulusReflex::HTML::DocumentFragment.new(html)
- assert_equal %(1 ), fragment.to_html.squish
- assert_equal %(1 ), fragment.outer_html.squish
+ assert_equal %(1 ), fragment.to_html.squish
+ assert_equal %(1 ), fragment.outer_html.squish
end
test "case-sensitive |
---|