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


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

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


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

alias_method :configure_parser_raw, :configure_parser

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


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

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


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

alias_method :handle_extension_raw, :handle_extension

#parse_codeblock_fenced_gfmObject


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

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


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

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