Skip to content

Commit

Permalink
resolves #4571 pass cursor to preprocessor when processing first line…
Browse files Browse the repository at this point in the history
… of AsciiDoc table cell (PR #4572)
  • Loading branch information
mblythe86 committed May 16, 2024
1 parent f1da34a commit 1b2f7c7
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 @@ -303,7 +303,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 @@ -1708,6 +1708,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 1b2f7c7

Please sign in to comment.