Method: Markascend::Parser#parse

Defined in:
lib/markascend/parser.rb

#parseObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/markascend/parser.rb', line 24

def parse
  @out = []
  while parse_new_line or parse_rec_block or parse_hx or parse_block_code or parse_paragraph
  end
  unless @src.eos?
    @env.warn 'reached end of input'
  end
  @env.srcs.pop

  @out.map! do |(node, content)|
    case node
    when :footnode_id_ref
      if content < 1 or content > @env.footnotes.size
        raise "footnote not defined: #{content}"
      end
      %Q|<a href="#footnote-#{content}">#{content}</a>|
    when :footnode_acronym_ref
      unless index = @env.footnotes.find_index{|k, _| k == content }
        raise "footnote note defined: #{content}"
      end
      %Q|<a href="#footnote-#{index + 1}">#{content}</a>|
    else
      node
    end
  end
  @out.join
end