diff --git a/resources/asciidoctor/lib/elastic_compat_preprocessor/extension.rb b/resources/asciidoctor/lib/elastic_compat_preprocessor/extension.rb index 213c448a8fcb9..41a30fc5149b4 100644 --- a/resources/asciidoctor/lib/elastic_compat_preprocessor/extension.rb +++ b/resources/asciidoctor/lib/elastic_compat_preprocessor/extension.rb @@ -124,11 +124,13 @@ def reader.process_line(line) @in_attribute_only_block = true line.clear - elsif SOURCE_WITH_SUBS_RX =~ line - line = super - line.sub! "subs=\"#{$1}\"", "subs=\"#{$1},callouts\"" unless $1.include? 'callouts' else line = super + return nil if line.nil? + + if SOURCE_WITH_SUBS_RX =~ line + line.sub! "subs=\"#{$1}\"", "subs=\"#{$1},callouts\"" unless $1.include? 'callouts' + end if CODE_BLOCK_RX =~ line if @code_block_start if line != @code_block_start diff --git a/resources/asciidoctor/spec/elastic_compat_preprocessor_spec.rb b/resources/asciidoctor/spec/elastic_compat_preprocessor_spec.rb index f2944cf1cdce5..ac6ff47f11184 100644 --- a/resources/asciidoctor/spec/elastic_compat_preprocessor_spec.rb +++ b/resources/asciidoctor/spec/elastic_compat_preprocessor_spec.rb @@ -55,6 +55,23 @@ DOCBOOK expect(actual).to eq(expected.strip) end + + it "doesn't mind skipped #{name} block macros" do + actual = convert <<~ASCIIDOC + == Example + + ifeval::["true" == "false"] + #{name}[some_version] + #endif::[] + ASCIIDOC + expected = <<~DOCBOOK + + Example + + + DOCBOOK + expect(actual).to eq(expected.strip) + end end it "invokes include-tagged::" do @@ -210,6 +227,33 @@ expect(actual).to eq(expected.strip) end + it "doesn't mind skipped source blocks that are missing callouts" do + actual = convert <<~ASCIIDOC + == Example + + ifeval::["true" == "false"] + ["source","sh",subs="attributes"] + -------------------------------------------- + wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-{version}.zip + wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-{version}.zip.sha512 + shasum -a 512 -c elasticsearch-{version}.zip.sha512 <1> + unzip elasticsearch-{version}.zip + cd elasticsearch-{version}/ <2> + -------------------------------------------- + <1> Compares the SHA of the downloaded `.zip` archive and the published checksum, which should output + `elasticsearch-{version}.zip: OK`. + <2> This directory is known as `$ES_HOME`. + endif::[] + ASCIIDOC + expected = <<~DOCBOOK + + Example + + + DOCBOOK + expect(actual).to eq(expected.strip) + end + it "fixes mismatched fencing on code blocks" do input = <<~ASCIIDOC == Example @@ -227,6 +271,25 @@ expect(actual).to eq(expected.strip) end + it "doesn't doesn't mind skipped mismatched code blocks" do + actual = convert <<~ASCIIDOC + == Example + + ifeval::["true" == "false"] + ---- + foo + -------- + endif::[] + ASCIIDOC + expected = <<~DOCBOOK + + Example + + + DOCBOOK + expect(actual).to eq(expected.strip) + end + it "doesn't break table-style outputs" do actual = convert <<~ASCIIDOC == Example