commentaries: replace <img> tags with dtext links (#3586)
Replace <img> tags with dtext links, unless the <img> tag is already inside an <a> tag. Also strip Unicode spaces from DeviantArt commentaries.
This commit is contained in:
@@ -83,7 +83,16 @@ class DText
|
|||||||
url = element["href"]
|
url = element["href"]
|
||||||
%("#{title}":[#{url}]) if title.present? && url.present?
|
%("#{title}":[#{url}]) if title.present? && url.present?
|
||||||
when "img"
|
when "img"
|
||||||
element.attributes["title"] || element.attributes["alt"] || ""
|
alt_text = element.attributes["title"] || element.attributes["alt"] || ""
|
||||||
|
src = element["src"]
|
||||||
|
|
||||||
|
if element.parent.name == "a"
|
||||||
|
alt_text
|
||||||
|
elsif alt_text.present? && src.present?
|
||||||
|
%("#{alt_text}":[#{src}]\n\n)
|
||||||
|
else
|
||||||
|
""
|
||||||
|
end
|
||||||
when "comment"
|
when "comment"
|
||||||
# ignored
|
# ignored
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ module Sources
|
|||||||
element["href"] = uri.to_s
|
element["href"] = uri.to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end.gsub(/\A[[:space:]]+|[[:space:]]+\z/, "")
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ module Sources
|
|||||||
* two
|
* two
|
||||||
* three
|
* three
|
||||||
|
|
||||||
Heart
|
"Heart":[https://e.deviantart.net/emoticons/h/heart.gif]
|
||||||
EOS
|
EOS
|
||||||
|
|
||||||
assert_equal(desc, @site.dtext_artist_commentary_desc)
|
assert_equal(desc, @site.dtext_artist_commentary_desc)
|
||||||
|
|||||||
Reference in New Issue
Block a user