diff --git a/app/services/discourse_translator/base.rb b/app/services/discourse_translator/base.rb index 1b5ca5f9..a931925d 100644 --- a/app/services/discourse_translator/base.rb +++ b/app/services/discourse_translator/base.rb @@ -74,8 +74,7 @@ def self.language_supported?(detected_lang) def self.strip_tags_for_detection(detection_text) html_doc = Nokogiri::HTML::DocumentFragment.parse(detection_text) - html_doc.css("img").remove - html_doc.css("a.mention,a.lightbox").remove + html_doc.css("img", "aside.quote", "div.lightbox-wrapper", "a.mention,a.lightbox").remove html_doc.to_html end diff --git a/spec/services/base_spec.rb b/spec/services/base_spec.rb index 2dc1f24e..c1609d0d 100644 --- a/spec/services/base_spec.rb +++ b/spec/services/base_spec.rb @@ -51,13 +51,23 @@ class EmptyTranslator < DiscourseTranslator::Base expect(DiscourseTranslator::Base.text_for_detection(post)).to eq("") end + it "strips lightboxes" do + post.cooked = "
" + expect(DiscourseTranslator::Base.text_for_detection(post)).to eq("") + end + + it "strips quotes" do + post.cooked = "" + expect(DiscourseTranslator::Base.text_for_detection(post)).to eq("") + end + it "leaves other anchor tags alone" do cooked = <<~HTML - HTML + HTML post.cooked = cooked expect(DiscourseTranslator::Base.text_for_detection(post)).to eq(cooked) end