Skip to content

Commit

Permalink
resolves asciidoctor#2208 fix calculation of TOC extent when entries …
Browse files Browse the repository at this point in the history
…have children but no ID
  • Loading branch information
mojavelinux committed May 25, 2022
1 parent ad6adec commit 68f490b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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::
Expand Down
2 changes: 1 addition & 1 deletion lib/asciidoctor/pdf/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions spec/toc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 68f490b

Please sign in to comment.