Class: ClWiki::FormatSimpleTable

Inherits:
CustomFormatter show all
Defined in:
lib/cl_wiki/format_simple_table.rb

Class Method Summary collapse

Class Method Details

.format_content(content, page = nil) ⇒ Object



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

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



5
6
7
# File 'lib/cl_wiki/format_simple_table.rb', line 5

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