Class: Slaw::ZA::Act::Table

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

Instance Method Summary collapse

Instance Method Details

#to_xml(b, idprefix) ⇒ Object



326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# File 'lib/slaw/za/act_nodes.rb', line 326

def to_xml(b, idprefix)
  # parse the table using wikicloth
  html = WikiCloth::Parser.new({data: self.text_value}).to_html

  # we need to strip any surrounding p tags and add
  # an id to the table
  html = Nokogiri::HTML(html)
  table = html.css("table").first
  table['id'] = "#{idprefix}table0"

  # wrap td and th content in p tags
  table.css("td, th").each do |cell|
    p = Nokogiri::XML::Node.new("p", html)
    p.children = cell.children
    p.parent = cell
  end

  table.xpath('//text()[1]').each{ |t|      t.content = t.content.lstrip }
  table.xpath('//text()[last()]').each{ |t| t.content = t.content.rstrip }

  b << table.to_html
end