class Kramdown::Parser::Kramdown

Constants

ALD_TYPE_ANY
ALD_TYPE_STYLE_ATTR

Public Instance Methods

parse_attribute_list(str, opts) click to toggle source

Parse the string str and extract all attributes and add all found attributes to the hash opts.

# File lib/darkmouun/kramdown/parser/kramdown/extensions.rb, line 15
def parse_attribute_list(str, opts)
  return if str.strip.empty? || str.strip == ':'
  style_attr = []
  attrs = str.scan(ALD_TYPE_ANY)
  attrs.each do |key, sep, val, style_key, style_val, ref, id_and_or_class, _, _|
    if ref
      (opts[:refs] ||= []) << ref
    elsif id_and_or_class
      id_and_or_class.scan(ALD_TYPE_ID_OR_CLASS).each do |id_attr, class_attr|
        if class_attr
          opts[IAL_CLASS_ATTR] = "#{opts[IAL_CLASS_ATTR]} #{class_attr}".lstrip
        else
          opts['id'] = id_attr
        end
      end
    elsif style_key
      style_attr << (style_key + style_val)
    else
      val.gsub!(/\\(\}|#{sep})/, "\\1")
      if /\Astyle\Z/i =~ key
        style_attr << val
      else
        opts[key] = val
      end
    end
  end
  (opts['style'] = style_attr.join(' ')) unless style_attr.empty?
  warning("No or invalid attributes found in IAL/ALD content: #{str}") if attrs.empty?
end
parse_span() click to toggle source

Parse the span at the current location.

# File lib/darkmouun/kramdown/parser/kramdown/span.rb, line 9
def parse_span
  start_line_number = @src.current_line_number
  saved_pos = @src.save_pos

  span_start = /(?:\[\s*?)/
  result = @src.scan(span_start)
  stop_re = /(?:\s*?\])/

  el = Element.new(:span, nil, nil, :location => start_line_number)
  found = parse_spans(el, stop_re) do
    el.children.size > 0
  end

  if found
    @src.scan(stop_re)
    @tree.children << el
  else
    @src.revert_pos(saved_pos)
    @src.pos += result.length
    add_text(result)
  end
end