Class: FormatSimpleTable

Inherits:
ClWiki::CustomFormatter show all
Defined in:
lib/cl_wiki/format/format.simpletable.rb

Class Method Summary collapse

Class Method Details

.format_content(content, page = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/cl_wiki/format/format.simpletable.rb', line 8

def self.format_content(content, page = nil)
  table_attr = content.scan(/<simpletable(.*?)>/m).to_s.strip
  table_attr = 'border="1"' if table_attr.empty?
  content.gsub!(/<simpletable.*?>/m, '')
  content.gsub!(%r{</simpletable>}m, '')
  content.strip!
  lines = content.split("\n")
  lines.collect! do |ln|
    ln.gsub!(/\t/, '  ')
    '<tr><td>' + ln.gsub(/  +/, '</td><td>') + '</td></tr>'
  end
  lines.collect! { |ln| ln.gsub(%r{<td>\s*?</td>}, '<td>&nbsp;</td>') }

  # if you do a .join("\n"), then the \n will be converted to <br>
  # ... so don't do that
  "<table #{table_attr}>\n#{lines.join('')}</table>"
end

.match_reObject



4
5
6
# File 'lib/cl_wiki/format/format.simpletable.rb', line 4

def self.match_re
  %r{<simpletable.*?>.*?</simpletable>}m
end