Class: Slaw::Grammars::Tables::TableCell

Inherits:
Treetop::Runtime::SyntaxNode
  • Object
show all
Defined in:
lib/slaw/grammars/tables_nodes.rb

Instance Method Summary collapse

Instance Method Details

#to_xml(b, idprefix) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/slaw/grammars/tables_nodes.rb', line 35

def to_xml(b, idprefix)
  tag = table_cell_start.th? ? 'th' : 'td'

  attrs = {}
  if not attribs.empty?
    for item in attribs.attribs.elements
      # key=value (strip quotes around value)
      attrs[item.name.text_value.strip] = item.value.text_value[1..-2]
    end
  end

  b.send(tag.to_sym, attrs) { |b|
    b.p { |b|
      # first line, and the rest
      lines = [content.line] + content.elements.last.elements.map(&:line)

      lines.each_with_index do |line, i|
        line.to_xml(b, i, i == lines.length-1)
      end
    }
  }
end