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



374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# File 'lib/slaw/za/act_nodes.rb', line 374

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