FIX: Keep `alt` and `title` in lightbox when indexing for search.
Follow up to cfd507822f
This commit is contained in:
parent
e87ca59401
commit
2a69ab4a4c
|
@ -190,9 +190,25 @@ class SearchIndexer
|
|||
|
||||
document = Nokogiri::HTML("<div>#{html}</div>", nil, Encoding::UTF_8.to_s)
|
||||
|
||||
document.css(
|
||||
nodes = document.css(
|
||||
"div.#{CookedPostProcessor::LIGHTBOX_WRAPPER_CSS_CLASS}"
|
||||
).remove
|
||||
)
|
||||
|
||||
if nodes.present?
|
||||
nodes.each do |node|
|
||||
node.traverse do |child_node|
|
||||
next if child_node == node
|
||||
|
||||
if %w{a img}.exclude?(child_node.name)
|
||||
child_node.remove
|
||||
elsif child_node.name == "a"
|
||||
ATTRIBUTES.each do |attribute|
|
||||
child_node.remove_attribute(attribute)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
document.css("a[href]").each do |node|
|
||||
node.remove_attribute("href") if node["href"] == node.text
|
||||
|
|
|
@ -61,7 +61,7 @@ describe SearchIndexer do
|
|||
|
||||
scrubbed = scrub(html)
|
||||
|
||||
expect(scrubbed).to eq("Discourse 51%20PM")
|
||||
expect(scrubbed).to eq("Discourse 51%20PM Untitled%20design%20(21)")
|
||||
end
|
||||
|
||||
it 'correctly indexes a post according to version' do
|
||||
|
@ -137,7 +137,7 @@ describe SearchIndexer do
|
|||
|
||||
post = Fabricate(:post, raw: <<~RAW)
|
||||
Let me see how I can fix this image
|
||||
<img src="#{src}" width="2" height="2">
|
||||
<img src="#{src}" title="GOT" alt="white walkers" width="2" height="2">
|
||||
RAW
|
||||
|
||||
post.rebake!
|
||||
|
@ -149,7 +149,7 @@ describe SearchIndexer do
|
|||
)
|
||||
|
||||
expect(post.post_search_data.raw_data).to eq(
|
||||
"#{topic.title} #{topic.category.name} Let me see how I can fix this image"
|
||||
"#{topic.title} #{topic.category.name} Let me see how I can fix this image white walkers GOT"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue