Skip to content

Commit aaa55b9

Browse files
authored
Asciidoctor: Handle skipped lines (#643)
Our compat-preprocessor wasn't properly handling "skipped" lines sometimes, mostly because we didn't have any tests for them. This fixes both problems. It is a prerequisite to switching the "Getting Started" book to asciidoctor.
1 parent 0c9e593 commit aaa55b9

File tree

2 files changed

+68
-3
lines changed

2 files changed

+68
-3
lines changed

resources/asciidoctor/lib/elastic_compat_preprocessor/extension.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,13 @@ def reader.process_line(line)
124124

125125
@in_attribute_only_block = true
126126
line.clear
127-
elsif SOURCE_WITH_SUBS_RX =~ line
128-
line = super
129-
line.sub! "subs=\"#{$1}\"", "subs=\"#{$1},callouts\"" unless $1.include? 'callouts'
130127
else
131128
line = super
129+
return nil if line.nil?
130+
131+
if SOURCE_WITH_SUBS_RX =~ line
132+
line.sub! "subs=\"#{$1}\"", "subs=\"#{$1},callouts\"" unless $1.include? 'callouts'
133+
end
132134
if CODE_BLOCK_RX =~ line
133135
if @code_block_start
134136
if line != @code_block_start

resources/asciidoctor/spec/elastic_compat_preprocessor_spec.rb

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,23 @@
5555
DOCBOOK
5656
expect(actual).to eq(expected.strip)
5757
end
58+
59+
it "doesn't mind skipped #{name} block macros" do
60+
actual = convert <<~ASCIIDOC
61+
== Example
62+
63+
ifeval::["true" == "false"]
64+
#{name}[some_version]
65+
#endif::[]
66+
ASCIIDOC
67+
expected = <<~DOCBOOK
68+
<chapter id="_example">
69+
<title>Example</title>
70+
71+
</chapter>
72+
DOCBOOK
73+
expect(actual).to eq(expected.strip)
74+
end
5875
end
5976

6077
it "invokes include-tagged::" do
@@ -210,6 +227,33 @@
210227
expect(actual).to eq(expected.strip)
211228
end
212229

230+
it "doesn't mind skipped source blocks that are missing callouts" do
231+
actual = convert <<~ASCIIDOC
232+
== Example
233+
234+
ifeval::["true" == "false"]
235+
["source","sh",subs="attributes"]
236+
--------------------------------------------
237+
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-{version}.zip
238+
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-{version}.zip.sha512
239+
shasum -a 512 -c elasticsearch-{version}.zip.sha512 <1>
240+
unzip elasticsearch-{version}.zip
241+
cd elasticsearch-{version}/ <2>
242+
--------------------------------------------
243+
<1> Compares the SHA of the downloaded `.zip` archive and the published checksum, which should output
244+
`elasticsearch-{version}.zip: OK`.
245+
<2> This directory is known as `$ES_HOME`.
246+
endif::[]
247+
ASCIIDOC
248+
expected = <<~DOCBOOK
249+
<chapter id="_example">
250+
<title>Example</title>
251+
252+
</chapter>
253+
DOCBOOK
254+
expect(actual).to eq(expected.strip)
255+
end
256+
213257
it "fixes mismatched fencing on code blocks" do
214258
input = <<~ASCIIDOC
215259
== Example
@@ -227,6 +271,25 @@
227271
expect(actual).to eq(expected.strip)
228272
end
229273

274+
it "doesn't doesn't mind skipped mismatched code blocks" do
275+
actual = convert <<~ASCIIDOC
276+
== Example
277+
278+
ifeval::["true" == "false"]
279+
----
280+
foo
281+
--------
282+
endif::[]
283+
ASCIIDOC
284+
expected = <<~DOCBOOK
285+
<chapter id="_example">
286+
<title>Example</title>
287+
288+
</chapter>
289+
DOCBOOK
290+
expect(actual).to eq(expected.strip)
291+
end
292+
230293
it "doesn't break table-style outputs" do
231294
actual = convert <<~ASCIIDOC
232295
== Example

0 commit comments

Comments
 (0)