-
Notifications
You must be signed in to change notification settings - Fork 57
Description
Hi, and thanks for providing this extension! :)
I was wondering whether it would be possible for you to add a feature that allows multi-line regex matching in the configuration for prompt identifiers.
Is your feature request related to a problem? Please describe.
My use case is the following: I maintain the DataLad handbook. Its a Sphinx-based Tutorial/User-documentation that contains a continuous, hands-on narrative, and it uses code snippets that readers are encouraged to copy-paste into their terminal to follow along to give a software demonstration for various workflows.
The code snippets are in some ways peculiar. For one, they can get quite complex because they are walk-throughs through actual, sometimes complex use cases. Second, they contain the output of each command (so that users know what to expect, or can chose to read the book without coding along). Third, the output of the commands comes from a recording of actual code execution, which we do using the autorunrecord Sphinx extension in order to automatically record the output of the most recent software release, and to have a "workflow test suite", as the entire 400 page book will fail to build if a software update breaks any of the documented workflows.
As an example: Here is how a code snippets looks in raw
.. runrecord:: _examples/DL-101-103-103
:language: console
:workdir: dl-101/DataLad-101
:cast: 01_dataset_basics
$ datalad save -m "Add notes on datalad create"and here is how it ends up in the final document:

The copy-button extension would make it much easier for users to copy-paste code without output into their own terminals, and it works very well in many snippets. However, there are a number of edge cases where the copy button extension wouldn't succeed due to the way our project works.
One of them are here documents which we quite frequently used (the top of this page contains an example.
A standard here-doc looks like this in our code snippets:
$ cat << EOT > notes.txt
One can create a new dataset with 'datalad create [--description] PATH'.
The dataset is created empty
EOT
This allows copy-pasting it as is into a terminal for users, and executing it locally during the build of the book, but a copy-button configured to copy only lines that start with a $ wouldn't be able to catch anything from that here doc apart from the first line.
Describe the solution you'd like
If there would be an option for multi-line regex matching, so that we could for example match for the EOT at the end of the snippet, we could work around this. Unfortunately, I have no JS skills at all, so implementing this would be a tough and time-intensive endeavor for me. I was hoping that it may be easy for people with JS knowledge.
Describe alternatives you've considered
We're faced with a range of suboptimal choices without the feature. Using the copy-button in its current state means having it work for a subset of code snippets, and having user to realize that what gets copied is wrong or insufficient, and that is not a nice UX experience. Likewise, if we would write the heredocs with, e.g., command prompts, they become inexecutable for us during build, and fail to run if anyone would copy-paste them without the copy button.
Additional context
I guess I'm a bit sorry for the weird use case. I'm hoping that it may just be a trivial and easy addition for anyone who knows JS. Even if that feature wouldn't be desired in this extension, we would be happy to keep a fix in a fork.