summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2022-09-01 02:07:58 -0600
committerDan Allen <dan.j.allen@gmail.com>2022-09-04 00:39:33 -0600
commit3b9ee228573c4521363d6bb8cacd13b0a5d7cc2c (patch)
treeee6c9e7c2062247049ee370e88eba57dc1f2e3ea
parent73098f2104660e93828225c9a9e554d4d26a4f50 (diff)
ensure heading-min-height-after theme key is ignored if section is empty or discrete heading is last child
-rw-r--r--CHANGELOG.adoc1
-rw-r--r--lib/asciidoctor/pdf/converter.rb2
-rw-r--r--spec/floating_title_spec.rb21
-rw-r--r--spec/section_spec.rb14
4 files changed, 35 insertions, 3 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc
index 5a14357c..5f15af67 100644
--- a/CHANGELOG.adoc
+++ b/CHANGELOG.adoc
@@ -12,6 +12,7 @@ Bug Fixes::
* don't include bottom margin when computing heading height if `heading-min-height-after` theme key is empty (#2326)
* draw border on heading (section title or discrete heading) if it is advanced to next page (#2322)
* arrange heading even if section is empty
+* ensure `heading-min-height-after` theme key is ignored if section is empty or discrete heading is last child
* don't force justify first line of abstract if it ends with a hard break
== 2.3.0 (2022-08-16) - @mojavelinux
diff --git a/lib/asciidoctor/pdf/converter.rb b/lib/asciidoctor/pdf/converter.rb
index df2a4648..c3947d72 100644
--- a/lib/asciidoctor/pdf/converter.rb
+++ b/lib/asciidoctor/pdf/converter.rb
@@ -2848,6 +2848,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..32630f9b 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
+ 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 033d86a3..fdcded3c 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
+ 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]