Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolves #2520 duplicate attributes on table when wrapping table in breakable or unbreakable container #2522

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Improvements::

Bug Fixes::

* duplicate attributes on table when wrapping table in breakable or unbreakable container (#2520)
* 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
Expand Down
2 changes: 2 additions & 0 deletions lib/asciidoctor/pdf/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2005,6 +2005,8 @@ def convert_table node
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)
# NOTE: we need to duplicate the attributes so that the unbreakable/breakable option is preserved on subsequent conversions
table_dup.instance_variable_set :@attributes, node.attributes.dup
if unbreakable
table_dup.remove_attr 'unbreakable-option'
table_container.set_attr 'unbreakable-option'
Expand Down
74 changes: 74 additions & 0 deletions spec/table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3001,6 +3001,80 @@ def add_header(*)
(expect caption_prefix_text[:x] - 5).to be > cell2_text[:x]
(expect caption_wrap_text[:x]).to be > caption_prefix_text[:x]
end

it 'should not keep caption with table without breakable option and heading-min-height-after is auto' do
pdf_theme = { heading_min_height_after: 'auto' }
filler = (['filler'] * 35).join %( +\n)
pdf = to_pdf <<~END, pdf_theme: pdf_theme, analyze: true
= Document Title
:!table-caption:

== Section Title

#{filler}

=== Subsection Title

.Table title
|===
|Col A |Col B |Col C

|A1
|B1
|C1

|A2
|B2
|C2
|===
END

subsection_title = pdf.find_unique_text 'Subsection Title'
(expect subsection_title).not_to be_nil
(expect subsection_title[:page_number]).to be 1
table_caption = pdf.find_unique_text 'Table title'
(expect table_caption).not_to be_nil
(expect table_caption[:page_number]).to be 1
col_a_text = pdf.find_unique_text 'Col A'
(expect col_a_text).not_to be_nil
(expect col_a_text[:page_number]).to be 2
end

it 'should keep caption with table with breakable option and heading-min-height-after is auto' do
pdf_theme = { heading_min_height_after: 'auto' }
filler = (['filler'] * 35).join %( +\n)
pdf = to_pdf <<~END, pdf_theme: pdf_theme, analyze: true
= Document Title
:!table-caption:

== Section Title

#{filler}

=== Subsection Title

.Table title
[%breakable]
|===
|A |B |C

|A1
|B1
|C1

|A2
|B2
|C2
|===
END

subsection_title = pdf.find_unique_text 'Subsection Title'
(expect subsection_title).not_to be_nil
(expect subsection_title[:page_number]).to be 2
table_caption = pdf.find_unique_text 'Table title'
(expect table_caption).not_to be_nil
(expect table_caption[:page_number]).to be 2
end
end

context 'Table alignment' do
Expand Down
Loading