Fix #3591: DeviantArt commentaries: strip embedded image/text thumbs.
This commit is contained in:
@@ -47,7 +47,7 @@ class DText
|
|||||||
stripped.strip
|
stripped.strip
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.from_html(text, &block)
|
def self.from_html(text, inline: false, &block)
|
||||||
html = Nokogiri::HTML.fragment(text)
|
html = Nokogiri::HTML.fragment(text)
|
||||||
|
|
||||||
dtext = html.children.map do |element|
|
dtext = html.children.map do |element|
|
||||||
@@ -79,14 +79,14 @@ class DText
|
|||||||
title = from_html(element.inner_html, &block)
|
title = from_html(element.inner_html, &block)
|
||||||
"#{hN}. #{title}\n\n"
|
"#{hN}. #{title}\n\n"
|
||||||
when "a"
|
when "a"
|
||||||
title = from_html(element.inner_html, &block).strip
|
title = from_html(element.inner_html, inline: true, &block).strip
|
||||||
url = element["href"]
|
url = element["href"]
|
||||||
%("#{title}":[#{url}]) if title.present? && url.present?
|
%("#{title}":[#{url}]) if title.present? && url.present?
|
||||||
when "img"
|
when "img"
|
||||||
alt_text = element.attributes["title"] || element.attributes["alt"] || ""
|
alt_text = element.attributes["title"] || element.attributes["alt"] || ""
|
||||||
src = element["src"]
|
src = element["src"]
|
||||||
|
|
||||||
if element.parent.name == "a"
|
if inline
|
||||||
alt_text
|
alt_text
|
||||||
elsif alt_text.present? && src.present?
|
elsif alt_text.present? && src.present?
|
||||||
%("#{alt_text}":[#{src}]\n\n)
|
%("#{alt_text}":[#{src}]\n\n)
|
||||||
|
|||||||
@@ -42,6 +42,21 @@ module Sources
|
|||||||
|
|
||||||
def self.to_dtext(text)
|
def self.to_dtext(text)
|
||||||
DText.from_html(text) do |element|
|
DText.from_html(text) do |element|
|
||||||
|
# Convert embedded thumbnails of journal posts to 'deviantart #123'
|
||||||
|
# links. Strip embedded thumbnails of image posts. Example:
|
||||||
|
# https://sa-dui.deviantart.com/art/Commission-Meinos-Kaen-695905927.
|
||||||
|
if element.name == "a" && element["data-sigil"] == "thumb"
|
||||||
|
element.name = "span"
|
||||||
|
|
||||||
|
# <a href="https://sa-dui.deviantart.com/journal/About-Commissions-223178193" data-sigil="thumb" class="thumb lit" ...>
|
||||||
|
if element["class"].split.include?("lit")
|
||||||
|
deviation_id = element["href"][%r!-(\d+)\z!, 1].to_i
|
||||||
|
element.content = "deviantart ##{deviation_id}"
|
||||||
|
else
|
||||||
|
element.content = ""
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if element.name == "a" && element["href"].present?
|
if element.name == "a" && element["href"].present?
|
||||||
element["href"] = element["href"].gsub(%r!\Ahttps?://www\.deviantart\.com/users/outgoing\?!i, "")
|
element["href"] = element["href"].gsub(%r!\Ahttps?://www\.deviantart\.com/users/outgoing\?!i, "")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user