Class: Asciidoctor::DocTest::HTML::Converter

Inherits:
AsciidocConverter show all
Defined in:
lib/asciidoctor/doctest/html/converter.rb

Instance Attribute Summary

Attributes inherited from AsciidocConverter

#default_opts

Instance Method Summary collapse

Methods inherited from AsciidocConverter

#convert

Constructor Details

#initialize(paragraph_xpath: './p/node()', **opts) ⇒ Converter

Returns a new instance of Converter


13
14
15
16
# File 'lib/asciidoctor/doctest/html/converter.rb', line 13

def initialize(paragraph_xpath: './p/node()', **opts)
  @paragraph_xpath = paragraph_xpath
  super opts
end

Instance Method Details

#convert_examples(input_exmpl, output_exmpl) ⇒ void


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/asciidoctor/doctest/html/converter.rb', line 18

def convert_examples(input_exmpl, output_exmpl)
  opts = input_exmpl.opts.merge(output_exmpl.opts)

  # The header & footer are excluded by default; always enable for document examples.
  opts[:header_footer] ||= input_exmpl.name.start_with?('document')

  # When asserting inline examples, defaults to ignore paragraph "wrapper".
  opts[:include] ||= (@paragraph_xpath if input_exmpl.name.start_with? 'inline_')

  actual = convert(input_exmpl.content, header_footer: opts[:header_footer])
    .then { |s| parse_html s }
    .then { |h| find_nodes h, opts[:include] }
    .then { |h| remove_nodes h, opts[:exclude] }
    .then { |h| normalize h }

  expected = normalize(output_exmpl.content)

  [actual, expected]
end