diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2023-03-26 02:43:00 -0600 |
|---|---|---|
| committer | Dan Allen <dan.j.allen@gmail.com> | 2023-03-27 03:11:17 -0600 |
| commit | e3bca28cc7fe871c96479376b4689f61d26e97eb (patch) | |
| tree | 52244a04ca6d449da5905e36923129e864c6e7a4 | |
| parent | 8e18286a628b8195e44322add6fae048142184b6 (diff) | |
resolves #2379 restore bottom margin on table with breakable or unbreakable option
| -rw-r--r-- | CHANGELOG.adoc | 1 | ||||
| -rw-r--r-- | lib/asciidoctor/pdf/converter.rb | 8 | ||||
| -rw-r--r-- | spec/table_spec.rb | 42 |
3 files changed, 49 insertions, 2 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 2b7aeed6..7686e9b5 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -38,6 +38,7 @@ Improvements:: Bug Fixes:: +* restore bottom margin on table with `breakable` or `unbreakable` option (#2379) * correctly map all icons from FontAwesome 4 (#2373) * resolve remote image in document title or section title with autogenerated ID * keep caret between items in menu macro with previous item if items wrap diff --git a/lib/asciidoctor/pdf/converter.rb b/lib/asciidoctor/pdf/converter.rb index e1b329ff..07199a40 100644 --- a/lib/asciidoctor/pdf/converter.rb +++ b/lib/asciidoctor/pdf/converter.rb @@ -1989,13 +1989,15 @@ module Asciidoctor def convert_table node if !at_page_top? && ((unbreakable = node.option? 'unbreakable') || ((node.option? 'breakable') && (node.id || node.title?))) - (table_container = Block.new (table_dup = node.dup), :open) << table_dup + # 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) if unbreakable table_dup.remove_attr 'unbreakable-option' table_container.set_attr 'unbreakable-option' else table_dup.remove_attr 'breakable-option' end + table_container.style = 'table-container' table_container.id, table_dup.id = table_dup.id, nil if table_dup.title? table_container.title = '' @@ -4055,7 +4057,9 @@ module Asciidoctor end siblings = siblings.flatten if parent_context == :dlist if block != siblings[-1] - (self_idx = siblings.index block) && siblings[self_idx + 1] + context == :open && block.style == 'table-container' ? + (next_enclosed_block parent) : + (self_idx = siblings.index block) && siblings[self_idx + 1] elsif parent_context == :list_item || (parent_context == :open && parent.style != 'abstract') || parent_context == :section next_enclosed_block parent elsif list_item && (grandparent = parent.parent).context == :list_item diff --git a/spec/table_spec.rb b/spec/table_spec.rb index 18eff273..77a308d1 100644 --- a/spec/table_spec.rb +++ b/spec/table_spec.rb @@ -3272,5 +3272,47 @@ describe 'Asciidoctor::PDF::Converter - Table' do table_dest = get_dest pdf, 't1' (expect table_dest[:page_number]).to be 2 end + + it 'should not collapse margin below table with %unbreakable option' do + pdf = to_pdf <<~END, analyze: true + before + + [%unbreakable] + |=== + | will not be broken + |=== + + after + END + + before_text = pdf.find_unique_text 'before' + table_text = pdf.find_unique_text 'will not be broken' + after_text = pdf.find_unique_text 'after' + margin_above = (before_text[:y] - table_text[:y]).round 2 + margin_below = (table_text[:y] - after_text[:y]).round 2 + (expect margin_below).to eql margin_above + end + + it 'should not collapse margin below table with %breakable option' do + pdf = to_pdf <<~END, pdf_theme: { caption_font_size: 10.5, table_cell_padding: 0 }, analyze: true + before + + .title + [%breakable] + |=== + | will not be separated from title + |=== + + after + END + + before_text = pdf.find_unique_text 'before' + title_text = pdf.find_unique_text 'Table 1. title' + table_text = pdf.find_unique_text 'will not be separated from title' + after_text = pdf.find_unique_text 'after' + margin_above = (before_text[:y] - title_text[:y]).round 2 + margin_below = (table_text[:y] - after_text[:y]).round 2 + (expect margin_below).to eql margin_above + end end end |
