Comments (14)
@Samy-Oubouaziz in the end I used indeed a similar approach to what you propose: to enumerate all possible prompts. However. as I mentioned, I had quite a number of different prompt (around12-14 IIRC, I left that project now so can't check), each with #
and $
, so it became really a complex enumeration.
My comment however was more to point out that this extension currently does not support complex regexp with ( )
, to help spare time in case someone encounters the same problem.
from sphinx-copybutton.
Thanks for opening your first issue here! Engagement like this is essential for open source projects! 🤗
If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.
If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).
Welcome to the EBP community! 🎉
from sphinx-copybutton.
Oh no regexes can be tricky. It looks like you have two spaces after dollar, have you tried using the specific white space regex: r"\$\s|\#\s"
?
from sphinx-copybutton.
Thanks for your reply!
I tried:
copybutton_prompt_text = r"\$\s|\#\s"
On the built document, the Copy button copies the entire block, but does not omit the "$ " prompt.
from sphinx-copybutton.
FWIW, the JavaScript regex "or" pattern looks to involve parentheses: https://www.w3schools.com/jsref/jsref_regexp_xy.asp.
but I'm not having much luck permutating on that, either...
from sphinx-copybutton.
@choldgraf just remembered that I left @wabernatScality hanging a bit here lol. I'm a bit out of ideas, without perhaps going into the code and trying to add more test cases
from sphinx-copybutton.
@wabernatScality do you still have these issues? this is also something I don't know how to debug either, I am terrible with regexes :-/ it sounds like it might be a bit of time before we can figure out a solution, just FYI
from sphinx-copybutton.
We have not found a solution. I've rolled out sphinx-copybutton with regexp turned off, hoping our own talent might be sufficiently bent out of shape to fix it as a challenge. In the meantime, we make do with '$ ' as our default "cropped" prompt.
from sphinx-copybutton.
Sounds good - if anybody can figure out a fix for why this isn't working I am happy to review and cut a release quickly 👍
from sphinx-copybutton.
Any updates on this issue? I can also reproduce it with and without copybutton_prompt_is_regexp
. I'm using Python==3.6.9 sphinx==4.0.2 sphinx_rtd_theme==0.5.2 sphinx-copybutton==0.4.0
.
from sphinx-copybutton.
I am facing a similar issue (perhaps exactly the same). I was asked to setup a quitevery complex regexp, which validates at regexp101.com, to remove a number of prompts from the docs.
After quite a lot of debugging, my guess is that @wabernat was on the right track: ORs using ( )
are apparently not supported in this extension. I stripped down my prompt text to set up a counterexample.
copybutton_prompt_text = r"cluster#\s|single#\s"
this workscopybutton_prompt_text = r"(cluster|single)#\s"
this does not work, regardless of any escape used on parentheses (e.g,\(
,\\(
,\\\(
etc.).
Both regexp validate at regexp101.com and match against the same set of examples.
- The isse raised since we wanted to catch non only
#
as prompt ending character, but also$
, therefore I added(cluster |single)(#|\$)\s
as regexp.
To be honest, I have no idea how to fix this issue, since my regexp knowledge is for sure lower than @choldgraf 's 😅
from sphinx-copybutton.
Hello all, I am currently working on the same project as @wabernat was 3 years ago for the same company, and ran into the same problems, which led me to this issue !
We use a variety of prompts in the following formats:
#
$
[foo@bar]#
{{fooBar}}#
(each one has a trailing space)
I managed to get the regex to work by adding the following lines in our conf.py file:
copybutton_prompt_text = '\# |\$ |\[.*\@.*\]\# |\{\{.*\}\}\# '
copybutton_prompt_is_regexp = True
copybutton_remove_prompts = True
The documentation is a bit unclear and feels like we have to use enclose the regular expression in a raw string for it to work, but it seems that it is not the case.
Can anyone confirm or deny ?
Also, the documentation should display basic examples of regex to copy-paste as is to the conf.py of a project, at least for testing purposes.
Example:
The following configuration will treat the string "# " or "$ " as prompts which will not be copied.
copybutton_prompt_is_regexp = True
copybutton_remove_prompts = True
copybutton_prompt_text = '\# |\$ '
I can open a documentation PR if you agree with this proposal.
Thanks !
Edit: behavior seems to be the same with or without the r
at the beginning of the regex prompt text.
from sphinx-copybutton.
@stefanodavid You may have solved your issue already, but maybe try the following:
copybutton_prompt_text = r"cluster\# |single\# |cluster\$ |single\$ "
I do not know the regex best practices, but if it is either "cluster" or "single" + "# " or "$ " (which is only 4 possible prompts), maybe it is not worth factorizing everything!
from sphinx-copybutton.
Thank you @stefanodavid ! This might be a good time to close this issue @choldgraf, and maybe open a doc PR for better regex explanations for users who are not familiar with it, including:
- basic regex examples
- a list of characters that need to be escaped maybe?
- an admonition regarding the limitations of regex in t his context
Thanks again !
from sphinx-copybutton.
Related Issues (20)
- Convert documentation into MyST Markdown
- Update the copybutton image to match GitHub's copybutton style
- Modularize our documentation a bit HOT 1
- Copy button stays put sometimes when other objects shrink its container
- Copy button does not show up for productionlist HOT 1
- issue to store media HOT 1
- Post message after all copy buttons added HOT 3
- Build failed for config doc when importing an extension sphinx_copybutton HOT 4
- Failed build in RTD for extension sphinx-copybutton
- Copybutton disappears too quickly if you click copy then move the cursor off the code cell
- Conflict between regex exclusion/prompt selection and copybutton_exclude HOT 12
- Add Trailing New Line to Clipboard Option HOT 1
- Blank Lines Stripped from code
- Use only one tooltip HOT 2
- newline ignored when using emphasize-lines HOT 1
- Copy button not shown on some pages HOT 3
- Example Not Functional HOT 2
- Add expand button for some block elements HOT 1
- Stripping ellipsis HOT 1
- URL to copy-button.svg is incorrect because DOCUMENTATION_OPTIONS.URL_ROOT is undefined HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sphinx-copybutton.