@@ -280,6 +280,68 @@ To disable copying empty lines, use the following configuration in ``conf.py``:
280
280
281
281
copybutton_copy_empty_lines = False
282
282
283
+ Honor line continuation characters when copying multline-snippets
284
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
285
+
286
+ Sometimes you may wish to copy a code block like this one:
287
+
288
+ .. code-block :: bash
289
+
290
+ $ datalad download-url http://www.tldp.org/LDP/Bash-Beginners-Guide/Bash-Beginners-Guide.pdf \
291
+ --dataset . \
292
+ -m " add beginners guide on bash" \
293
+ -O books/bash_guide.pdf
294
+
295
+ Assuming that you specified ``$ `` as your prompt, sphinx-copybutton will only copy
296
+ the first line by default.
297
+
298
+ To copy all lines above, you can use the following configuration:
299
+
300
+ .. code-block :: python
301
+
302
+ copybutton_line_continuation_character = " \\ "
303
+
304
+ Note that if we want to define ``\ `` as the line continuation character, we have to "escape"
305
+ it with another ``\ ``, as with any Python string that should carry a literal ``\ ``.
306
+
307
+ Next, this configuration will make the code look for lines to copy based on the rules above,
308
+ but if one of the lines to be copied contains a line continuation character,
309
+ then the next line will be automatically copied, regardless of whether it matches the other
310
+ rules.
311
+
312
+ Honor HERE-document syntax when copying multline-snippets
313
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
314
+
315
+ `HERE-documents <https://en.wikipedia.org/wiki/Here_document >`_ are a form of multiline string literals
316
+ in which line breaks and other whitespace (including indentation) is preserved.
317
+ For example:
318
+
319
+ .. code-block :: bash
320
+
321
+ $ cat << EOT > notes.txt
322
+ This is an example sentence.
323
+ Put some indentation on this line.
324
+
325
+ EOT
326
+
327
+ Executing this codeblock in the terminal will create a file ` ` notes.txt` ` with the exact
328
+ text from line two of the codeblock until (but not including) the final line containing ` ` EOT` ` .
329
+
330
+ However, assuming that you specified ` ` $` ` as your prompt, sphinx-copybutton will only copy
331
+ the first line by default.
332
+
333
+ sphinx-copybutton can be configured to copy the whole "HERE-document" by using the following
334
+ configuration:
335
+
336
+ .. code-block:: python
337
+
338
+ copybutton_here_doc_delimiter = "EOT"
339
+
340
+ This will continue to look for lines to copy based on the rules above,
341
+ but if one of the lines to be copied contains the defined delimiter (here: ` ` EOT` ` ),
342
+ then all following lines will be copied literally until the next delimiter is
343
+ encountered in a line.
344
+
283
345
Use a different copy button image
284
346
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
285
347
0 commit comments