Skip to content

Instantly share code, notes, and snippets.

@robmcalister
Created August 11, 2013 23:53
Show Gist options
  • Save robmcalister/6207440 to your computer and use it in GitHub Desktop.
Save robmcalister/6207440 to your computer and use it in GitHub Desktop.
Hide Email With Entities
#!/usr/bin/env ruby
email = STDIN.read
url_email = email.gsub(/./) { |c| '%' + c.unpack('H2' * c.size).join('%').upcase }
html_email = url_email[1..-1].split(/%/).collect { |c| sprintf("&#%03d;", c.to_i(16)) }.join
print "<a href=\"mailto:#{url_email}\">#{html_email}</a>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment