Class: Markdownator::Converters::Html
- Defined in:
- lib/markdownator/converters/html.rb
Overview
Converts HTML into Markdown by walking the Nokogiri node tree.
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
26 27 28 29 30 |
# File 'lib/markdownator/converters/html.rb', line 26 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.
19 20 21 22 23 24 |
# File 'lib/markdownator/converters/html.rb', line 19 def self.html_to_markdown(html) Markdownator.require_optional("nokogiri", feature: "HTML conversion") doc = Nokogiri::HTML(html) root = doc.at_css("body") || doc.root || doc Renderers::HtmlRenderer.new.render(root) end |
Instance Method Details
#accepts?(_io, stream_info) ⇒ Boolean
9 10 11 |
# File 'lib/markdownator/converters/html.rb', line 9 def accepts?(_io, stream_info) matches?(stream_info, extensions: %w[html htm], mimetypes: %w[text/html application/xhtml+xml]) end |