Skip to content

Commit

Permalink
resolves #4580 don't leave behind empty line inside skipped condition…
Browse files Browse the repository at this point in the history
…al (PR #4582)
  • Loading branch information
mojavelinux committed May 4, 2024
1 parent 935a0a3 commit ffab036
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.adoc
Expand Up @@ -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::
Expand Down
4 changes: 4 additions & 0 deletions lib/asciidoctor/reader.rb
Expand Up @@ -807,6 +807,10 @@ def process_line line
return line unless @process_lines

if line.empty?
if @skipping
shift
return nil
end
@look_ahead += 1
return line
end
Expand Down
26 changes: 26 additions & 0 deletions test/reader_test.rb
Expand Up @@ -2232,6 +2232,19 @@ def process reader, target, attributes
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[]
Expand Down Expand Up @@ -2541,6 +2554,19 @@ def process reader, target, attributes
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!
Expand Down

0 comments on commit ffab036

Please sign in to comment.