@@ -60,7 +60,7 @@ Installation
6060
6161.. note ::
6262
63- ``sphinx-copybutton `` only works on Python >= 3.4
63+ ``sphinx-copybutton `` only works on Python >= 3.6
6464
6565You can install ``sphinx-copybutton `` with ``pip ``:
6666
@@ -268,6 +268,80 @@ strip the prompts), use the following configuration in ``conf.py``:
268268
269269 copybutton_remove_prompts = False
270270
271+ Configure whether *empty * lines are copied
272+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
273+
274+ By default, sphinx-copybutton will also copy / pass through empty lines,
275+ determined by ``line.trim() === '' ``.
276+
277+ To disable copying empty lines, use the following configuration in ``conf.py ``:
278+
279+ .. code-block :: python
280+
281+ copybutton_copy_empty_lines = False
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+
271345Use a different copy button image
272346~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
273347
0 commit comments