diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2022-09-01 02:07:58 -0600 |
|---|---|---|
| committer | Dan Allen <dan.j.allen@gmail.com> | 2022-09-01 02:07:58 -0600 |
| commit | b31cd4186aaf1c5a0a5540bb4e1db34b0279e117 (patch) | |
| tree | 5acc3a907bcae375727e0eaeb0ce9ba796d9f83d | |
| parent | 7054785ec100ea28d853deb7d3caf79b18bc4153 (diff) | |
ensure heading-min-height-after theme key is ignored if section is empty or discrete heading is last child
| -rw-r--r-- | CHANGELOG.adoc | 1 | ||||
| -rw-r--r-- | lib/asciidoctor/pdf/converter.rb | 2 | ||||
| -rw-r--r-- | spec/floating_title_spec.rb | 21 | ||||
| -rw-r--r-- | spec/section_spec.rb | 14 |
4 files changed, 35 insertions, 3 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index cd9b1f70..897cdeed 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -22,6 +22,7 @@ Enhancements:: Improvements:: * don't include bottom margin when computing heading height if `heading-min-height-after` theme key is empty (#2326) +* ensure `heading-min-height-after` theme key is ignored if section is empty or discrete heading is last child Bug Fixes:: diff --git a/lib/asciidoctor/pdf/converter.rb b/lib/asciidoctor/pdf/converter.rb index b8ee8c01..675fb3db 100644 --- a/lib/asciidoctor/pdf/converter.rb +++ b/lib/asciidoctor/pdf/converter.rb @@ -2864,6 +2864,8 @@ module Asciidoctor theme_font :heading, level: (hlevel = opts[:level]) do if (space_below = ::Numeric === min_height_after ? min_height_after : 0) > 0 && (node.context == :section ? node.blocks? : !node.last_child?) space_below += @theme[%(heading_h#{hlevel}_margin_bottom)] || @theme.heading_margin_bottom + else + space_below = 0 end h_padding_t, h_padding_r, h_padding_b, h_padding_l = expand_padding_value @theme[%(heading_h#{hlevel}_padding)] h_fits = indent h_padding_l, h_padding_r do diff --git a/spec/floating_title_spec.rb b/spec/floating_title_spec.rb index 8b169f47..f37ff5bd 100644 --- a/spec/floating_title_spec.rb +++ b/spec/floating_title_spec.rb @@ -55,7 +55,7 @@ describe 'Asciidoctor::PDF::Converter - Floating Title' do (expect discrete_heading_text[:x]).to be > main_text[:x] end - it 'should force discrete heading to next page if space below is less than min_height_after value' do + it 'should force discrete heading to next page if space below is less than heading-min-height-after value' do pdf = with_content_spacer 10, 690 do |spacer_path| to_pdf <<~EOS image::#{spacer_path}[] @@ -95,7 +95,7 @@ describe 'Asciidoctor::PDF::Converter - Floating Title' do (expect (get_dest pdf, 'buddy')[:page_number]).to eql 2 end - it 'should force discrete heading to next page when heading_min_content_after is auto if no content is inked below it' do + it 'should force discrete heading to next page when heading-min-height-after is auto if no content is inked below it' do pdf = with_content_spacer 10, 675 do |spacer_path| to_pdf <<~EOS, pdf_theme: { heading_min_height_after: 'auto' } image::#{spacer_path}[] @@ -116,6 +116,21 @@ describe 'Asciidoctor::PDF::Converter - Floating Title' do (expect (get_dest pdf, 'buddy')[:page_number]).to eql 2 end + it 'should ignore heading-min-height-after if heading is last child' do + pdf = with_content_spacer 10, 650 do |spacer_path| + to_pdf <<~EOS, pdf_theme: { heading_min_height_after: 100, heading_font_color: 'AA0000' }, analyze: true, debug: true + image::#{spacer_path}[] + + [discrete] + == Heading Fits + EOS + end + + (expect pdf.pages).to have_size 1 + heading_text = pdf.find_unique_text font_color: 'AA0000' + (expect heading_text[:page_number]).to eql 1 + end + it 'should allow arrange_heading to be reimplemented to always keep heading with content that follows it' do source_file = doc_file 'modules/extend/examples/pdf-converter-avoid-break-after-heading.rb' source_lines = (File.readlines source_file).select {|l| l == ?\n || (l.start_with? ' ') } @@ -151,7 +166,7 @@ describe 'Asciidoctor::PDF::Converter - Floating Title' do (expect content_text[:page_number]).to be 2 end - it 'should not force discrete heading to next page if min_height_after value is not set' do + it 'should not force discrete heading to next page if heading-min-height-after value is not set' do pdf = with_content_spacer 10, 690 do |spacer_path| to_pdf <<~EOS, pdf_theme: { heading_min_height_after: nil } image::#{spacer_path}[] diff --git a/spec/section_spec.rb b/spec/section_spec.rb index 2c7d7cbb..0dc443d8 100644 --- a/spec/section_spec.rb +++ b/spec/section_spec.rb @@ -1116,6 +1116,20 @@ describe 'Asciidoctor::PDF::Converter - Section' do (expect heading_text[:page_number]).to eql 1 end + it 'should ignore heading-min-height-after if section is empty' do + pdf = with_content_spacer 10, 650 do |spacer_path| + to_pdf <<~EOS, pdf_theme: { heading_min_height_after: 100, heading_font_color: 'AA0000' }, analyze: true, debug: true + image::#{spacer_path}[] + + == Heading Fits + EOS + end + + (expect pdf.pages).to have_size 1 + heading_text = pdf.find_unique_text font_color: 'AA0000' + (expect heading_text[:page_number]).to eql 1 + end + it 'should force section title with text transform to next page to keep with first line of section content' do pdf = to_pdf <<~EOS, pdf_theme: { heading_text_transform: 'uppercase' }, analyze: true image::tall.svg[pdfwidth=80mm] |
