Class: Markdownator::Converters::Html
- Defined in:
- lib/markdownator/converters/html.rb
Overview
Converts HTML into Markdown using reverse_markdown (Nokogiri-backed).
Class Method Summary collapse
- .extract_title(html) ⇒ Object
-
.html_to_markdown(html) ⇒ Object
Shared so other container converters (EPUB) can reuse HTML conversion.
Instance Method Summary collapse
Class Method Details
.extract_title(html) ⇒ Object
22 23 24 25 26 |
# File 'lib/markdownator/converters/html.rb', line 22 def self.extract_title(html) Markdownator.require_optional("nokogiri", feature: "HTML conversion") title = Nokogiri::HTML(html).at_css("title")&.text&.strip title unless title.nil? || title.empty? end |
.html_to_markdown(html) ⇒ Object
Shared so other container converters (EPUB) can reuse HTML conversion.
17 18 19 20 |
# File 'lib/markdownator/converters/html.rb', line 17 def self.html_to_markdown(html) Markdownator.require_optional("reverse_markdown", feature: "HTML conversion") ReverseMarkdown.convert(html, unknown_tags: :bypass, github_flavored: true).strip end |
Instance Method Details
#accepts?(_io, stream_info) ⇒ Boolean
7 8 9 |
# File 'lib/markdownator/converters/html.rb', line 7 def accepts?(_io, stream_info) matches?(stream_info, extensions: %w[html htm], mimetypes: %w[text/html application/xhtml+xml]) end |