Sha256: c75ca9856d6f62118d1c417424866e0efa2bdfc655cabf2c15f9fc6f317f8251

Contents?: true

Size: 958 Bytes

Versions: 10

Compression:

Stored size: 958 Bytes

Contents

require 'reverse_markdown'

module Html2rss
  module AttributePostProcessors
    ##
    # Returns HTML code as Markdown formatted String.
    # Before converting to markdown, the HTML is sanitized with SanitizeHtml.
    # Imagine this HTML structure:
    #
    #     <section>
    #       Lorem <b>ipsum</b> dolor...
    #       <iframe src="https://evil.corp/miner"></iframe>
    #       <script>alert();</script>
    #     </section>
    #
    # YAML usage example:
    #
    #    selectors:
    #      description:
    #        selector: section
    #        extractor: html
    #        post_process:
    #          name: html_to_markdown
    #
    # Would return:
    #    'Lorem **ipsum** dolor'
    class HtmlToMarkdown
      def initialize(value, env)
        @value = SanitizeHtml.new(value, env).get
      end

      ##
      # @return [String] formatted in Markdown
      def get
        ReverseMarkdown.convert @value
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
html2rss-0.9.0 lib/html2rss/attribute_post_processors/html_to_markdown.rb
html2rss-0.8.2 lib/html2rss/attribute_post_processors/html_to_markdown.rb
html2rss-0.8.1 lib/html2rss/attribute_post_processors/html_to_markdown.rb
html2rss-0.8.0 lib/html2rss/attribute_post_processors/html_to_markdown.rb
html2rss-0.7.0 lib/html2rss/attribute_post_processors/html_to_markdown.rb
html2rss-0.6.0 lib/html2rss/attribute_post_processors/html_to_markdown.rb
html2rss-0.5.2 lib/html2rss/attribute_post_processors/html_to_markdown.rb
html2rss-0.5.1 lib/html2rss/attribute_post_processors/html_to_markdown.rb
html2rss-0.5.0 lib/html2rss/attribute_post_processors/html_to_markdown.rb
html2rss-0.4.1 lib/html2rss/attribute_post_processors/html_to_markdown.rb