insert a comment if no TOC headers found
This commit is contained in:
@@ -69,7 +69,6 @@ module Gollum
|
|||||||
end
|
end
|
||||||
|
|
||||||
def process_headers(doc)
|
def process_headers(doc)
|
||||||
toc = nil
|
|
||||||
doc.css('h1,h2,h3,h4,h5,h6').each do |h|
|
doc.css('h1,h2,h3,h4,h5,h6').each do |h|
|
||||||
id = CGI::escape(h.content.gsub(' ','-'))
|
id = CGI::escape(h.content.gsub(' ','-'))
|
||||||
level = h.name.gsub(/[hH]/,'').to_i
|
level = h.name.gsub(/[hH]/,'').to_i
|
||||||
@@ -86,7 +85,7 @@ module Gollum
|
|||||||
tail ||= toc
|
tail ||= toc
|
||||||
tail_level ||= 1
|
tail_level ||= 1
|
||||||
|
|
||||||
while tail_level < level do
|
while tail_level < level
|
||||||
node = Nokogiri::XML::Node.new('ul', doc)
|
node = Nokogiri::XML::Node.new('ul', doc)
|
||||||
tail = tail.add_child(node)
|
tail = tail.add_child(node)
|
||||||
tail_level += 1
|
tail_level += 1
|
||||||
@@ -99,6 +98,7 @@ module Gollum
|
|||||||
node.add_child("<a href='##{id}'>#{h.content}</a>")
|
node.add_child("<a href='##{id}'>#{h.content}</a>")
|
||||||
tail.add_child(node)
|
tail.add_child(node)
|
||||||
end
|
end
|
||||||
|
toc ||= Nokogiri::XML::DocumentFragment.parse('<!--No TOC headers found-->')
|
||||||
[doc, toc]
|
[doc, toc]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user