handle more edge cases in archor tagger
parent
e3ecc0871c
commit
e14d543edd
|
@ -36,18 +36,21 @@ class Sanitize
|
||||||
href = node['href']
|
href = node['href']
|
||||||
return if href == node.text.strip
|
return if href == node.text.strip
|
||||||
|
|
||||||
# remove query string from link text
|
# href matches link text with sanitized query string?
|
||||||
node.inner_html = node.inner_html.sub(/\?\S+=\S+/, '')
|
text = Sanitize::sanitize_query_string(node.text.strip)
|
||||||
|
if href == text
|
||||||
# href matches link text without query string?
|
node.inner_html = "\u2728 #{node.inner_html}"
|
||||||
text = node.text.strip
|
return
|
||||||
return if href == text
|
end
|
||||||
|
|
||||||
# strip ellipse & replace keyword search obscuring
|
# strip ellipse & replace keyword search obscuring
|
||||||
text = text.sub(/ *(?:\u2026|\.\.\.)\Z/, '').gsub(/ dot /i, '.').gsub(/[\u200b-\u200d\ufeff\u200e\u200f]/, '')
|
text = text.sub(/ *(?:\u2026|\.\.\.)\Z/, '').gsub(/ dot /i, '.').gsub(/[\u200b-\u200d\ufeff\u200e\u200f]/, '')
|
||||||
|
|
||||||
# href now matches text without obscuring?
|
# href now matches text without obscuring?
|
||||||
return if href == text
|
if href == text
|
||||||
|
node.inner_html = "\u2728 #{node.inner_html}"
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
# try to detect filenames
|
# try to detect filenames
|
||||||
href_filename = '/'.in?(href) ? href.rpartition('/')[2] : nil
|
href_filename = '/'.in?(href) ? href.rpartition('/')[2] : nil
|
||||||
|
@ -57,10 +60,10 @@ class Sanitize
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
# many fedi servers obfuscate media filenames
|
# possibly linked media?
|
||||||
ext = text.rpartition('.')[-1]
|
ext = href_filename.rpartition('.')[2]
|
||||||
if ext.downcase.in?(MEDIA_EXTENSIONS) && ext == href_filename.rpartition('.')[2]
|
if ext.downcase.in?(MEDIA_EXTENSIONS)
|
||||||
node.inner_html = "\xf0\x9f\x93\x8e #{node.inner_html}"
|
node.inner_html = "\xf0\x9f\x96\xbc\xef\xb8\x8f #{node.inner_html}"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue