Sha256: 2b883f587947ee0a9914ebcfaf158f2237cd90cbb8df621bc2903975a4719238

Contents?: true

Size: 624 Bytes

Versions: 3

Compression:

Stored size: 624 Bytes

Contents

module Boilerpipe::SAX
  class BoilerpipeHTMLParser
    def self.parse(text)
      # script bug - delete script tags
      text.gsub!(/\<script>.+?<\/script>/i, '')

      # nokogiri uses libxml for mri and nekohtml for jruby
      # mri doesn't remove &nbsp; when missing the semicolon
      text.gsub!(/(&nbsp) /, '\1; ')

      # use nokogiri to fix any bad tags, errors - keep experimenting with this
      text = Nokogiri::HTML(text).to_html

      handler = HTMLContentHandler.new
      noko_parser = Nokogiri::HTML::SAX::Parser.new(handler)
      noko_parser.parse(text)
      handler.text_document
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
boilerpipe-ruby-0.4.3 lib/boilerpipe/sax/boilerpipe_html_parser.rb
boilerpipe-ruby-0.4.2 lib/boilerpipe/sax/boilerpipe_html_parser.rb
boilerpipe-ruby-0.4.1 lib/boilerpipe/sax/boilerpipe_html_parser.rb