Class: Html2Md

Inherits:
Object
  • Object
show all
Defined in:
lib/html2md.rb,
lib/html2md/VERSION.rb,
lib/html2md/document.rb

Defined Under Namespace

Classes: Document

Constant Summary collapse

VERSION =
"0.1.2"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source = nil, options = {}) ⇒ Html2Md

Returns a new instance of Html2Md.



8
9
10
11
# File 'lib/html2md.rb', line 8

def initialize(source =nil , options = {})
  @options = options
  @source = source
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



6
7
8
# File 'lib/html2md.rb', line 6

def options
  @options
end

#sourceObject

Returns the value of attribute source.



6
7
8
# File 'lib/html2md.rb', line 6

def source
  @source
end

Instance Method Details

#parseObject



13
14
15
16
17
18
19
# File 'lib/html2md.rb', line 13

def parse()
  doc = Html2Md::Document.new()
  doc.relative_url = options[:relative_url]
  parser = Nokogiri::HTML::SAX::Parser.new(doc)
  parser.parse( CGI.unescapeHTML(source).gsub(/\r/," ") )
  parser.document.markdown
end