diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2022-08-03 02:46:04 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-03 02:46:04 -0600 |
| commit | 38cc77d619e9718993304137eb2d3bcba194db33 (patch) | |
| tree | 52bbb6d11dde69780128cb928878d03890270c96 | |
| parent | 0f4d133731c89cd2e6187f38dd6dc9667d77328e (diff) | |
resolves #2291 allow theme to control vertical alignment of footnotes block (PR #2292)
| -rw-r--r-- | CHANGELOG.adoc | 4 | ||||
| -rw-r--r-- | docs/modules/theme/pages/footnotes.adoc | 6 | ||||
| -rw-r--r-- | lib/asciidoctor/pdf/converter.rb | 5 | ||||
| -rw-r--r-- | spec/footnote_spec.rb | 34 |
4 files changed, 44 insertions, 5 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 37c818b0..ae390df2 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -7,6 +7,10 @@ For a detailed view of what has changed, refer to the {url-repo}/commits/main[co == Unreleased +Enhancements:: + +* Allow footnotes to be placed directly below last block of content if `footnotes_margin_top` theme key is 0 (#2291) + Bug Fixes:: * apply text transform and formatting when checking height of heading for orphan prevention diff --git a/docs/modules/theme/pages/footnotes.adoc b/docs/modules/theme/pages/footnotes.adoc index 75781338..35b4cbfc 100644 --- a/docs/modules/theme/pages/footnotes.adoc +++ b/docs/modules/theme/pages/footnotes.adoc @@ -41,11 +41,11 @@ footnotes: item-spacing: 5 |margin-top -|xref:measurement-units.adoc[Measurement] + -(default: `0`) +|xref:measurement-units.adoc[Measurement] {vbar} `auto` + +(default: `auto`) |[source] footnotes: - margin-top: 2 + margin-top: 0 |text-transform |xref:text.adoc#transform[Text transform] + diff --git a/lib/asciidoctor/pdf/converter.rb b/lib/asciidoctor/pdf/converter.rb index 3df0e3e8..b75a34c3 100644 --- a/lib/asciidoctor/pdf/converter.rb +++ b/lib/asciidoctor/pdf/converter.rb @@ -578,6 +578,7 @@ module Asciidoctor theme.code_linenum_font_color ||= '999999' theme.callout_list_margin_top_after_code ||= 0 theme.role_unresolved_font_color ||= 'FF0000' + theme.footnotes_margin_top ||= 'auto' theme.footnotes_item_spacing ||= 0 theme.index_columns ||= 2 theme.index_column_gap ||= theme.base_font_size @@ -3164,9 +3165,9 @@ module Asciidoctor def ink_footnotes node return if (fns = (doc = node.document).footnotes - @rendered_footnotes).empty? theme_margin :block, :bottom if node.context == :document || node == node.document.last_child - theme_margin :footnotes, :top + theme_margin :footnotes, :top unless (valign_bottom = @theme.footnotes_margin_top == 'auto') with_dry_run do |extent| - if (single_page_height = extent&.single_page_height) && (delta = cursor - single_page_height - 0.0001) > 0 + if valign_bottom && (single_page_height = extent&.single_page_height) && (delta = cursor - single_page_height - 0.0001) > 0 move_down delta end theme_font :footnotes do diff --git a/spec/footnote_spec.rb b/spec/footnote_spec.rb index af1d3d95..43294455 100644 --- a/spec/footnote_spec.rb +++ b/spec/footnote_spec.rb @@ -165,6 +165,40 @@ describe 'Asciidoctor::PDF::Converter - Footnote' do (expect first_footnote[:y]).to be < (footnotes_height + 50) end + it 'should put footnotes directly below last block if footnotes_margin_top is 0' do + pdf_theme = { footnotes_margin_top: 0 } + input = <<~'EOS' + About this thing.footnote:[More about this thing.] + + **** + sidebar + **** + EOS + + pdf = to_pdf input, pdf_theme: pdf_theme, analyze: true + horizontal_lines = (to_pdf input, pdf_theme: pdf_theme, analyze: :line).lines + .select {|it| it[:from][:y] == it[:to][:y] }.sort_by {|it| -it[:from][:y] } + (expect pdf.pages).to have_size 1 + footnote_text = pdf.find_unique_text %r/More about / + footnote_text_top = footnote_text[:y] + footnote_text[:font_size] + content_bottom_y = horizontal_lines[-1][:from][:y] + (expect content_bottom_y - footnote_text_top).to be > 12.0 + (expect content_bottom_y - footnote_text_top).to be < 14.0 + end + + it 'should push footnotes to bottom of page if footnotes_margin_top is auto' do + pdf_theme = { page_margin: 36, footnotes_margin_top: 'auto', footnotes_item_spacing: 0 } + input = <<~'EOS' + About this thing.footnote:[More about this thing.] + + more content + EOS + + pdf = to_pdf input, pdf_theme: pdf_theme, analyze: true + footnote_text = pdf.find_unique_text %r/More about / + (expect footnote_text[:y]).to (be_within 3).of 36 + end + it 'should put footnotes beyond margin below last block of content' do pdf_theme = { sidebar_background_color: 'transparent' } input = <<~'EOS' |
