Skip to content

Commit

Permalink
resolves #2410 catalog all footnotes found inside AsciiDoc table cells
Browse files Browse the repository at this point in the history
  • Loading branch information
mojavelinux committed Mar 25, 2023
1 parent 6e225be commit 2acf2bb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Improvements::

Bug Fixes::

* catalog all footnotes found inside AsciiDoc table cells and render them in the footnotes list (#2410)
* 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
5 changes: 3 additions & 2 deletions lib/asciidoctor/pdf/ext/prawn-table/cell/asciidoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@ def dry_run
apply_font_properties do
extent = @pdf.dry_run keep_together: true, single_page: true do
push_scratch parent_doc
doc.catalog[:footnotes] = parent_doc.catalog[:footnotes]
doc.catalog[:footnotes] = parent_doc.catalog[:footnotes].dup unless doc == parent_doc
# NOTE: we should be able to use cell.max_width, but returns 0 in some conditions (like when colspan > 1)
indent cell.padding_left, bounds.width - cell.width + cell.padding_right do
move_down padding_y if padding_y > 0
conceal_page_top { traverse cell.content }
end
pop_scratch parent_doc
doc.catalog[:footnotes] = parent_doc.catalog[:footnotes]
end
end
# NOTE: prawn-table doesn't support cells that exceed the height of a single page
Expand Down Expand Up @@ -90,6 +89,8 @@ def draw_content
# end
# end
start_page = pdf.page_number
parent_doc = (doc = content.document).nested? ? doc.parent_document : doc
doc.catalog[:footnotes] = parent_doc.catalog[:footnotes]
# TODO: apply horizontal alignment; currently it is necessary to specify alignment on content blocks
apply_font_properties { pdf.traverse content }
if (extra_pages = pdf.page_number - start_page) > 0
Expand Down
24 changes: 23 additions & 1 deletion spec/table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2028,7 +2028,7 @@
(expect (markers_x[0] - left_edge).round 2).to eql reference_x
end

it 'should capture footnotes in AsciiDoc table cell and render them with other footnotes' do
it 'should capture footnote in AsciiDoc table cell and render them with other footnotes' do
pdf = to_pdf <<~'END', analyze: true
before{empty}footnote:[Footnote before table]
Expand All @@ -2050,6 +2050,28 @@
(expect pdf.lines).to eql expected_lines
end

it 'should capture footnotes in multiple AsciiDoc table cells and render them with other footnotes' do
pdf = to_pdf <<~'END', analyze: true
[cols=1a]
|===
|first{empty}footnote:[First footnote inside table]
|second{empty}footnote:[Second footnote inside table]
|===
third{empty}footnote:[Footnote outside of table]
END

expected_lines = [
'first[1]',
'second[2]',
'third[3]',
'1. First footnote inside table',
'2. Second footnote inside table',
'3. Footnote outside of table',
]
(expect pdf.lines).to eql expected_lines
end

it 'should not fail to fit content in table cell and create blank page when margin bottom is 0' do
pdf_theme = {
base_font_family: 'M+ 1mn',
Expand Down

0 comments on commit 2acf2bb

Please sign in to comment.