Class: MarkdownComposer::DocumentIndex::HtmlParser

Inherits:
Object
  • Object
show all
Defined in:
lib/markdown_composer/document_index/html_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, diagnostics:) ⇒ HtmlParser

Returns a new instance of HtmlParser.



14
15
16
17
# File 'lib/markdown_composer/document_index/html_parser.rb', line 14

def initialize(source, diagnostics:)
  @source = source
  @diagnostics = diagnostics
end

Instance Attribute Details

#diagnosticsObject (readonly)

Returns the value of attribute diagnostics.



12
13
14
# File 'lib/markdown_composer/document_index/html_parser.rb', line 12

def diagnostics
  @diagnostics
end

#sourceObject (readonly)

Returns the value of attribute source.



12
13
14
# File 'lib/markdown_composer/document_index/html_parser.rb', line 12

def source
  @source
end

Instance Method Details

#indexObject



19
20
21
22
23
# File 'lib/markdown_composer/document_index/html_parser.rb', line 19

def index
  fragment = Nokogiri::HTML5.fragment(source.html.to_s)
  markdown = html_to_markdown(fragment)
  DocumentIndex.from_markdown(markdown, source_key: source.key, diagnostics: diagnostics)
end