diff --git a/resources/asciidoctor/lib/elastic_include_tagged/extension.rb b/resources/asciidoctor/lib/elastic_include_tagged/extension.rb index 8caee5f4b1948..1d76e4fa6a694 100644 --- a/resources/asciidoctor/lib/elastic_include_tagged/extension.rb +++ b/resources/asciidoctor/lib/elastic_include_tagged/extension.rb @@ -49,14 +49,15 @@ def process(_doc, reader, target, attrs) break end if found_tag - line = line[indentation..-1] + line = line.sub(indentation, '') included_lines << line if line next end - next unless start_match =~ line + start_match_data = start_match.match(line) + next unless start_match_data found_tag = true - indentation = $1.size + indentation = /^#{start_match_data[1]}/ start_of_include = lineno end end diff --git a/resources/asciidoctor/spec/elastic_include_tagged_spec.rb b/resources/asciidoctor/spec/elastic_include_tagged_spec.rb index 57deccfb4876e..c737f48f2b113 100644 --- a/resources/asciidoctor/spec/elastic_include_tagged_spec.rb +++ b/resources/asciidoctor/spec/elastic_include_tagged_spec.rb @@ -84,6 +84,25 @@ expect(actual).to eq(expected.strip) end + it "preserves empty lines" do + actual = convert <<~ASCIIDOC + == Example + ["source","java",subs="attributes,callouts,macros"] + ---- + include::elastic-include-tagged:resources/elastic_include_tagged/Example.java[empty_line] + ---- + ASCIIDOC + expected = <<~DOCBOOK + + Example + System.err.println("empty list after this one"); + + System.err.println("and before this one"); + + DOCBOOK + expect(actual).to eq(expected.strip) + end + it "warns if the file doesn't exist" do input = <<~ASCIIDOC include::elastic-include-tagged:resources/elastic_include_tagged/DoesNotExist.java[doesn't-matter] @@ -113,7 +132,9 @@ expected = <<~DOCBOOK - System.err.println("this tag doesn’t have any end"); + System.err.println("this tag doesn’t have any end"); + } + } DOCBOOK actual = convert input, {}, match(%r{resources/elastic_include_tagged/Example.java: line \d+: elastic-include-tagged missing end tag \[missing-end\]}) diff --git a/resources/asciidoctor/spec/resources/elastic_include_tagged/Example.java b/resources/asciidoctor/spec/resources/elastic_include_tagged/Example.java index 09b0667e530b8..4508ed1475b31 100644 --- a/resources/asciidoctor/spec/resources/elastic_include_tagged/Example.java +++ b/resources/asciidoctor/spec/resources/elastic_include_tagged/Example.java @@ -19,6 +19,12 @@ public void doThings() { System.err.println("no leading space"); //end::no_leading_space + // tag::empty_line + System.err.println("empty list after this one"); + + System.err.println("and before this one"); + // end::empty_line + // end::missing-start // tag::missing-end