Class: HtmlToMarkdown

Inherits:
Object
  • Object
show all
Defined in:
lib/html_to_markdown.rb

Instance Method Summary collapse

Constructor Details

#initialize(html, opts = {}) ⇒ HtmlToMarkdown

Returns a new instance of HtmlToMarkdown.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/html_to_markdown.rb', line 6

def initialize(html, opts = {})
  @opts = opts

  # we're only interested in <body>
  @doc = Nokogiri.HTML5(html).at("body")

  remove_not_allowed!(@doc)
  remove_hidden!(@doc)
  hoist_line_breaks!(@doc)
  remove_whitespaces!(@doc)
end

Instance Method Details

#to_markdownObject



18
19
20
# File 'lib/html_to_markdown.rb', line 18

def to_markdown
  traverse(@doc).gsub(/\n{2,}/, "\n\n").strip
end