diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 1f31bb433..3273912f9 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -5,6 +5,12 @@ This document provides a high-level view of the changes to the {project-name} by release. For a detailed view of what has changed, refer to the {url-repo}/commits/main[commit history] on GitHub. +== Unreleased + +Bug Fixes:: + +* fix calculation of TOC extent when TOC entry has children but no ID (#2208) + == 2.0.3 (2022-05-25) - @mojavelinux Improvements:: diff --git a/lib/asciidoctor/pdf/converter.rb b/lib/asciidoctor/pdf/converter.rb index 13287a69d..9688c5602 100644 --- a/lib/asciidoctor/pdf/converter.rb +++ b/lib/asciidoctor/pdf/converter.rb @@ -3756,9 +3756,9 @@ def ink_toc_level entries, num_levels, dot_leader, num_front_matter_pages hanging_indent = @theme.toc_hanging_indent entries.each do |entry| next if (num_levels_for_entry = (entry.attr 'toclevels', num_levels).to_i) < (entry_level = entry.level + 1).pred || - !(entry_anchor = (entry.attr 'pdf-anchor') || entry.id) || ((entry.option? 'notitle') && entry == entry.document.last_child && entry.empty?) theme_font :toc, level: entry_level do + next unless (entry_anchor = (entry.attr 'pdf-anchor') || entry.id) entry_title = entry.context == :section ? entry.numbered_title : (entry.title? ? entry.title : (entry.xreftext 'basic')) next if entry_title.empty? entry_title = transform_text entry_title, @text_transform if @text_transform diff --git a/spec/toc_spec.rb b/spec/toc_spec.rb index 5cb1901c5..c7a7d8092 100644 --- a/spec/toc_spec.rb +++ b/spec/toc_spec.rb @@ -221,6 +221,30 @@ (expect pdf.pages[3][:strings]).to include 'Chapter 1' end + it 'should render descendants of section without ID when computing extent of TOC' do + input = <<~EOS + = Document Title + :doctype: book + :pdf-page-size: A5 + :toc: + + the preface + + :!sectids: + == Chapter 1 + :sectids: + + #{5.times.map {|idx| %(=== Section #{idx + 1}) }.join ?\n} + + #{21.times.map {|idx| %(== Chapter #{idx + 2}) }.join ?\n} + EOS + + pdf = to_pdf input, analyze: true + preface_text = pdf.find_unique_text 'the preface' + last_toc_entry_text = (pdf.find_text 'Chapter 22')[0] + (expect preface_text[:page_number]).to be > last_toc_entry_text[:page_number] + end + it 'should insert toc after preamble if toc attribute is preamble' do pdf = to_pdf <<~'EOS', analyze: true = Document Title