Class: Html2rss::Selectors::PostProcessors::HtmlToMarkdown
- Defined in:
- lib/html2rss/selectors/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'
Constant Summary collapse
- DESCRIPTION =
JSON Schema description exported via
schema_doc. 'Sanitize HTML then convert it to Markdown (via ReverseMarkdown).'- EXAMPLES =
Example post-process objects for JSON Schema
examples. [ { 'name' => 'html_to_markdown' } ].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
Formatted in Markdown.
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.
40 |
# File 'lib/html2rss/selectors/post_processors/html_to_markdown.rb', line 40 def self.schema_doc = SchemaDoc.for_post_processor(name: :html_to_markdown, klass: self) |
.validate_args!(value, context) ⇒ void
This method returns an undefined value.
45 46 47 |
# File 'lib/html2rss/selectors/post_processors/html_to_markdown.rb', line 45 def self.validate_args!(value, context) assert_type value, String, :value, context: end |
Instance Method Details
#get ⇒ String
Returns formatted in Markdown.
51 52 53 54 55 |
# File 'lib/html2rss/selectors/post_processors/html_to_markdown.rb', line 51 def get sanitized_value = SanitizeHtml.new(value, context).get ReverseMarkdown.convert(sanitized_value) end |