summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dallen@redhat.com>2013-04-18 16:00:35 -0600
committerDan Allen <dallen@redhat.com>2013-04-18 16:00:35 -0600
commitc7bb02c481f3ebe9cd3e71592b7260ea0e5c8682 (patch)
tree17c3b6df2b292a5374af19ed1b2548769385deda
parente74f0a7967c3936001a565247a9fc9b86372c74a (diff)
resolves #241 negative case for inline ifndef should only affect current line
-rw-r--r--lib/asciidoctor/reader.rb8
-rw-r--r--test/reader_test.rb16
2 files changed, 21 insertions, 3 deletions
diff --git a/lib/asciidoctor/reader.rb b/lib/asciidoctor/reader.rb
index 8913212d..7302bd02 100644
--- a/lib/asciidoctor/reader.rb
+++ b/lib/asciidoctor/reader.rb
@@ -343,7 +343,7 @@ class Reader
return preprocess_next_line.nil? ? nil : true
end
- skip = nil
+ skip = false
if !@skipping
case directive
when 'ifdef'
@@ -384,17 +384,19 @@ class Reader
skip = !lhs.send(op.to_sym, rhs)
end
- @skipping = skip
end
advance
# single line conditional inclusion
if directive != 'ifeval' && !text.nil?
- if !@skipping
+ if !@skipping && !skip
unshift_line "#{text.rstrip}\n"
return true
end
# conditional inclusion block
else
+ if !@skipping && skip
+ @skipping = true
+ end
@conditionals_stack << {:target => target, :skip => skip, :skipping => @skipping}
end
return preprocess_next_line.nil? ? nil : true
diff --git a/test/reader_test.rb b/test/reader_test.rb
index bc7832a8..0d7f1418 100644
--- a/test/reader_test.rb
+++ b/test/reader_test.rb
@@ -387,6 +387,22 @@ There was much rejoicing.
assert_equal "On our quest we go...\nThere is a holy grail!\nThere was much rejoicing.", lines.join.strip
end
+ test 'ifndef with defined attribute does not include text in brackets' do
+ input = <<-EOS
+On our quest we go...
+ifndef::hardships[There is a holy grail!]
+There was no rejoicing.
+ EOS
+
+ doc = Asciidoctor::Document.new [], :attributes => {'hardships' => ''}
+ reader = Asciidoctor::Reader.new(input.lines.entries, doc, true)
+ lines = []
+ while reader.has_more_lines?
+ lines << reader.get_line
+ end
+ assert_equal "On our quest we go...\nThere was no rejoicing.", lines.join.strip
+ end
+
test 'include with non-matching nested exclude' do
input = <<-EOS
ifdef::grail[]