summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2022-06-25 12:16:59 -0600
committerGitHub <noreply@github.com>2022-06-25 12:16:59 -0600
commit5fd22a20eafcb515f0fda7ddc5ef4e6bf458a376 (patch)
treef962c7659c132476033f68669933b9ac2f2b74f1
parent92ccc32bb086415cd2decde63505b769ead30c7c (diff)
resolves #2261 include source location in warning message for truncated table cell if sourcemap is enabled (PR #2262)
-rw-r--r--CHANGELOG.adoc4
-rw-r--r--lib/asciidoctor/pdf/converter.rb8
-rw-r--r--lib/asciidoctor/pdf/ext/prawn-table/cell.rb2
-rw-r--r--lib/asciidoctor/pdf/ext/prawn-table/cell/asciidoc.rb4
-rw-r--r--lib/asciidoctor/pdf/ext/prawn-table/cell/text.rb4
-rw-r--r--spec/table_spec.rb46
6 files changed, 63 insertions, 5 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc
index a7b29bd2..8a6d9cbf 100644
--- a/CHANGELOG.adoc
+++ b/CHANGELOG.adoc
@@ -13,6 +13,10 @@ Enhancements::
* allow page margin for rotated page to be configured independently using `page-margin-rotated` theme key or `pdf-page-margin-rotated` document attribute (#1719)
* don't force page break after TOC with automatic placement in article if `title-page` attribute is set and value of `toc-break-after` theme key is `auto` (#1768)
+Improvements::
+
+* include source location in warning message for truncated table cell if sourcemap is enabled (#2261)
+
Bug Fixes::
* allow alt text for block image, video, and audio to wrap to next line on same page (#2258)
diff --git a/lib/asciidoctor/pdf/converter.rb b/lib/asciidoctor/pdf/converter.rb
index 7df81d1e..2096df4a 100644
--- a/lib/asciidoctor/pdf/converter.rb
+++ b/lib/asciidoctor/pdf/converter.rb
@@ -2023,7 +2023,8 @@ module Asciidoctor
content: cell_text,
colspan: cell.colspan || 1,
align: (cell.attr 'halign').to_sym,
- valign: (val = cell.attr 'valign') == 'middle' ? :center : val.to_sym
+ valign: (val = cell.attr 'valign') == 'middle' ? :center : val.to_sym,
+ source_location: cell.source_location
end)
end
end unless head_rows.empty?
@@ -2042,7 +2043,8 @@ module Asciidoctor
colspan: cell.colspan || 1,
rowspan: cell.rowspan || 1,
align: (cell.attr 'halign').to_sym,
- valign: (val = cell.attr 'valign') == 'middle' ? :center : val.to_sym
+ valign: (val = cell.attr 'valign') == 'middle' ? :center : val.to_sym,
+ source_location: cell.source_location
cell_line_metrics = body_cell_line_metrics
case cell.style
when :emphasis
@@ -2103,7 +2105,7 @@ module Asciidoctor
# NOTE: line metrics get applied when AsciiDoc content is converted
cell_line_metrics = nil
asciidoc_cell = ::Prawn::Table::Cell::AsciiDoc.new self, (cell_data.merge content: cell.inner_document, padding: body_cell_padding)
- cell_data = { content: asciidoc_cell }
+ cell_data = { content: asciidoc_cell, source_location: cell.source_location }
end
if cell_line_metrics
cell_padding = body_cell_padding.dup
diff --git a/lib/asciidoctor/pdf/ext/prawn-table/cell.rb b/lib/asciidoctor/pdf/ext/prawn-table/cell.rb
index dac6af83..19d4adac 100644
--- a/lib/asciidoctor/pdf/ext/prawn-table/cell.rb
+++ b/lib/asciidoctor/pdf/ext/prawn-table/cell.rb
@@ -1,6 +1,8 @@
# frozen_string_literal: true
Prawn::Table::Cell.prepend (Module.new do
+ attr_writer :source_location
+
def border_color= color
color = [color, color] if Asciidoctor::PDF::ThemeLoader::CMYKColorValue === color
super
diff --git a/lib/asciidoctor/pdf/ext/prawn-table/cell/asciidoc.rb b/lib/asciidoctor/pdf/ext/prawn-table/cell/asciidoc.rb
index 0af9cd52..07406237 100644
--- a/lib/asciidoctor/pdf/ext/prawn-table/cell/asciidoc.rb
+++ b/lib/asciidoctor/pdf/ext/prawn-table/cell/asciidoc.rb
@@ -91,7 +91,9 @@ module Prawn
# 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
- logger.error %(the table cell on page #{start_page} has been truncated; Asciidoctor PDF does not support table cell content that exceeds the height of a single page) unless extra_pages == 1 && pdf.page.empty?
+ unless extra_pages == 1 && pdf.page.empty?
+ logger.error message_with_context %(the table cell on page #{start_page} has been truncated; Asciidoctor PDF does not support table cell content that exceeds the height of a single page), source_location: @source_location
+ end
extra_pages.times { pdf.delete_current_page }
end
nil
diff --git a/lib/asciidoctor/pdf/ext/prawn-table/cell/text.rb b/lib/asciidoctor/pdf/ext/prawn-table/cell/text.rb
index cd279fd4..aa73ccac 100644
--- a/lib/asciidoctor/pdf/ext/prawn-table/cell/text.rb
+++ b/lib/asciidoctor/pdf/ext/prawn-table/cell/text.rb
@@ -16,7 +16,9 @@ class Prawn::Table::Cell::Text
height: spanned_content_height + FPTolerance,
at: [0, @pdf.cursor]).render
end
- logger.error %(the table cell on page #{@pdf.page_number} has been truncated; Asciidoctor PDF does not support table cell content that exceeds the height of a single page) unless remaining_text.empty? || @pdf.scratch?
+ unless remaining_text.empty? || @pdf.scratch?
+ logger.error message_with_context %(the table cell on page #{@pdf.page_number} has been truncated; Asciidoctor PDF does not support table cell content that exceeds the height of a single page), source_location: @source_location
+ end
end
end
diff --git a/spec/table_spec.rb b/spec/table_spec.rb
index 829203c3..8d5c69f3 100644
--- a/spec/table_spec.rb
+++ b/spec/table_spec.rb
@@ -1474,6 +1474,28 @@ describe 'Asciidoctor::PDF::Converter - Table' do
(expect after_text[:page_number]).to be 3
end).to log_message severity: :ERROR, message: 'the table cell on page 2 has been truncated; Asciidoctor PDF does not support table cell content that exceeds the height of a single page'
end
+
+ it 'should report file and line number in truncated cell error if sourcemap is enabled' do
+ (expect do
+ blank_line = %(\n\n)
+
+ pdf = to_pdf <<~EOS, sourcemap: true, attribute_overrides: { 'docfile' => 'test.adoc' }, analyze: true
+ |===
+ |first cell
+ |second cell
+
+ #{(['filler'] * 25).join blank_line}
+ |last cell
+ |===
+ EOS
+
+ (expect pdf.pages.size).to eql 3
+ (expect (pdf.find_unique_text 'first cell')[:page_number]).to eql 1
+ (expect (pdf.find_unique_text 'second cell')[:page_number]).to eql 2
+ (expect (pdf.find_text 'filler').map {|it| it[:page_number] }.uniq).to eql [2]
+ (expect (pdf.find_unique_text 'last cell')[:page_number]).to eql 3
+ end).to log_message severity: :ERROR, message: 'the table cell on page 2 has been truncated; Asciidoctor PDF does not support table cell content that exceeds the height of a single page', file: 'test.adoc', lineno: 3
+ end
end
context 'Strong table cell' do
@@ -2257,6 +2279,30 @@ describe 'Asciidoctor::PDF::Converter - Table' do
end).to log_message severity: :ERROR, message: 'the table cell on page 2 has been truncated; Asciidoctor PDF does not support table cell content that exceeds the height of a single page'
end
+ it 'should report file and line number in truncated cell error if sourcemap is enabled' do
+ (expect do
+ blank_line = %(\n\n)
+
+ pdf = to_pdf <<~EOS, sourcemap: true, attribute_overrides: { 'docfile' => 'test.adoc' }, analyze: true
+ before table
+
+ |===
+ |first cell
+ a|
+ before list
+
+ #{(['* list item'] * 50).join blank_line}
+ |last cell
+ |===
+ EOS
+
+ (expect pdf.pages).to have_size 3
+ (expect (pdf.find_unique_text 'before list')[:page_number]).to eql 2
+ (expect (pdf.find_text 'list item').map {|it| it[:page_number] }.uniq).to eql [2]
+ (expect (pdf.find_unique_text 'last cell')[:page_number]).to eql 3
+ end).to log_message severity: :ERROR, message: 'the table cell on page 2 has been truncated; Asciidoctor PDF does not support table cell content that exceeds the height of a single page', file: 'test.adoc', lineno: 5
+ end
+
it 'should not warn if cell exceeds page height in scratch document' do
(expect do
pdf = to_pdf <<~'EOS', analyze: true