diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2022-05-25 16:25:54 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-25 16:25:54 -0600 |
| commit | ec22605f8a7879f83c219d480654f68e84d3613c (patch) | |
| tree | deb5362d8751ddce21939f69a68d844f470d1839 | |
| parent | ad6adec0b7942ea405eb58f0ebb7bdb15219f0a7 (diff) | |
resolves #2208 fix calculation of TOC extent when entries have children but no ID (PR #2209)
| -rw-r--r-- | CHANGELOG.adoc | 6 | ||||
| -rw-r--r-- | lib/asciidoctor/pdf/converter.rb | 2 | ||||
| -rw-r--r-- | spec/toc_spec.rb | 24 |
3 files changed, 31 insertions, 1 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 1f31bb43..3273912f 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 13287a69..9688c560 100644 --- a/lib/asciidoctor/pdf/converter.rb +++ b/lib/asciidoctor/pdf/converter.rb @@ -3756,9 +3756,9 @@ module Asciidoctor 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 5cb1901c..c7a7d809 100644 --- a/spec/toc_spec.rb +++ b/spec/toc_spec.rb @@ -221,6 +221,30 @@ describe 'Asciidoctor::PDF::Converter - TOC' do (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 |
