class Kramdown::Parser::Kramdown

class KramdownRespec < Kramdown::Parser::Kramdown

Constants

RESPECTESTS
RESPECTESTS_ANNOTATIONS

List of possible annotations If annotation is not in the list, then it should be a reference to a test

RESPECTESTS_START

Public Class Methods

new(source, options) click to toggle source

Create a new Kramdown parser object with the given options.

Calls superclass method
# File lib/kramdown-respec.rb, line 76
def initialize(source, options)
  super

  reset_env

  @alds = {}
  @footnotes = {}
  @link_defs = {}
  update_link_definitions(@options[:link_defs])

  @block_parsers = [:blank_line, :codeblock, :codeblock_fenced, :blockquote, :atx_header,
                    :horizontal_rule, :list, :definition_list, :block_html, :setext_header,
                    :block_math, :table, :footnote_definition, :link_definition, :abbrev_definition,
                    :block_extensions, :eob_marker, :paragraph, :respectests]
  @span_parsers =  [:emphasis, :codespan, :autolink, :span_html, :footnote_marker, :link, :smart_quotes, :inline_math,
                   :span_extensions, :html_entity, :typographic_syms, :line_break, :escaped_chars,
                   :respectests]

end

Public Instance Methods

parse_block_extensions() click to toggle source

Parse one of the block extensions (ALD, block IAL or generic extension) at the current location.

# File lib/kramdown-respec.rb, line 110
def parse_block_extensions
  # Parse the string +str+ and extract the annotation or the list of tests
  if @src.scan(RESPECTESTS_START)
    last_child = @tree.children.last
    if last_child.type == :header
      parse_respec_tests_list(@src[1], last_child.options[:respec_section] ||= {})
      @tree.children << new_block_el(:eob, :respec_section)
    else
      parse_respec_tests_list(@src[1], last_child.options[:ial] ||= {})
      @tree.children << new_block_el(:eob, :ial)
    end
  # Original parser of block extensions
  elsif @src.scan(ALD_START)
    parse_attribute_list(@src[2], @alds[@src[1]] ||= Utils::OrderedHash.new)
    @tree.children << new_block_el(:eob, :ald)
    true
  elsif @src.check(EXT_BLOCK_START)
    parse_extension_start_tag(:block)
  elsif @src.scan(IAL_BLOCK_START)
    if @tree.children.last && @tree.children.last.type != :blank &&
        (@tree.children.last.type != :eob || [:link_def, :abbrev_def, :footnote_def].include?(@tree.children.last.value))
      parse_attribute_list(@src[1], @tree.children.last.options[:ial] ||= Utils::OrderedHash.new)
      @tree.children << new_block_el(:eob, :ial) unless @src.check(IAL_BLOCK_START)
    else
      parse_attribute_list(@src[1], @block_ial ||= Utils::OrderedHash.new)
    end
    true
  else
    false
  end
end
parse_respec_tests_list(str, opts) click to toggle source

Parse the string str and extract the annotation or the list of tests

# File lib/kramdown-respec.rb, line 158
def parse_respec_tests_list(str, opts)
  str = str.strip
  if RESPECTESTS_ANNOTATIONS.include?(str)
    opts['class'] = "#{str}"
  else
    opts['data-tests'] = "#{str}"
  end
end
parse_respectests() click to toggle source
# File lib/kramdown-respec.rb, line 167
def parse_respectests
  last_child = @tree.children.last
  if last_child.type == :header
    parse_respec_tests_list(@src[1], last_child.options[:respec_section] ||= {})
    @tree.children << new_block_el(:eob, :respec_section)
  else
    parse_respec_tests_list(@src[1], last_child.options[:ial] ||= {})
    @tree.children << new_block_el(:eob, :ial)
  end
end
parse_span_extensions() click to toggle source

Parse the extension span at the current location.

# File lib/kramdown-respec.rb, line 179
def parse_span_extensions
  if @src.check(RESPECTESTS_START)
    if (last_child = @tree.children.last) && last_child.type != :text
      @src.pos += @src.matched_size
      attr = {}
      parse_respec_tests_list(@src[1], attr)
      update_ial_with_ial(last_child.options[:ial] ||= {}, attr)
      update_attr_with_ial(last_child.attr, attr)
    else
      warning("Found span respec-test after text - ignoring it")
      add_text(@src.getch)
    end
  # Original parser of span extension
  elsif @src.check(EXT_SPAN_START)
    parse_extension_start_tag(:span)
  elsif @src.check(IAL_SPAN_START)
    if @tree.children.last && @tree.children.last.type != :text
      @src.pos += @src.matched_size
      attr = Utils::OrderedHash.new
      parse_attribute_list(@src[1], attr)
      update_ial_with_ial(@tree.children.last.options[:ial] ||= Utils::OrderedHash.new, attr)
      update_attr_with_ial(@tree.children.last.attr, attr)
    else
      warning("Found span IAL after text - ignoring it")
      add_text(@src.getch)
    end
  else
    add_text(@src.getch)
  end
end