class Kramdown::Parser::Sekd

Constants

COLUMN_MATCH
DEFINITION_TABLE_MATCH
DIV_MATCH
FENCED_CODEBLOCK_MATCH
FOOTNOTE_DEFINITION_START
FOOTNOTE_MARKER_START
LANG_BY_EXT
LIST_START_OL
PAGE_MATCH
WRAPAROUND_MATCH

Public Class Methods

new(source, options) click to toggle source
Calls superclass method
# File lib/zine_brewer/kramdown/parser/sekd.rb, line 15
def initialize(source, options)
  super

  parsers_replacing = {
    :@block_parsers => {:codeblock_fenced => :codeblock_fenced_sekd,
                        :footnote_definition => :footnote_definition_sekd},
    :@span_parsers  => {:footnote_marker => :footnote_marker_sekd}
  }
  parsers_replacing.each do |target, definitions|
    target_instance = instance_variable_get(target)
      definitions.each do |current, replacement|
      target_instance[target_instance.index(current)] = replacement
    end
  end

  @block_parsers.insert(5, :column, :definition_table, :wraparound,:div, :page)

  @page = 0
  @fn_counter = 0
  @fn_number = Hash.new{|h, k| h[k] = (@fn_counter += 1).to_s }
end

Public Instance Methods

parse_codeblock_fenced_sekd() click to toggle source

Parse the fenced codeblock at the current location code highlighting by Google Prettify.

# File lib/zine_brewer/kramdown/parser/sekd.rb, line 41
def parse_codeblock_fenced_sekd
  if @src.check(self.class::FENCED_CODEBLOCK_MATCH)
    start_line_number = @src.current_line_number
    @src.pos += @src.matched_size
    el = new_block_el(:codeblock, @src[4].chomp, nil, :location => start_line_number)
    lang, linenums = @src[3].to_s.strip.split(/:/)
    lang_ext = LANG_BY_EXT[lang] || lang
    el.attr['class'] = "prettyprint" + (lang_ext.nil? ? ' nocode' : " lang-#{lang_ext}")
    el.attr['class'] += " linenums:#{linenums}" unless linenums.nil?
    @tree.children << el
    true
  else
    false
  end
end
parse_column() click to toggle source
# File lib/zine_brewer/kramdown/parser/sekd.rb, line 104
def parse_column
  if @src.check(self.class::COLUMN_MATCH)
    start_line_number = @src.current_line_number
    @src.pos += @src.matched_size
    el = Element.new(:column, nil, {'class' => 'columnSection'}, :location => start_line_number)
    parse_blocks(el, @src[1])
    update_attr_with_ial(el.attr, @block_ial) unless @block_ial.nil?
    @tree.children << el
    true
  else
    false
  end
end
parse_definition_table() click to toggle source
# File lib/zine_brewer/kramdown/parser/sekd.rb, line 121
def parse_definition_table
  if @src.check(self.class::DEFINITION_TABLE_MATCH)
    start_line_number = @src.current_line_number
    @src.pos += @src.matched_size
    el = Element.new(:definition_table, nil, nil, :location => start_line_number)
    parse_blocks(el, @src[1])
    update_attr_with_ial(el.attr, @block_ial) unless @block_ial.nil?
    @tree.children << el
    true
  else
    false
  end
end
parse_div() click to toggle source
# File lib/zine_brewer/kramdown/parser/sekd.rb, line 70
def parse_div
  if @src.check(self.class::DIV_MATCH)
    start_line_number = @src.current_line_number
    @src.pos += @src.matched_size
    el = Element.new(:div, nil, nil, :location => start_line_number)
    parse_blocks(el, @src[1])
    update_attr_with_ial(el.attr, @block_ial) unless @block_ial.nil?
    @tree.children << el
    true
  else
    false
  end
end
parse_footnote_definition_sekd() click to toggle source
# File lib/zine_brewer/kramdown/parser/sekd.rb, line 154
def parse_footnote_definition_sekd
  start_line_number = @src.current_line_number
  @src.pos += @src.matched_size
  if @fn_number.has_key?(@src[1])
    warning("Duplicate footnote name '#{@src[1]}' on line #{start_line_number} - overwriting")
  end
  a = %!<a href="#fnref:#{@fn_number[@src[1]]}">\\[#{@fn_number[@src[1]]}\\]</a>: #{@src[2].strip}!
  p = new_block_el(:p, nil, {'id' => "fn:#{@fn_number[@src[1]]}"})
  p.children << new_block_el(:raw_text, a, nil)
  if @tree.children.last.type == :footnote_definition_sekd
    @tree.children.last.children << p
  elsif [-1, -2].map{|i| @tree.children[i].type } == [:blank, :footnote_definition_sekd]
    @tree.children.pop
    @tree.children.last.children << p
  else
    f = new_block_el(:footnote_definition_sekd, nil, {'class' => 'columnSection footnotes'},
                     :location => start_line_number)
    f.children << p
    @tree.children << f
  end
  true
end
parse_footnote_marker_sekd() click to toggle source
# File lib/zine_brewer/kramdown/parser/sekd.rb, line 180
def parse_footnote_marker_sekd
  start_line_number = @src.current_line_number
  @src.pos += @src.matched_size
  unless @fn_number.has_key?(@src[1])
    warning("No footnote marker '#{@src[1]}' on line #{start_line_number} - missing")
  end
  @tree.children << new_block_el(:footnote_marker_sekd, @fn_number[@src[1]], nil,
                                 :location => start_line_number)
end
parse_page() click to toggle source
# File lib/zine_brewer/kramdown/parser/sekd.rb, line 139
def parse_page
  if @src.check(self.class::PAGE_MATCH)
    start_line_number = @src.current_line_number
    @src.pos += @src.matched_size
    page = (@page > 0 ? "</div>\n<!-- page_delimiter -->\n" : '') + "<div id=\"p#{@page+=1}\">"
    @tree.children << new_block_el(:page, page, nil, :location => start_line_number)
    true
  else
    false
  end
end
parse_wraparound() click to toggle source
# File lib/zine_brewer/kramdown/parser/sekd.rb, line 87
def parse_wraparound
  if @src.check(self.class::WRAPAROUND_MATCH)
    start_line_number = @src.current_line_number
    @src.pos += @src.matched_size
    el = Element.new(:div, nil, {'class' => 'imgLRBlock cf'}, :location => start_line_number)
    parse_blocks(el, @src[1])
    update_attr_with_ial(el.attr, @block_ial) unless @block_ial.nil?
    @tree.children << el
    true
  else
    false
  end
end