Skip to content

Commit

Permalink
👌 IMPROVE: Add default python repl continuation regex (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
s-weigand authored Jul 25, 2020
1 parent 0cf5c68 commit f97ed8b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
# html_sidebars = {}

# CopyButton configuration
copybutton_prompt_text = r">>> |\$ |\[\d*\]: |In \[\d*\]: | {2,5}\.\.\.: | {5,8}: "
copybutton_prompt_text = r">>> |\.\.\. |\$ |In \[\d*\]: | {2,5}\.\.\.: | {5,8}: "
copybutton_prompt_is_regexp = True
# Switches for testing but shouldn't be activated in the live docs
# copybutton_only_copy_prompt_lines = False
Expand Down
32 changes: 29 additions & 3 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,38 @@ If your prompts are more complex than a single string, then you can use a regexp

If you enclose your regexp in a raw string (``r""``),
you can easily test that your RegExp matches all the wanted prompts,
i.e. at `RegEx101 <https://regex101.com>`_.
i.e. at `RegEx101`_.

For example this documentation uses the following configuration:

.. code-block:: python
copybutton_prompt_text = r">>> |\$ |\[\d*\]: |In \[\d*\]: | {2,5}\.\.\.: | {5,8}: "
copybutton_prompt_text = r">>> |\.\.\. |In \[\d*\]: | {2,5}\.\.\.: | {5,8}: "
copybutton_prompt_is_regexp = True
Which also matches the prompts when using prompts with continuations:
Which matches the following prompts and their continuations if they exist:

.. list-table::
:widths: 30 37 33
:header-rows: 1

* - Prompt Name
- RegEx Pattern
- Matched String Examples
* - Python Repl + continuation
- ``r'>>> |\.\.\. '``
- ``'>>> '``, ``'... '``
* - Bash
- ``r'\$ '``
- ``'$ '``
* - ``ipython`` and ``qtconsole`` + continuation
- ``r'In \[\d*\]: | {2,5}\.\.\.: '``
- ``'In []: '``, ``'In [999]: '``, ``' ...: '``, ``' ...: '``
* - ``jupyter-console`` + continuation
- ``r'In \[\d*\]: | {5,8}: '``
- ``'In []: '``, ``'In [999]: '``, ``' ...: '``, ``' ...: '``

An example usage would be the ``ipython``-directive:

.. code-block:: restructuredtext
Expand Down Expand Up @@ -210,6 +232,10 @@ Which also matches the prompts when using prompts with continuations:
output
In [2]: second
If you want a detailed explanation how the RegEx's work you can also use `RegEx101`_ and read the ``Explanation`` sidebar.

.. _RegEx101: https://regex101.com


Configure whether *only* lines with prompts are copied
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down

0 comments on commit f97ed8b

Please sign in to comment.