Class: HamdownCore::ElementParser

Inherits:
Object
  • Object
show all
Defined in:
lib/hamdown_core/element_parser.rb

Constant Summary collapse

ELEMENT_REGEXP =
/\A%([-:\w]+)([-:\w.#]*)(.+)?\z/o

Instance Method Summary collapse

Constructor Details

#initialize(line_parser) ⇒ ElementParser

Returns a new instance of ElementParser.



11
12
13
# File 'lib/hamdown_core/element_parser.rb', line 11

def initialize(line_parser)
  @line_parser = line_parser
end

Instance Method Details

#parse(text) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/hamdown_core/element_parser.rb', line 17

def parse(text)
  m = text.match(ELEMENT_REGEXP)
  unless m
    syntax_error!('Invalid element declaration')
  end

  element = Ast::Element.new
  element.filename = @line_parser.filename
  element.lineno = @line_parser.lineno
  element.tag_name = m[1]
  element.static_class, element.static_id = parse_class_and_id(m[2])
  rest = m[3] || ''

  element.old_attributes, element.new_attributes, element.object_ref, rest = parse_attributes(rest)
  element.nuke_inner_whitespace, element.nuke_outer_whitespace, rest = parse_nuke_whitespace(rest)
  element.self_closing, rest = parse_self_closing(rest)
  element.oneline_child = ScriptParser.new(@line_parser).parse(rest)

  element
end