diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2022-06-07 23:53:52 -0600 |
|---|---|---|
| committer | Dan Allen <dan.j.allen@gmail.com> | 2022-06-08 00:34:34 -0600 |
| commit | b63114c23940c2e62f240562761a8777f8c25353 (patch) | |
| tree | c60a43005ddf08ee903a2478e252b77f602b6f75 | |
| parent | 5fd47cc4d343f340e1f1c411dee5117f9f6eb463 (diff) | |
don't push section that follows index section in article to new page if last page of index does not extend to bottom of page
| -rw-r--r-- | CHANGELOG.adoc | 1 | ||||
| -rw-r--r-- | lib/asciidoctor/pdf/converter.rb | 4 | ||||
| -rw-r--r-- | spec/index_spec.rb | 63 |
3 files changed, 68 insertions, 0 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index a73be1d1..a18242e7 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -15,6 +15,7 @@ Bug Fixes:: * `at_page_top?` should consider top of column box to be top of page * prevent SVG image taller than column from being advanced to next column * fix computation of default height for formatted box inside column box +* don't push section that follows index section in article to new page if last page of index does not extend to bottom of page == 2.0.7 (2022-06-03) - @mojavelinux diff --git a/lib/asciidoctor/pdf/converter.rb b/lib/asciidoctor/pdf/converter.rb index e9a0c57f..c969484c 100644 --- a/lib/asciidoctor/pdf/converter.rb +++ b/lib/asciidoctor/pdf/converter.rb @@ -702,6 +702,7 @@ module Asciidoctor def convert_index_section node space_needed_for_category = @theme.description_list_term_spacing + (2 * (height_of_typeset_text 'A')) pagenum_sequence_style = node.document.attr 'index-pagenum-sequence-style' + end_cursor = nil column_box [0, cursor], columns: @theme.index_columns, width: bounds.width, reflow_margins: true, spacer: @theme.index_column_gap do @index.categories.each do |category| bounds.move_past_bottom if space_needed_for_category > cursor @@ -713,7 +714,10 @@ module Asciidoctor category.terms.each {|term| convert_index_list_item term, pagenum_sequence_style } @theme.prose_margin_bottom > cursor ? bounds.move_past_bottom : (move_down @theme.prose_margin_bottom) end + end_cursor = cursor if (bounds.instance_variable_get :@current_column) == 0 end + # Q: could we move this logic into column_box? + move_cursor_to end_cursor if end_cursor nil end diff --git a/spec/index_spec.rb b/spec/index_spec.rb index 0fe4bd6c..5069bea9 100644 --- a/spec/index_spec.rb +++ b/spec/index_spec.rb @@ -870,4 +870,67 @@ describe 'Asciidoctor::PDF::Converter - Index' do chapter_a_toc_text = pdf.find_unique_text 'Chapter A', page_number: 2 (expect chapter_a_toc_text[:x]).to eql 98.24 end + + it 'should not push following section to new page if index section does not extend to bottom of page' do + pdf = to_pdf <<~'EOS', analyze: true + = Document Title + + == Chapter About Cats + + We know that ((cats)) control the internet. + But they sort of run nature too. + (((cats,big cats,lion))) + After all, the ((king of the jungle)) is the lion, which is a big cat. + + == Chapter About Dogs + + Cats may rule, well, everything. + But ((dogs)) are a human's best friend. + + [index] + == Index + + == Section After Index + EOS + + (expect pdf.pages).to have_size 1 + category_k_text = pdf.find_unique_text 'K' + (expect category_k_text[:page_number]).to eql 1 + section_after_index_text = pdf.find_unique_text 'Section After Index' + (expect section_after_index_text[:page_number]).to eql 1 + (expect section_after_index_text[:y]).to be < category_k_text[:y] + end + + it 'should not push following section to new page if index section does not extend to bottom of second page' do + pdf = to_pdf <<~EOS, analyze: true, debug: true + = Document Title + + #{('a'..'z').map {|it| %(((#{it}-term))) }.join} + + == Chapter About Cats + + We know that ((cats)) control the internet. + But they sort of run nature too. + (((cats,big cats,lion))) + After all, the ((king of the jungle)) is the lion, which is a big cat. + + == Chapter About Dogs + + Cats may rule, well, everything. + But ((dogs)) are a human's best friend. + + [index] + == Index + + == Section After Index + EOS + + (expect pdf.pages).to have_size 2 + category_z_text = pdf.find_unique_text 'Z' + (expect category_z_text[:page_number]).to eql 2 + (expect category_z_text[:x]).to eql 48.24 + section_after_index_text = pdf.find_unique_text 'Section After Index' + (expect section_after_index_text[:page_number]).to eql 2 + (expect section_after_index_text[:y]).to be < category_z_text[:y] + end end |
