Permalink
Browse files

Include all heading levels. You can always hide it using CSS.

  • Loading branch information...
1 parent 6249c60 commit d8e0f801d19829587c2848f988f6d831b2e54377 @fnando committed Nov 14, 2012
Showing with 4 additions and 2 deletions.
  1. +1 −1 lib/kitabu/stream.rb
  2. +1 −1 lib/kitabu/toc/html.rb
  3. +2 −0 spec/kitabu/toc/html_spec.rb
View
2 lib/kitabu/stream.rb
@@ -21,7 +21,7 @@ def traverse(node)
end
def emit(node)
- listener.send(:tag, node) if node.name =~ /h[2-6]/
+ listener.send(:tag, node) if node.name =~ /h[1-6]/
end
end
end
View
2 lib/kitabu/toc/html.rb
@@ -16,7 +16,7 @@ class HTML
def self.normalize(content)
counter = {}
html = Nokogiri::HTML.parse(content)
- html.search("h2, h3, h4, h5, h6").each do |tag|
+ html.search("h1, h2, h3, h4, h5, h6").each do |tag|
title = tag.inner_text
permalink = title.to_permalink
View
2 spec/kitabu/toc/html_spec.rb
@@ -26,6 +26,7 @@
end
it "generates toc" do
+ html.should have_tag("div.level1.item-1", "Item 1")
html.should have_tag("div.level2.item-1-2", "Item 1.2")
html.should have_tag("div.level3.item-1-1-3", "Item 1.1.3")
html.should have_tag("div.level4.item-1-1-1-4", "Item 1.1.1.4")
@@ -39,6 +40,7 @@
end
it "adds id attribute to content" do
+ content.should have_tag("h1#item-1", "Item 1")
content.should have_tag("h2#item-1-2", "Item 1.2")
content.should have_tag("h3#item-1-1-3", "Item 1.1.3")
content.should have_tag("h4#item-1-1-1-4", "Item 1.1.1.4")

0 comments on commit d8e0f80

Please sign in to comment.