------=_Part_110378_8267316.1136952806778
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
i like this code i found, i did not make but found. and i wish i could give
credit to who created it but i lost the website
require 'cgi'
def html2text html
text =3D html.
gsub(/( |\n|\s)+/im, ' ').squeeze(' ').strip.
gsub(/<([^\s]+)[^>]*(src|href)=3D\s*(.?)([^>\s]*)\3[^>]*>\4<\/\1>/i, '\=
4')
links =3D []
linkregex =3D /<[^>]*(src|href)=3D\s*(.?)([^>\s]*)\2[^>]*>\s*/i
while linkregex.match(text)
links << $~[3]
text.sub!(linkregex, "[#{links.size}]")
end
text =3D CGI.unescapeHTML(
text.
gsub(/<(script|style)[^>]*>.*<\/\1>/im, '').
gsub(/<!--.*-->/m, '').
gsub(/<hr(| [^>]*)>/i, "___\n").
gsub(/<li(| [^>]*)>/i, "\n* ").
gsub(/<blockquote(| [^>]*)>/i, '> ').
gsub(/<(br)(| [^>]*)>/i, "\n").
gsub(/<(\/h[\d]+|p)(| [^>]*)>/i, "\n\n").
gsub(/<[^>]*>/, '')
).lstrip.gsub(/\n[ ]+/, "\n") + "\n"
for i in (0...links.size).to_a
text =3D text + "\n [#{i+1}] <#{CGI.unescapeHTML(links
)}>" unless
links.nil?
end
links =3D nil
text
end
input =3D" <h1>Title</h1> This is the body. Testing <a href=3D'
http://www.google.com/'>link to Google</a>.<p /> Testing image <img
src=3D'/noimage.png'>.<br /> The End."
print html2text(input)