mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 01:16:38 -06:00
FIX: Handle cases where alt
and title
tag is blank when parsing excerpt.
This commit is contained in:
parent
2d9b31b147
commit
0a4c30bce3
@ -68,9 +68,9 @@ class ExcerptParser < Nokogiri::XML::SAX::Document
|
||||
# If include_images is set, include the image in markdown
|
||||
characters("!") if @markdown_images
|
||||
|
||||
if attributes["alt"]
|
||||
if !attributes["alt"].blank?
|
||||
characters("[#{attributes["alt"]}]")
|
||||
elsif attributes["title"]
|
||||
elsif !attributes["title"].blank?
|
||||
characters("[#{attributes["title"]}]")
|
||||
else
|
||||
characters("[#{I18n.t 'excerpt_image'}]")
|
||||
|
@ -124,12 +124,28 @@ HTML
|
||||
expect(PrettyText.excerpt("<img src='http://cnn.com/a.gif'>",100)).to eq("[image]")
|
||||
end
|
||||
|
||||
it "should keep alt tags" do
|
||||
expect(PrettyText.excerpt("<img src='http://cnn.com/a.gif' alt='car' title='my big car'>",100)).to eq("[car]")
|
||||
context 'alt tags' do
|
||||
it "should keep alt tags" do
|
||||
expect(PrettyText.excerpt("<img src='http://cnn.com/a.gif' alt='car' title='my big car'>", 100)).to eq("[car]")
|
||||
end
|
||||
|
||||
describe 'when alt tag is empty' do
|
||||
it "should not keep alt tags" do
|
||||
expect(PrettyText.excerpt("<img src='http://cnn.com/a.gif' alt>", 100)).to eq("[#{I18n.t('excerpt_image')}]")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "should keep title tags" do
|
||||
expect(PrettyText.excerpt("<img src='http://cnn.com/a.gif' title='car'>",100)).to eq("[car]")
|
||||
context 'title tags' do
|
||||
it "should keep title tags" do
|
||||
expect(PrettyText.excerpt("<img src='http://cnn.com/a.gif' title='car'>", 100)).to eq("[car]")
|
||||
end
|
||||
|
||||
describe 'when title tag is empty' do
|
||||
it "should not keep title tags" do
|
||||
expect(PrettyText.excerpt("<img src='http://cnn.com/a.gif' title>", 100)).to eq("[#{I18n.t('excerpt_image')}]")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "should convert images to markdown if the option is set" do
|
||||
|
Loading…
Reference in New Issue
Block a user