Skip to content

Asciidoctor: Fix Elastic's include-tagged with empty lines #693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also write this like next unless start_match_data = start_match.match(line)
But some people might disagree : )

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dan didn't like that too much so I'm avoiding it. Asciidoctor uses this sort of thing in the extreme and I think it is fairly hard to read. So for the most part I've swung the other way....

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's purely a style thing, so no problem


found_tag = true
indentation = $1.size
indentation = /^#{start_match_data[1]}/
start_of_include = lineno
end
end
Expand Down
23 changes: 22 additions & 1 deletion resources/asciidoctor/spec/elastic_include_tagged_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
<chapter id="_example">
<title>Example</title>
<programlisting language="java" linenumbering="unnumbered">System.err.println("empty list after this one");

System.err.println("and before this one");</programlisting>
</chapter>
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]
Expand Down Expand Up @@ -113,7 +132,9 @@
expected = <<~DOCBOOK
<preface>
<title></title>
<simpara>System.err.println("this tag doesn&#8217;t have any end");</simpara>
<simpara>System.err.println("this tag doesn&#8217;t have any end");
}
}</simpara>
</preface>
DOCBOOK
actual = convert input, {}, match(%r{resources/elastic_include_tagged/Example.java: line \d+: elastic-include-tagged missing end tag \[missing-end\]})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down