Sha256: a6c18663f93b85ba867eca93da2b82a1efac11c1fc473e45cbb3d26856259c9d

Contents?: true

Size: 766 Bytes

Versions: 1

Compression:

Stored size: 766 Bytes

Contents

require 'sanitize'

module Html2rss
  module ItemExtractor
    TEXT = proc { |xml, options| xml.css(options['selector'])&.text }
    ATTRIBUTE = proc { |xml, options| xml.css(options['selector']).attr(options['attribute']) }

    HREF = proc { |xml, options|
      uri = URI(options['channel']['url'])
      uri.path = xml.css(options['selector']).attr('href')
      uri
    }

    HTML = proc { |xml, options|
      html = xml.css(options['selector']).to_s

      Sanitize.fragment(html, Sanitize::Config.merge(
                                Sanitize::Config::RELAXED,
                                add_attributes: {
                                  'a' => { 'rel' => 'nofollow noopener noreferrer' }
                                }
      ))
    }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
html2rss-0.0.1 lib/html2rss/item_extractor.rb