Merge pull request #48522 from flavorjones/flavorjones-update-action-view-to-html5
Update Action Text to use HTML5 when available
This commit is contained in:
commit
52ca1b6345
@ -4,7 +4,7 @@
|
||||
|
||||
module ActionText
|
||||
module ContentHelper
|
||||
mattr_accessor(:sanitizer) { Rails::Html::Sanitizer.safe_list_sanitizer.new }
|
||||
mattr_accessor(:sanitizer) { Rails::Html::Sanitizer.best_supported_vendor.safe_list_sanitizer.new }
|
||||
mattr_accessor(:allowed_tags) { sanitizer.class.allowed_tags + [ ActionText::Attachment.tag_name, "figure", "figcaption" ] }
|
||||
mattr_accessor(:allowed_attributes) { sanitizer.class.allowed_attributes + ActionText::Attachment::ATTRIBUTES }
|
||||
mattr_accessor(:scrubber)
|
||||
|
@ -42,4 +42,18 @@ module Attachments
|
||||
autoload :Minification
|
||||
autoload :TrixConversion
|
||||
end
|
||||
|
||||
class << self
|
||||
def html_document_class
|
||||
return @html_document_class if defined?(@html_document_class)
|
||||
@html_document_class =
|
||||
defined?(Nokogiri::HTML5) ? Nokogiri::HTML5::Document : Nokogiri::HTML4::Document
|
||||
end
|
||||
|
||||
def html_document_fragment_class
|
||||
return @html_document_fragment_class if defined?(@html_document_fragment_class)
|
||||
@html_document_fragment_class =
|
||||
defined?(Nokogiri::HTML5) ? Nokogiri::HTML5::DocumentFragment : Nokogiri::HTML4::DocumentFragment
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -7,7 +7,7 @@ def wrap(fragment_or_html)
|
||||
case fragment_or_html
|
||||
when self
|
||||
fragment_or_html
|
||||
when Nokogiri::HTML::DocumentFragment
|
||||
when Nokogiri::XML::DocumentFragment # base class for all fragments
|
||||
new(fragment_or_html)
|
||||
else
|
||||
from_html(fragment_or_html)
|
||||
@ -30,7 +30,7 @@ def find_all(selector)
|
||||
end
|
||||
|
||||
def update
|
||||
yield source = self.source.clone
|
||||
yield source = self.source.dup
|
||||
self.class.new(source)
|
||||
end
|
||||
|
||||
|
@ -18,7 +18,7 @@ def create_element(tag_name, attributes = {})
|
||||
|
||||
private
|
||||
def document
|
||||
Nokogiri::HTML::Document.new.tap { |doc| doc.encoding = "UTF-8" }
|
||||
ActionText.html_document_class.new.tap { |doc| doc.encoding = "UTF-8" }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -20,7 +20,7 @@ class ActionText::ControllerRenderTest < ActionDispatch::IntegrationTest
|
||||
|
||||
host! "loocalhoost"
|
||||
get message_path(message, format: :json)
|
||||
content = Nokogiri::HTML::DocumentFragment.parse(response.parsed_body["content"])
|
||||
content = ActionText.html_document_fragment_class.parse(response.parsed_body["content"])
|
||||
assert_select content, "img:match('src', ?)", %r"//loocalhoost/.+/racecar"
|
||||
end
|
||||
|
||||
|
@ -18,7 +18,7 @@ class ActionText::JobRenderTest < ActiveJob::TestCase
|
||||
perform_enqueued_jobs
|
||||
end
|
||||
|
||||
rendered = Nokogiri::HTML::DocumentFragment.parse(File.read(file))
|
||||
rendered = ActionText.html_document_fragment_class.parse(File.read(file))
|
||||
assert_select rendered, "img:match('src', ?)", %r"//foo.example.com:9001/.+/racecar"
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user