Class: Html2rss::AttributePostProcessors::HtmlToMarkdown

Inherits:
Object
  • Object
show all
Defined in:
lib/html2rss/attribute_post_processors/html_to_markdown.rb

Overview

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'

Instance Method Summary collapse

Constructor Details

#initialize(value, env) ⇒ HtmlToMarkdown

Returns a new instance of HtmlToMarkdown.

Parameters:



33
34
35
# File 'lib/html2rss/attribute_post_processors/html_to_markdown.rb', line 33

def initialize(value, env)
  @sanitized_value = SanitizeHtml.new(value, env).get
end

Instance Method Details

#getString

Returns formatted in Markdown.

Returns:

  • (String)

    formatted in Markdown



39
40
41
# File 'lib/html2rss/attribute_post_processors/html_to_markdown.rb', line 39

def get
  ReverseMarkdown.convert(@sanitized_value)
end