Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions app/services/discourse_translator/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 11 additions & 1 deletion spec/services/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,23 @@ class EmptyTranslator < DiscourseTranslator::Base
expect(DiscourseTranslator::Base.text_for_detection(post)).to eq("")
end

it "strips lightboxes" do
post.cooked = "<div class='lightbox-wrapper' />"
expect(DiscourseTranslator::Base.text_for_detection(post)).to eq("")
end

it "strips quotes" do
post.cooked = "<aside class='quote'>多言語トピック</aside>"
expect(DiscourseTranslator::Base.text_for_detection(post)).to eq("")
end

it "leaves other anchor tags alone" do
cooked = <<~HTML
<p>
<a href="http://cat.com/image.png"></a>
<a class="derp" href="http://cat.com/image.png"></a>
</p>
HTML
HTML
post.cooked = cooked
expect(DiscourseTranslator::Base.text_for_detection(post)).to eq(cooked)
end
Expand Down
Loading