@@ -201,4 +201,145 @@ def copy_attributes copied
201
201
expect ( copied ) . to eq ( [ ] )
202
202
}
203
203
end
204
+
205
+ it "copies images for callouts when requested (png)" do
206
+ copied = [ ]
207
+ attributes = copy_attributes copied
208
+ attributes [ 'copy-callout-images' ] = 'png'
209
+ input = <<~ASCIIDOC
210
+ == Example
211
+ ----
212
+ foo <1> <2>
213
+ ----
214
+ <1> words
215
+ <2> words
216
+ ASCIIDOC
217
+ expected_warnings = <<~WARNINGS
218
+ INFO: <stdin>: line 5: copying #{ spec_dir } /resources/copy_images/images/icons/callouts/1.png
219
+ INFO: <stdin>: line 6: copying #{ spec_dir } /resources/copy_images/images/icons/callouts/2.png
220
+ WARNINGS
221
+ convert input , attributes , eq ( expected_warnings . strip )
222
+ expect ( copied ) . to eq ( [
223
+ [ "images/icons/callouts/1.png" , "#{ spec_dir } /resources/copy_images/images/icons/callouts/1.png" ] ,
224
+ [ "images/icons/callouts/2.png" , "#{ spec_dir } /resources/copy_images/images/icons/callouts/2.png" ] ,
225
+ ] )
226
+ end
227
+
228
+ it "copies images for callouts when requested (gif)" do
229
+ copied = [ ]
230
+ attributes = copy_attributes copied
231
+ attributes [ 'copy-callout-images' ] = 'gif'
232
+ input = <<~ASCIIDOC
233
+ == Example
234
+ ----
235
+ foo <1>
236
+ ----
237
+ <1> words
238
+ ASCIIDOC
239
+ expected_warnings = <<~WARNINGS
240
+ INFO: <stdin>: line 5: copying #{ spec_dir } /resources/copy_images/images/icons/callouts/1.gif
241
+ WARNINGS
242
+ convert input , attributes , eq ( expected_warnings . strip )
243
+ expect ( copied ) . to eq ( [
244
+ [ "images/icons/callouts/1.gif" , "#{ spec_dir } /resources/copy_images/images/icons/callouts/1.gif" ] ,
245
+ ] )
246
+ end
247
+
248
+ it "has a nice error message when a callout image is missing" do
249
+ copied = [ ]
250
+ attributes = copy_attributes copied
251
+ attributes [ 'copy-callout-images' ] = 'gif'
252
+ input = <<~ASCIIDOC
253
+ == Example
254
+ ----
255
+ foo <1> <2>
256
+ ----
257
+ <1> words
258
+ <2> words
259
+ ASCIIDOC
260
+ convert input , attributes , match ( /
261
+ WARN:\ <stdin>:\ line\ 6:\ can't\ read\ image\ at\ any\ of\ \[
262
+ "#{ spec_dir } \/ images\/ icons\/ callouts\/ 2.gif",\s
263
+ "#{ spec_dir } \/ resources\/ images\/ icons\/ callouts\/ 2.gif",\s
264
+ .+
265
+ "#{ spec_dir } \/ resources\/ copy_images\/ images\/ icons\/ callouts\/ 2.gif"
266
+ .+
267
+ \] /x ) . and ( match ( /INFO: <stdin>: line 5: copying #{ spec_dir } \/ resources\/ copy_images\/ images\/ icons\/ callouts\/ 1.gif/ ) )
268
+ expect ( copied ) . to eq ( [
269
+ [ "images/icons/callouts/1.gif" , "#{ spec_dir } /resources/copy_images/images/icons/callouts/1.gif" ] ,
270
+ ] )
271
+ end
272
+
273
+ it "only copies callout images one time" do
274
+ copied = [ ]
275
+ attributes = copy_attributes copied
276
+ attributes [ 'copy-callout-images' ] = 'png'
277
+ input = <<~ASCIIDOC
278
+ == Example
279
+ ----
280
+ foo <1>
281
+ ----
282
+ <1> words
283
+
284
+ ----
285
+ foo <1>
286
+ ----
287
+ <1> words
288
+ ASCIIDOC
289
+ expected_warnings = <<~WARNINGS
290
+ INFO: <stdin>: line 5: copying #{ spec_dir } /resources/copy_images/images/icons/callouts/1.png
291
+ WARNINGS
292
+ convert input , attributes , eq ( expected_warnings . strip )
293
+ expect ( copied ) . to eq ( [
294
+ [ "images/icons/callouts/1.png" , "#{ spec_dir } /resources/copy_images/images/icons/callouts/1.png" ] ,
295
+ ] )
296
+ end
297
+
298
+ it "supports callout lists with multiple callouts per item" do
299
+ # This is a *super* weird case but we have it in Elasticsearch.
300
+ # The only way I can make callout lists be for two things is by making
301
+ # blocks with callouts but only having a single callout list below both.
302
+ copied = [ ]
303
+ attributes = copy_attributes copied
304
+ attributes [ 'copy-callout-images' ] = 'png'
305
+ input = <<~ASCIIDOC
306
+ == Example
307
+ ----
308
+ foo <1>
309
+ ----
310
+
311
+ ----
312
+ foo <1>
313
+ ----
314
+ <1> words
315
+ ASCIIDOC
316
+ expected_warnings = <<~WARNINGS
317
+ INFO: <stdin>: line 9: copying #{ spec_dir } /resources/copy_images/images/icons/callouts/1.png
318
+ INFO: <stdin>: line 9: copying #{ spec_dir } /resources/copy_images/images/icons/callouts/2.png
319
+ WARNINGS
320
+ convert input , attributes , eq ( expected_warnings . strip )
321
+ expect ( copied ) . to eq ( [
322
+ [ "images/icons/callouts/1.png" , "#{ spec_dir } /resources/copy_images/images/icons/callouts/1.png" ] ,
323
+ [ "images/icons/callouts/2.png" , "#{ spec_dir } /resources/copy_images/images/icons/callouts/2.png" ] ,
324
+ ] )
325
+ end
326
+
327
+ it "doesn't copy callout images if the extension isn't set" do
328
+ copied = [ ]
329
+ attributes = copy_attributes copied
330
+ input = <<~ASCIIDOC
331
+ == Example
332
+ ----
333
+ foo <1>
334
+ ----
335
+ <1> words
336
+
337
+ ----
338
+ foo <1>
339
+ ----
340
+ <1> words
341
+ ASCIIDOC
342
+ convert input , attributes
343
+ expect ( copied ) . to eq ( [ ] )
344
+ end
204
345
end
0 commit comments