summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.adoc4
-rw-r--r--lib/asciidoctor/reader.rb4
-rw-r--r--test/reader_test.rb26
3 files changed, 34 insertions, 0 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc
index f664e1bd..e66d22b2 100644
--- a/CHANGELOG.adoc
+++ b/CHANGELOG.adoc
@@ -66,6 +66,10 @@ Improvements::
* Return `nil` if name passed to `Asciidoctor::SafeMode.value_for_name` is not recognized (#3526)
* Modify default stylesheet to honor text-* roles on quote blocks
+Bug Fixes::
+
+ * Don't leave behind empty line inside skipped preprocessor conditional (#4580)
+
== 2.0.22 (2024-03-08) - @mojavelinux
Improvements::
diff --git a/lib/asciidoctor/reader.rb b/lib/asciidoctor/reader.rb
index 2aa565ce..23000dda 100644
--- a/lib/asciidoctor/reader.rb
+++ b/lib/asciidoctor/reader.rb
@@ -807,6 +807,10 @@ class PreprocessorReader < Reader
return line unless @process_lines
if line.empty?
+ if @skipping
+ shift
+ return nil
+ end
@look_ahead += 1
return line
end
diff --git a/test/reader_test.rb b/test/reader_test.rb
index be8ccd49..28e44268 100644
--- a/test/reader_test.rb
+++ b/test/reader_test.rb
@@ -2232,6 +2232,19 @@ class ReaderTest < Minitest::Test
assert_equal 4, reader.lineno
end
+ test 'peek_line returns nil if contents of skipped conditional is empty line' do
+ input = <<~'EOS'
+ ifdef::foobar[]
+
+ endif::foobar[]
+ EOS
+
+ doc = Asciidoctor::Document.new input
+ reader = doc.reader
+ assert_equal 1, reader.lineno
+ assert_nil reader.peek_line
+ end
+
test 'ifdef with defined attribute includes content' do
input = <<~'EOS'
ifdef::holygrail[]
@@ -2541,6 +2554,19 @@ class ReaderTest < Minitest::Test
assert_equal 'Our quest is complete!', result
end
+ test 'ifdef around empty line does not introduce extra line' do
+ input = <<~'EOS'
+ before
+ ifdef::no-such-attribute[]
+
+ endif::[]
+ after
+ EOS
+
+ result = (Asciidoctor::Document.new input).reader.read
+ assert_equal %(before\nafter), result
+ end
+
test 'should log warning if endif is unmatched' do
input = <<~'EOS'
Our quest is complete!