insert a comment if no TOC headers found

This commit is contained in:
kristi
2012-05-13 18:48:02 -07:00
parent 1d3905bb71
commit ae30b23d34
+2 -2
View File
@@ -69,7 +69,6 @@ module Gollum
end
def process_headers(doc)
toc = nil
doc.css('h1,h2,h3,h4,h5,h6').each do |h|
id = CGI::escape(h.content.gsub(' ','-'))
level = h.name.gsub(/[hH]/,'').to_i
@@ -86,7 +85,7 @@ module Gollum
tail ||= toc
tail_level ||= 1
while tail_level < level do
while tail_level < level
node = Nokogiri::XML::Node.new('ul', doc)
tail = tail.add_child(node)
tail_level += 1
@@ -99,6 +98,7 @@ module Gollum
node.add_child("<a href='##{id}'>#{h.content}</a>")
tail.add_child(node)
end
toc ||= Nokogiri::XML::DocumentFragment.parse('<!--No TOC headers found-->')
[doc, toc]
end