Class: Html2rss::AttributePostProcessors::MarkdownToHtml

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

Overview

Generates HTML from Markdown.

It’s particularly useful in conjunction with the Template post processor to generate a description from other selectors.

YAML usage example:

selectors:
  description:
    selector: section
    post_process:
      - name: template
        string: |
          # %s

          Price: %s
        methods:
          - self
          - price
      - name: markdown_to_html

Would e.g. return:

<h1>Section</h1>

<p>Price: 12.34</p>

Instance Method Summary collapse

Constructor Details

#initialize(value, env) ⇒ MarkdownToHtml

Returns a new instance of MarkdownToHtml.

Parameters:

  • value (String)

    Markdown content to convert to HTML

  • env (Item::Context)

    Context object providing additional environment details



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

def initialize(value, env)
  @value = value
  @env = env
end

Instance Method Details

#getString

Converts Markdown to sanitized HTML.

Returns:

  • (String)

    Sanitized HTML content



48
49
50
51
# File 'lib/html2rss/attribute_post_processors/markdown_to_html.rb', line 48

def get
  html_content = Kramdown::Document.new(@value).to_html
  SanitizeHtml.new(html_content, @env).get
end