mirror of
https://github.com/discourse/discourse.git
synced 2025-03-22 01:05:45 +08:00
FIX: Strip audio/video content from excerpt (#8881)
This commit is contained in:
parent
928e011140
commit
49843f327e
@ -340,8 +340,8 @@ module PrettyText
|
||||
doc = Nokogiri::HTML.fragment(html)
|
||||
DiscourseEvent.trigger(:reduce_excerpt, doc, options)
|
||||
strip_image_wrapping(doc)
|
||||
strip_oneboxed_media(doc)
|
||||
html = doc.to_html
|
||||
|
||||
ExcerptParser.get_excerpt(html, max_length, options)
|
||||
end
|
||||
|
||||
@ -374,6 +374,11 @@ module PrettyText
|
||||
doc.css(".lightbox-wrapper .meta").remove
|
||||
end
|
||||
|
||||
def self.strip_oneboxed_media(doc)
|
||||
doc.css("audio").remove
|
||||
doc.css("video").remove
|
||||
end
|
||||
|
||||
def self.convert_vimeo_iframes(doc)
|
||||
doc.css("iframe[src*='player.vimeo.com']").each do |iframe|
|
||||
if iframe["data-original-href"].present?
|
||||
|
@ -771,6 +771,29 @@ describe PrettyText do
|
||||
)).to eq("boom")
|
||||
end
|
||||
end
|
||||
|
||||
it 'should strip audio/video' do
|
||||
html = <<~HTML
|
||||
<audio controls>
|
||||
<source src="https://awebsite.com/audio.mp3"><a href="https://awebsite.com/audio.mp3">https://awebsite.com/audio.mp3</a></source>
|
||||
</audio>
|
||||
<p>Listen to this!</p>
|
||||
HTML
|
||||
|
||||
expect(PrettyText.excerpt(html, 100)).to eq("Listen to this!")
|
||||
|
||||
html = <<~HTML
|
||||
<div class="onebox video-onebox">
|
||||
<video controlslist="nodownload" width="100%" height="100%" controls="">
|
||||
<source src="http://videosource.com/running.mp4">
|
||||
<a href="http://videosource.com/running.mp4">http://videosource.com/running.mp4</a>
|
||||
</video>
|
||||
</div>
|
||||
<p>Watch this, but not in the excerpt.</p>
|
||||
HTML
|
||||
|
||||
expect(PrettyText.excerpt(html, 100)).to eq("Watch this, but not in the excerpt.")
|
||||
end
|
||||
end
|
||||
|
||||
describe "strip links" do
|
||||
|
Loading…
x
Reference in New Issue
Block a user