Class: Kramdown::Parser::Kramdown

Inherits:
Object
  • Object
show all
Defined in:
lib/rabbit/parser/markdown.rb

Constant Summary collapse

STRIKETHROUGH_DELIMITER =
"~~"
STRIKETHROUGH_DELIMITER_PATTERN =
/#{Regexp.escape(STRIKETHROUGH_DELIMITER)}/

Instance Method Summary collapse

Instance Method Details

#configure_parserObject



37
38
39
40
41
42
43
# File 'lib/rabbit/parser/markdown.rb', line 37

def configure_parser
  @span_parsers.unshift(:strikethrough)
  position = @block_parsers.index(:codeblock_fenced)
  @block_parsers.insert(position, :codeblock_fenced_gfm)

  configure_parser_raw
end

#configure_parser_rawObject



36
# File 'lib/rabbit/parser/markdown.rb', line 36

alias_method :configure_parser_raw, :configure_parser

#handle_extension(name, opts, body, type, line_no = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rabbit/parser/markdown.rb', line 11

def handle_extension(name, opts, body, type, line_no=nil)
  return true if handle_extension_raw(name, opts, body, type, line_no)
  element = Element.new(name.to_sym,
                        nil,
                        opts,
                        :category => type,
                        :location => line_no)
  if body
    root, warnings = self.class.parse(body, @options)
    fix_location(root, line_no)
    if type == :span
      p_element = root.children.first
      p_element.children.each do |sub_element|
        element.children << sub_element
      end
    else
      root.children.each do |sub_element|
        element.children << sub_element
      end
    end
  end
  @tree.children << element
  true
end

#handle_extension_rawObject



10
# File 'lib/rabbit/parser/markdown.rb', line 10

alias_method :handle_extension_raw, :handle_extension

#parse_codeblock_fenced_gfmObject



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/rabbit/parser/markdown.rb', line 74

def parse_codeblock_fenced_gfm
  original_match = self.class::FENCED_CODEBLOCK_MATCH
  begin
    self.class.send(:remove_const, :FENCED_CODEBLOCK_MATCH)
    self.class.const_set(:FENCED_CODEBLOCK_MATCH,
                         GFM::FENCED_CODEBLOCK_MATCH)
    parse_codeblock_fenced
  ensure
    self.class.send(:remove_const, :FENCED_CODEBLOCK_MATCH)
    self.class.const_set(:FENCED_CODEBLOCK_MATCH, original_match)
  end
end

#parse_strikethroughObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rabbit/parser/markdown.rb', line 48

def parse_strikethrough
  start_line_number = @src.current_line_number

  delimiter = @src.scan(STRIKETHROUGH_DELIMITER_PATTERN)
  saved_pos = @src.save_pos

  text = @src.scan_until(STRIKETHROUGH_DELIMITER_PATTERN)
  if text
    text = text.sub(/#{STRIKETHROUGH_DELIMITER_PATTERN}\Z/, "")
    @tree.children << Element.new(:strikethrough, text, nil,
                                  :location => start_line_number)
  else
    @src.revert_pos(saved_pos)
    add_text(delimiter)
  end
end