+ def wikimedia_commons_link(key, value)
+ if key == "wikimedia_commons" && value =~ /^(?:file|category):/i
+ return {
+ :url => "//commons.wikimedia.org/wiki/#{value}?uselang=#{I18n.locale}",
+ :title => value
+ }
+ end
+ nil
+ end
+
+ def email_links(_key, value)
+ # Does value look like an email? eg "someone@domain.tld"
+ # or a list of alternate emails separated by ;
+
+ # Uses WHATWG implementation of email validation, which follows RFC 1123
+ # but is a willful violation of RFC 5322.
+ # (see: https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address)
+ if value.match?(%r{^\s*[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+
+ @[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*\s*
+ (;\s*[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+
+ @[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*\s*)*$
+ }x)
+ return value.split(";").map do |email|
+ # remove any leading or trailing whitespace if present
+ email = email.strip
+
+ # add 'mailto:'' prefix
+ { :email => email, :url => "mailto:#{email}" }
+ end
+ end
+ nil
+ end
+