class Kramdown::Parser::Marsdawn

Public Class Methods

front_matter() click to toggle source
# File lib/marsdawn/source/kramdown/parser.rb, line 5
def self.front_matter
  @@front_matter
end

Public Instance Methods

handle_extension(name, opts, body, type) click to toggle source
Calls superclass method
# File lib/marsdawn/source/kramdown/parser.rb, line 26
def handle_extension(name, opts, body, type)
  case name
  when 'front_matter'
    opts.each do |key, val|
      @@front_matter[key.to_sym] = val
      @@front_matter[:link_key] = val if key == 'title'
    end
    true
  else
    super name, opts, body, type
  end
end
parse() click to toggle source
Calls superclass method
# File lib/marsdawn/source/kramdown/parser.rb, line 9
def parse
  @@front_matter = {}
  super
end
parse_atx_header() click to toggle source
Calls superclass method
# File lib/marsdawn/source/kramdown/parser.rb, line 20
def parse_atx_header
  ret = super
  handle_header @src[2].to_s.strip, @src[1].length
  ret
end
parse_setext_header() click to toggle source
Calls superclass method
# File lib/marsdawn/source/kramdown/parser.rb, line 14
def parse_setext_header
  ret = super
  handle_header @src[1], @src[3].to_i
  ret
end

Private Instance Methods

add_title_vars(title) click to toggle source
# File lib/marsdawn/source/kramdown/parser.rb, line 45
def add_title_vars title
  @@front_matter[:title] = title unless @@front_matter.key?(:title)
  @@front_matter[:link_key] = title unless @@front_matter.key?(:link_key)
end
handle_header(title, level) click to toggle source
# File lib/marsdawn/source/kramdown/parser.rb, line 40
def handle_header title, level
  add_title_vars title
  insert_title_anchor title if level < 4
end
insert_title_anchor(title) click to toggle source
# File lib/marsdawn/source/kramdown/parser.rb, line 50
def insert_title_anchor title
  anchor_name = title.downcase.gsub(' ', '-')
  @tree.children.last.children.insert 0, Element.new(:raw, %!<a name="#{anchor_name}"></a>!, 'type' => 'html')
  @@front_matter[:anchors] ||= {}
  @@front_matter[:anchors][title] = anchor_name
end