Sha256: 35ce1b5ea5b5dfe781f5f3fd340c2051b40c7cbacee982bd52a697e7c5bc8a40
Contents?: true
Size: 1.19 KB
Versions: 1
Compression:
Stored size: 1.19 KB
Contents
module PrawnRailsHelper ## # Removes all html tags from the string # @param html[String] string to remove the tags # @return [String] the string with out the tags ## def html_strip html return html if html.nil? html text = html. gsub(/( |\n|\s)+/im, ' ').squeeze(' ').strip. gsub(/<([^\s]+)[^>]*(src|href)=\s*(.?)([^>\s]*)\3[^>]*>\4<\/\1>/i, '\4') links = [] linkregex = /<[^>]*(src|href)=\s*(.?)([^>\s]*)\2[^>]*>\s*/i while linkregex.match(text) links << $~[3] text.sub!(linkregex, "[#{links.size}]") end text = 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 = text + "\n [#{i+1}] <#{CGI.unescapeHTML(links[i])}>" unless links[i].nil? end links = nil text end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
prawn-rails-0.0.2 | lib/prawn-rails/prawn_rails_helper.rb |