Skip to content

Commit

Permalink
resolves asciidoctor#2487 fix page number of index entries in prepres…
Browse files Browse the repository at this point in the history
…s book when page numbering starts after toc and toc is inserted using macro
  • Loading branch information
mojavelinux committed Feb 3, 2024
1 parent 360de47 commit 0b19009
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Bug Fixes::
* don't crash if page background image value is empty (interpret as "none")
* prevent special character substitution from interfering with callouts in plain verbatim block (#2390)
* remove deprecated, undocumented `svg-font-family` theme key (the correct key is `svg-fallback-font-family`)
* fix page number of index entries in prepress book when page numbering starts after toc and toc is inserted using macro (#2487)

== 2.3.11 (2024-01-23) - @mojavelinux

Expand Down
6 changes: 5 additions & 1 deletion lib/asciidoctor/pdf/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2385,7 +2385,11 @@ def convert_toc node, opts = {}
start_toc_page node, placement if (is_book = doc.doctype == 'book')
add_dest_for_block node, id: (node.id || 'toc') if is_macro
toc_extent = @toc_extent = allocate_toc doc, (doc.attr 'toclevels', 2).to_i, cursor, (title_page_on = is_book || (doc.attr? 'title-page'))
@index.start_page_number = toc_extent.to.page + 1 if title_page_on && @theme.page_numbering_start_at == 'after-toc'
if title_page_on && @theme.page_numbering_start_at == 'after-toc'
new_start_page_number = toc_extent.to.page + 1
new_start_page_number += 1 if @ppbook && (verso_page? new_start_page_number)
@index.start_page_number = new_start_page_number
end
if is_macro
@disable_running_content[:header] += toc_extent.page_range if node.option? 'noheader'
@disable_running_content[:footer] += toc_extent.page_range if node.option? 'nofooter'
Expand Down
27 changes: 27 additions & 0 deletions spec/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,33 @@
(expect terms).to eql %w(anchor AsciiDoc Asciidoctor authoring)
end

it 'should adjust start page number for prepress book when page numbering starts after-toc and toc macro is used' do
pdf = to_pdf <<~'END', pdf_theme: { page_numbering_start_at: 'after-toc' }, analyze: true
= Book Title
:doctype: book
:media: prepress
:toc: macro
toc::[]
== First Chapter
((apples))
== Second Chapter
((bananas))
[index]
== Index
END

index_title_text = (pdf.find_text 'Index')[-1]
(expect index_title_text[:page_number]).to be 9
index_lines = pdf.lines pdf.find_text page_number: 9
(expect index_lines).to eql ['Index', 'A', 'apples, 1', 'B', 'bananas, 3']
end

it 'should start with no categories' do
index = Asciidoctor::PDF::IndexCatalog.new
(expect index).to be_empty
Expand Down

0 comments on commit 0b19009

Please sign in to comment.