diff options
| -rw-r--r-- | CHANGELOG.adoc | 1 | ||||
| -rw-r--r-- | lib/asciidoctor/pdf/converter.rb | 9 | ||||
| -rw-r--r-- | spec/table_spec.rb | 23 |
3 files changed, 28 insertions, 5 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 5e389475..dfd13692 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -51,6 +51,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`) +* honor table caption end placement (`table-caption-end` theme key) when `unbreakable` (or `breakable`) option is set on table (#2434) == 2.3.8 (2023-06-25) - @mojavelinux diff --git a/lib/asciidoctor/pdf/converter.rb b/lib/asciidoctor/pdf/converter.rb index 7d094fd6..a0aed411 100644 --- a/lib/asciidoctor/pdf/converter.rb +++ b/lib/asciidoctor/pdf/converter.rb @@ -1997,6 +1997,7 @@ module Asciidoctor end def convert_table node + caption_end = (theme = @theme).table_caption_end&.to_sym || :top if !at_page_top? && ((unbreakable = node.option? 'unbreakable') || ((node.option? 'breakable') && (node.id || node.title?))) # NOTE: we use the current node as the parent so we can navigate back into the document model (table_container = Block.new node, :open) << (table_dup = node.dup) @@ -2008,7 +2009,7 @@ module Asciidoctor end table_container.style = 'table-container' table_container.id, table_dup.id = table_dup.id, nil - if table_dup.title? + if caption_end == :top && table_dup.title? table_container.title = '' table_container.instance_variable_set :@converted_title, table_dup.captioned_title table_dup.title = nil @@ -2020,7 +2021,6 @@ module Asciidoctor num_rows = node.attr 'rowcount' num_cols = node.columns.size table_header_size = false - theme = @theme prev_font_scale, @font_scale = @font_scale, 1 if node.document.nested? tbl_bg_color = resolve_theme_color :table_background_color @@ -2258,7 +2258,6 @@ module Asciidoctor alignment = theme.table_align&.to_sym || :left end - caption_end = theme.table_caption_end&.to_sym || :top caption_max_width = theme.table_caption_max_width || 'fit-content' table_settings = { @@ -2290,7 +2289,7 @@ module Asciidoctor @column_widths = column_widths unless column_widths.empty? # NOTE: call width to capture resolved table width table_width = width - @pdf.ink_table_caption node, alignment, table_width, caption_max_width if node.title? && caption_end == :top + @pdf.ink_table_caption node, alignment, table_width, caption_max_width if caption_end == :top && node.title? # NOTE: align using padding instead of bounding_box as prawn-table does # using a bounding_box across pages mangles the margin box of subsequent pages if alignment != :left && table_width != (this_bounds = @pdf.bounds).width @@ -2363,7 +2362,7 @@ module Asciidoctor bounds.subtract_left_padding left_padding bounds.subtract_right_padding right_padding if right_padding end - ink_table_caption node, alignment, table_width, caption_max_width, caption_end if node.title? && caption_end == :bottom + ink_table_caption node, alignment, table_width, caption_max_width, caption_end if caption_end == :bottom && node.title? theme_margin :block, :bottom, (next_enclosed_block node) rescue ::Prawn::Errors::CannotFit log :error, (message_with_context 'cannot fit contents of table cell into specified column width', source_location: node.source_location) diff --git a/spec/table_spec.rb b/spec/table_spec.rb index e6d30756..8acfe2fb 100644 --- a/spec/table_spec.rb +++ b/spec/table_spec.rb @@ -3291,6 +3291,29 @@ describe 'Asciidoctor::PDF::Converter - Table' do (expect cell_a1_text[:page_number]).to be 2 end + it 'should honor caption end placement if %unbreakable option is set on table' do + pdf_theme = { table_caption_end: 'bottom' } + pdf = to_pdf <<~END, pdf_theme: pdf_theme, analyze: true + image::tall.svg[pdfwidth=75mm] + + .Title + [%unbreakable] + |=== + | Column A | Column B + + #{(1.upto 5).map {|idx| %(| A#{idx} | B#{idx}) }.join %(\n\n)} + |=== + END + + title_text = pdf.find_unique_text 'Table 1. Title' + (expect title_text[:page_number]).to be 2 + column_a_text = pdf.find_text 'Column A' + (expect column_a_text).to have_size 1 + column_a_text = column_a_text[0] + (expect column_a_text[:page_number]).to be 2 + (expect title_text[:y]).to be < column_a_text[:y] + end + it 'should keep caption with table if %breakable option is set on table' do pdf = to_pdf <<~END, analyze: true image::tall.svg[pdfwidth=80mm] |
