Class: Html2rss::Selectors::PostProcessors::MarkdownToHtml
- Defined in:
- lib/html2rss/selectors/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:
Section
Price: 12.34
Constant Summary collapse
- DESCRIPTION =
JSON Schema description exported via
schema_doc. 'Convert Markdown to HTML (Kramdown) and sanitize the result. ' \ 'Often chained after `template`.'
- EXAMPLES =
Example post-process objects for JSON Schema
examples. [ { 'name' => 'markdown_to_html' } ].freeze
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
-
.schema_doc ⇒ Hash{Symbol => Object}
JSON Schema fragment for this post-processor.
- .validate_args!(value, context) ⇒ void
Instance Method Summary collapse
-
#get ⇒ String
Converts Markdown to sanitized HTML.
Methods inherited from Base
assert_type, expect_options, #initialize
Constructor Details
This class inherits a constructor from Html2rss::Selectors::PostProcessors::Base
Class Method Details
.schema_doc ⇒ Hash{Symbol => Object}
Returns JSON Schema fragment for this post-processor.
46 |
# File 'lib/html2rss/selectors/post_processors/markdown_to_html.rb', line 46 def self.schema_doc = SchemaDoc.for_post_processor(name: :markdown_to_html, klass: self) |
.validate_args!(value, context) ⇒ void
This method returns an undefined value.
51 52 53 |
# File 'lib/html2rss/selectors/post_processors/markdown_to_html.rb', line 51 def self.validate_args!(value, context) assert_type value, String, :value, context: end |
Instance Method Details
#get ⇒ String
Converts Markdown to sanitized HTML.
59 60 61 62 |
# File 'lib/html2rss/selectors/post_processors/markdown_to_html.rb', line 59 def get html_content = Kramdown::Document.new(value).to_html SanitizeHtml.new(html_content, context).get end |