Skip to content

Commit

Permalink
backport fix for #4571 pass cursor to preprocessor when processing fi…
Browse files Browse the repository at this point in the history
…rst line of AsciiDoc table cell
  • Loading branch information
mblythe86 authored and mojavelinux committed May 16, 2024
1 parent 1b1172a commit 40e5a7e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/asciidoctor/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def initialize column, cell_text, attributes = {}, opts = {}
# QUESTION is is faster to check for :: before splitting?
inner_document_lines = cell_text.split LF, -1
if (unprocessed_line1 = inner_document_lines[0]).include? '::'
preprocessed_lines = (PreprocessorReader.new @document, [unprocessed_line1]).readlines
preprocessed_lines = (PreprocessorReader.new @document, [unprocessed_line1], inner_document_cursor).readlines
unless unprocessed_line1 == preprocessed_lines[0] && preprocessed_lines.size < 2
inner_document_lines.shift
inner_document_lines.unshift(*preprocessed_lines) unless preprocessed_lines.empty?
Expand Down
30 changes: 30 additions & 0 deletions test/tables_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1711,6 +1711,36 @@
assert_match(/included content/, output)
end

test 'error about unresolved preprocessor directive on first line of an AsciiDoc table cell should have correct cursor' do
begin
tmp_include = Tempfile.new %w(include- .adoc)
tmp_include_dir, tmp_include_path = File.split tmp_include.path
tmp_include.write <<~'EOS'
|===
|A |B
|text
a|include::does-not-exist.adoc[]
|===
EOS
tmp_include.close
input = <<~EOS
first
include::#{tmp_include_path}[]
last
EOS
using_memory_logger do |logger|
output = convert_string_to_embedded input, safe: :safe, base_dir: tmp_include_dir
assert_includes output, %(Unresolved directive in #{tmp_include_path})
assert_message logger, :ERROR, %(#{tmp_include_path}: line 5: include file not found: #{File.join tmp_include_dir, 'does-not-exist.adoc'}), Hash
end
ensure
tmp_include.close!
end
end

test 'cross reference link in an AsciiDoc table cell should resolve to reference in main document' do
input = <<~'EOS'
== Some
Expand Down

0 comments on commit 40e5a7e

Please sign in to comment.