Skip to content
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

Demonstration of selecting only commands using Pygments-only #186

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,13 @@
myst_enable_extensions = ["colon_fence"]

# CopyButton configuration
copybutton_prompt_text = r">>> |\.\.\. |\$ |In \[\d*\]: | {2,5}\.\.\.: | {5,8}: "
copybutton_prompt_is_regexp = True
# copybutton_prompt_text = r">>> |\.\.\. |\$ |In \[\d*\]: | {2,5}\.\.\.: | {5,8}: "
# copybutton_prompt_is_regexp = True
copybutton_line_continuation_character = "\\"
copybutton_here_doc_delimiter = "EOT"
copybutton_selector = "div:not(.no-copybutton) > div.highlight > pre"
copybutton_exclude = ".linenos, .gp, .go"
copybutton_copy_empty_lines = False

# Switches for testing but shouldn't be activated in the live docs
# copybutton_only_copy_prompt_lines = False
Expand Down
12 changes: 6 additions & 6 deletions docs/use.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ An example usage would be the `ipython`-directive:
```restructuredtext
``ipython`` and ``qtconsole`` style:

.. code-block:: ipython
.. code-block:: ipythonconsole

In [1]: first
...: continuation
Expand All @@ -97,7 +97,7 @@ An example usage would be the `ipython`-directive:

``jupyter`` style:

.. code-block:: ipython
.. code-block:: ipythonconsole

In [1]: first
: continuation
Expand All @@ -107,7 +107,7 @@ An example usage would be the `ipython`-directive:

`ipython` and `qtconsole` style:

```ipython
```ipythonconsole
In [1]: first
...: continuation
output
Expand All @@ -116,7 +116,7 @@ In [2]: second

`jupyter` style:

```ipython
```ipythonconsole
In [1]: first
: continuation
output
Expand Down Expand Up @@ -175,7 +175,7 @@ See below for how to control this.

Sometimes you may wish to copy a code block like this one:

```bash
```console
$ datalad download-url http://www.tldp.org/LDP/Bash-Beginners-Guide/Bash-Beginners-Guide.pdf \
--dataset . \
-m "add beginners guide on bash" \
Expand Down Expand Up @@ -205,7 +205,7 @@ rules.
in which line breaks and other whitespace (including indentation) is preserved.
For example:

```bash
```console
$ cat << EOT > notes.txt
This is an example sentence.
Put some indentation on this line.
Expand Down
8 changes: 4 additions & 4 deletions sphinx_copybutton/_static/copybutton_funcs.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ export function formatCopyText(textContent, copybuttonPromptText, isRegexp = fal
const lineGotPrompt = [];
for (const line of textContent.split('\n')) {
match = line.match(regexp)
if (match || gotLineCont || gotHereDoc) {
if (!copyEmptyLines && line.trim() === '') {
// do nothing
} else if (match || gotLineCont || gotHereDoc) {
promptFound = regexp.test(line)
lineGotPrompt.push(promptFound)
if (removePrompts && promptFound) {
Expand All @@ -55,9 +57,7 @@ export function formatCopyText(textContent, copybuttonPromptText, isRegexp = fal
gotHereDoc = !gotHereDoc
} else if (!onlyCopyPromptLines) {
outputLines.push(line)
} else if (copyEmptyLines && line.trim() === '') {
outputLines.push(line)
}
}
}

// If no lines with the prompt were found then just use original lines
Expand Down