# class Kramdown::Parser::GFM

### Constants

ATX_HEADER_START
ESCAPED_CHARS_GFM
FENCED_CODEBLOCK_MATCH
STRIKETHROUGH_DELIM
STRIKETHROUGH_MATCH

### Public Class Methods

new(source, options) click to toggle source
Calls superclass method Kramdown::Parser::Kramdown.new

    # File lib/kramdown/parser/gfm.rb, line 16
    def initialize(source, options)
      super
      @span_parsers.delete(:line_break) if @options[:hard_wrap]
      {:codeblock_fenced => :codeblock_fenced_gfm,
        :atx_header => :atx_header_gfm}.each do |current, replacement|
        i = @block_parsers.index(current)
        @block_parsers.delete(current)
        @block_parsers.insert(i, replacement)
      end

      i = @span_parsers.index(:escaped_chars)
      @span_parsers[i] = :escaped_chars_gfm if i
      @span_parsers << :strikethrough_gfm
    end

### Public Instance Methods

add_hard_line_breaks(element) click to toggle source

    # File lib/kramdown/parser/gfm.rb, line 36
    def add_hard_line_breaks(element)
      element.children.map! do |child|
        if child.type == :text && child.value =~ /\n/
          children = []
          lines = child.value.split(/\n/, -1)
          omit_trailing_br = (Kramdown::Element.category(element) == :block && element.children[-1] == child &&
                              lines[-1].empty?)
          lines.each_with_index do |line, index|
            new_element_options = { :location => child.options[:location] + index }

            children << Element.new(:text, (index > 0 ? "\n#{line}" : line), nil, new_element_options)
            children << Element.new(:br, nil, nil, new_element_options) if index < lines.size - 2 ||
              (index == lines.size - 2 && !omit_trailing_br)
          end
          children
        elsif child.type == :html_element
          child
        else
          add_hard_line_breaks(child)
          child
        end
      end.flatten!
    end

parse() click to toggle source
Calls superclass method Kramdown::Parser::Kramdown#parse

    # File lib/kramdown/parser/gfm.rb, line 31
    def parse
      super
      add_hard_line_breaks(@root) if @options[:hard_wrap]
    end

parse_strikethrough_gfm() click to toggle source

    # File lib/kramdown/parser/gfm.rb, line 70
    def parse_strikethrough_gfm
      line_number = @src.current_line_number

      @src.pos += @src.matched_size
      el = Element.new(:html_element, 'del', {}, :category => :span, :line => line_number)
      @tree.children << el

      env = save_env
      reset_env(:src => Kramdown::Utils::StringScanner.new(@src.matched[2..-3], line_number),
                :text_type => :text)
      parse_spans(el)
      restore_env(env)

      el
    end