diff options
| -rw-r--r-- | lib/asciidoctor/backends/_stylesheets.rb | 5 | ||||
| -rw-r--r-- | lib/asciidoctor/backends/html5.rb | 21 | ||||
| -rw-r--r-- | test/sections_test.rb | 44 |
3 files changed, 55 insertions, 15 deletions
diff --git a/lib/asciidoctor/backends/_stylesheets.rb b/lib/asciidoctor/backends/_stylesheets.rb index b4c14fab..cd6f9582 100644 --- a/lib/asciidoctor/backends/_stylesheets.rb +++ b/lib/asciidoctor/backends/_stylesheets.rb @@ -157,13 +157,16 @@ p a > tt:hover { color: #561309; } #header br + span:before { content: "\2013 \0020"; } #toc { border-bottom: 3px double #ebebeb; padding-bottom: 1.25em; } #toc > ol { margin-left: 0.25em; } +#toc ol.sectlevel0 > li > a { font-style: italic; } +#toc ol.sectlevel0 ol.sectlevel1 { margin-left: 0; margin-top: 0.5em; margin-bottom: 0.5em; } #toc ol { list-style-type: none; } #toctitle { color: #7a2518; } @media only screen and (min-width: 80em) { body.toc2 { padding-left: 20em; } #toc.toc2 { position: fixed; width: 20em; left: 0; top: 0; border-right: 1px solid #ebebeb; border-bottom: 0; z-index: 1000; padding: 1em; height: 100%; overflow: auto; } #toc.toc2 #toctitle { margin-top: 0; } #toc.toc2 > ol { font-size: .95em; } - #toc.toc2 ol li ol { margin-left: 0; padding-left: 1em; } } + #toc.toc2 ol ol { margin-left: 0; padding-left: 1em; } + #toc.toc2 ol.sectlevel0 ol.sectlevel1 { padding-left: 0; margin-top: 0.5em; margin-bottom: 0.5em; } } #footer { max-width: 100%; background-color: #222222; padding: 1.25em; } #footer-text { color: #dddddd; line-height: 1.44; } .sect1 { border-bottom: 3px double #ebebeb; padding-bottom: 1.25em; } diff --git a/lib/asciidoctor/backends/html5.rb b/lib/asciidoctor/backends/html5.rb index f0e95ead..3a1b426f 100644 --- a/lib/asciidoctor/backends/html5.rb +++ b/lib/asciidoctor/backends/html5.rb @@ -29,12 +29,13 @@ class DocumentTemplate < BaseTemplate toc_level = nil sections = node.sections unless sections.empty? - if !node.is_a?(Document) && node.document.doctype == 'book' - nested = node.level > 0 - else - nested = true + # FIXME the level for special sections should be set correctly in the model + # sec_level will only be 0 if we have a book doctype with parts + sec_level = sections.first.level + if sec_level == 0 && sections.first.special + sec_level = 1 end - toc_level = nested ? %(<ol type="none">\n) : '' + toc_level = %(<ol type="none" class="sectlevel#{sec_level}">\n) numbered = node.document.attr? 'numbered' sections.each do |section| # need to check playback attributes for change in numbered setting @@ -44,17 +45,13 @@ class DocumentTemplate < BaseTemplate numbered = numbered_override.negate ? false : true end end - section_num = numbered && !section.special && section.level < 4 ? %(#{section.sectnum} ) : nil + section_num = numbered && !section.special && section.level > 0 && section.level < 4 ? %(#{section.sectnum} ) : nil toc_level = %(#{toc_level}<li><a href=\"##{section.id}\">#{section_num}#{section.caption}#{section.title}</a></li>\n) if section.level < to_depth && (child_toc_level = outline(section, to_depth)) - if section.document.doctype != 'book' || section.level > 0 - toc_level = %(#{toc_level}<li>\n#{child_toc_level}\n</li>\n) - else - toc_level = %(#{toc_level}#{child_toc_level}\n) - end + toc_level = %(#{toc_level}<li>\n#{child_toc_level}\n</li>\n) end end - toc_level = %(#{toc_level}</ol>) if nested + toc_level = %(#{toc_level}</ol>) end toc_level end diff --git a/test/sections_test.rb b/test/sections_test.rb index 4a5f9ae9..d780cb3e 100644 --- a/test/sections_test.rb +++ b/test/sections_test.rb @@ -1013,11 +1013,14 @@ That's all she wrote! assert_xpath '//*[@id="header"]//*[@id="toc"][@class="toc"]', output, 1 assert_xpath '//*[@id="header"]//*[@id="toc"]/*[@id="toctitle"][text()="Table of Contents"]', output, 1 assert_xpath '//*[@id="header"]//*[@id="toc"]/ol', output, 1 - assert_xpath '//*[@id="header"]//*[@id="toc"]/ol[@type="none"]', output, 1 + assert_xpath '//*[@id="header"]//*[@id="toc"]/ol[@type="none"][@class="sectlevel1"]', output, 1 assert_xpath '//*[@id="header"]//*[@id="toc"]//ol', output, 2 assert_xpath '//*[@id="header"]//*[@id="toc"]//ol[@type="none"]', output, 2 assert_xpath '//*[@id="header"]//*[@id="toc"]/ol/li', output, 4 assert_xpath '//*[@id="header"]//*[@id="toc"]/ol/li[1]/a[@href="#_section_one"][text()="Section One"]', output, 1 + assert_xpath '//*[@id="header"]//*[@id="toc"]/ol/li/ol', output, 1 + assert_xpath '//*[@id="header"]//*[@id="toc"]/ol/li/ol[@type="none"]', output, 1 + assert_xpath '//*[@id="header"]//*[@id="toc"]/ol/li/ol[@class="sectlevel2"]', output, 1 assert_xpath '//*[@id="header"]//*[@id="toc"]/ol/li/ol/li', output, 1 assert_xpath '//*[@id="header"]//*[@id="toc"]/ol/li/ol/li/a[@href="#_interlude"][text()="Interlude"]', output, 1 assert_xpath '((//*[@id="header"]//*[@id="toc"]/ol)[1]/li)[4]/a[@href="#_section_three"][text()="Section Three"]', output, 1 @@ -1095,6 +1098,43 @@ That's all she wrote! assert_xpath '((//*[@id="header"]//*[@id="toc"]/ol)[1]/li)[4]/a[@href="#_section_three"][text()="Section Three"]', output, 1 end + test 'should not number parts in table of contents for book doctype when numbered attribute is set' do + input = <<-EOS += Book +:doctype: book +:toc: +:numbered: + += Part 1 + +== First Section of Part 1 + +blah + +== Second Section of Part 1 + +blah + += Part 2 + +== First Section of Part 2 + +blah + EOS + + output = render_string input + assert_xpath '//*[@id="toc"]', output, 1 + assert_xpath '//*[@id="toc"]/ol', output, 1 + assert_xpath '//*[@id="toc"]/ol[@type="none"][@class="sectlevel0"]', output, 1 + assert_xpath '//*[@id="toc"]/ol[@type="none"][@class="sectlevel0"]/li', output, 4 + assert_xpath '(//*[@id="toc"]/ol[@type="none"][@class="sectlevel0"]/li)[1]/a[text()="Part 1"]', output, 1 + assert_xpath '(//*[@id="toc"]/ol[@type="none"][@class="sectlevel0"]/li)[3]/a[text()="Part 2"]', output, 1 + assert_xpath '(//*[@id="toc"]/ol[@type="none"][@class="sectlevel0"]/li)[2]/ol', output, 1 + assert_xpath '(//*[@id="toc"]/ol[@type="none"][@class="sectlevel0"]/li)[2]/ol[@type="none"][@class="sectlevel1"]', output, 1 + assert_xpath '(//*[@id="toc"]/ol[@type="none"][@class="sectlevel0"]/li)[2]/ol/li', output, 2 + assert_xpath '((//*[@id="toc"]/ol[@type="none"][@class="sectlevel0"]/li)[2]/ol/li)[1]/a[text()="1. First Section of Part 1"]', output, 1 + end + test 'should render table of contents in header if toc2 attribute is set' do input = <<-EOS = Article @@ -1387,7 +1427,7 @@ That's all she wrote! end context 'book doctype' do - test 'wip document title with level 0 headings' do + test 'document title with level 0 headings' do input = <<-EOS = Book Doc Writer |
