def toc(sections, toc_numbered=false)
ret = "<table id=\"toc\" class=\"toc\" summary=\"Contents\"><tr><td><div id=\"toctitle\"><h2>#{I18n.t('table of contents')}</h2></div><ul>"
previous_depth = 1
indices = []
section_list(sections).each do |section|
next if section.title.nil?
if section.depth > previous_depth
indices[section.depth] = 0 if indices[section.depth].nil?
indices[section.depth] += 1
c = section.depth - previous_depth
c.times { ret += "<ul>" }
ret += "<li><a href=\"##{section.id}\">#{indices[0..section.depth].compact.join('.') + " " if toc_numbered}#{section.title}</a>"
elsif section.depth == previous_depth
indices[section.depth] = 0 if indices[section.depth].nil?
indices[section.depth] += 1
ret += "</li><li><a href=\"##{section.id}\">#{indices[0..section.depth].compact.join('.') + " " if toc_numbered}#{section.title}</a>"
else
indices[section.depth] = 0 if indices[section.depth].nil?
indices[section.depth] += 1
indices = indices[0..section.depth]
ret += "</li>" unless previous_depth == 1
c = previous_depth - section.depth
c.times { ret += "</ul>" }
ret += "<li><a href=\"##{section.id}\">#{indices[0..section.depth].compact.join('.') + " " if toc_numbered}#{section.title}</a>"
end
previous_depth = section.depth
end
ret += "</li>"
(previous_depth-1).times { ret += "</ul>" }
"#{ret}</ul></td></tr></table>"
end