class Kramdown::Converter::Html

class HtmlRESPEC < Html

Public Class Methods

new(root, options) click to toggle source

Initialize the HTML converter with the given Kramdown document doc.

Calls superclass method
# File lib/kramdown-respec.rb, line 244
def initialize(root, options)
  super
  @footnote_counter = @footnote_start = @options[:footnote_nr]
  @footnotes = []
  @footnotes_by_name = {}
  @footnote_location = nil
  @toc = []
  @toc_code = nil
  @indent = 2
  @stack = []
  @respec_first_section = true
  @respec_last_header_level = 0
end

Public Instance Methods

convert_header(el, indent) click to toggle source

def convert_root(el, indent)

result = super
# Close the last sections that remain opened
current_header_level = 2
while @respec_last_header_level > current_header_level
  result += "</section>\n\n"
  @respec_last_header_level -= 1
end
result + "</section>\n\n"

end

# File lib/kramdown-respec.rb, line 300
def convert_header(el, indent)
  res = ""
  current_header_level = el.options[:level]
  if @respec_first_section
    @respec_first_section = false
    @respec_last_header_level = current_header_level
  else
    if @respec_last_header_level < current_header_level
      @respec_last_header_level = current_header_level
    else
      while @respec_last_header_level > current_header_level
        res += "#{' ' * indent}</section>\n\n"
        @respec_last_header_level -= 1
      end
      res += "#{' ' * indent}</section>\n\n"
    end
  end
  if el.options[:respec_section]
    res += "#{' ' * indent}<section#{html_attributes(el.options[:respec_section])}>\n"
  else
    res += "#{' ' * indent}<section>\n"
  end
  # res + super

  attr = el.attr.dup
  if @options[:auto_ids] && !attr['id']
    attr['id'] = generate_id(el.options[:raw_text])
  end
  @toc << [el.options[:level], attr['id'], el.children] if attr['id'] && in_toc?(el)
  level = output_header_level(el.options[:level])
  res + format_as_block_html("h#{level}", attr, inner(el, indent), indent)
end
convert_root(el, indent) click to toggle source

Initialize the HTML converter with the given Kramdown document doc. def initialize(root, options)

super
@respec_first_section = true
@respec_last_header_level = 0

end

# File lib/kramdown-respec.rb, line 264
def convert_root(el, indent)
  result = inner(el, indent)
  if @footnote_location
    result.sub!(/#{@footnote_location}/, footnote_content.gsub(/\\/, "\\\\\\\\"))
  else
    result << footnote_content
  end
  if @toc_code
    toc_tree = generate_toc_tree(@toc, @toc_code[0], @toc_code[1] || {})
    text = if toc_tree.children.size > 0
             convert(toc_tree, 0)
           else
             ''
           end
    result.sub!(/#{@toc_code.last}/, text.gsub(/\\/, "\\\\\\\\"))
  end
  # Close the last sections that remain opened
  current_header_level = 2
  while @respec_last_header_level > current_header_level
    result += "</section>\n\n"
    @respec_last_header_level -= 1
  end
  result + "</section>\n\n"
  result
end