-
Notifications
You must be signed in to change notification settings - Fork 51
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
ENH: Exclude unselectable text from being copied (update) #178
ENH: Exclude unselectable text from being copied (update) #178
Conversation
…electable text should be excluded from copy and do so if needed. [_static/copybutton_funcs.js] Added functionality to get unselectable elements and remove their text.
…ith funcitons using .innerText. [package.json] Added browser-env module for DOM support in testing. [docs/index] Updated documentation. [copybutton, copybutton_funcs] Fixed minor errors. Updated default exclude text. [__init__] Updated default exclude text.
for more information, see https://pre-commit.ci
- `.linenos` is the line numbers, and `.gp` is the tag from the pygments highlighter for things like the `$` prompt. Upstream sphinx CSS excludes `.gp` from being copied, see the analysis here: executablebooks#138 (comment) - If upstream sphinx excludes `.gp`, we probably should as well.
- Re-add documentation from PR executablebooks#138 - that PR got conflicted with a docs rearrangement, so I add the docs back in one chunk now. I include my own suggestions in that PR.
Just a note that I don't have much time to give this PR a thorough review. If somebody wishes I am happy to give merge privileges to push things forward, and I welcome a review from somebody else out there. |
This is in production in some of our sites. To do a test, try to select text in the code blocks in the link, and see if you can select the Example with sphinx_rtd_theme: Example with sphinx_book_theme: Example with sphinx_book_theme that does not use these changes. The copy button copies the On investigation, I found that sphinx-book-theme does exclude (the branch links above might disappear if those branches are deleted at some time in the future) |
As for review, don't trust me but I think the most difficult review has been done in #138, and the main question here would be "excluding .gp" and "is the general code still like #138", "is documentation good enough", and "is the test included good enough". I haven't looked at the javascript code much. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me - one question: do we really need all of the package-lock.json
changes? Other than that I think it looks good to go. I generally try not to update the package requirements in a PR that also does other stuff unless really necessary (but maybe it is necessary?)
I really don't know, it was all in the other pull request. I can test with it removed and see what happens - and I will also give a closer check to see if there are any changes that seem significant. I don't know JavaScript/node so don't count on me that much!
Thanks for the review!
|
copybutton_exclude = '.exclude_me' | ||
``` | ||
By default `.linenos, .gp` are excluded. If you specify the | ||
`copybutton_exclude` option it will replace the default. `.linenos` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two spaces before .linenos
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks both for your work on this. I included a few comments to clean up the final code before merging.
|
It seems that package-lock.json has real changes in it - there are new dependencies, and these get added to package-lock.json. There don't seem to be changes to the versions that were there before. So, my thought is that it should stay updated as we see here. If package-lock.json should be ignored, I'd propose to do that in a new pull request. Again, not an expert here, but I like the general idea of the general dependencies, and the exact working dependencies - I would want to do that more in my projects. |
Updates seem to work on a test deployment. |
My mistake. |
This PR's branch was used across eight different (but similar, all sphinx-rtd-theme) projects in a workshop over the last six weeks and no reports of problems. (it was this same workshop last time that prompted me to work on this). |
Can I add somebody in this PR to the maintainers so that you can press the merge button? We should not be bottlenecking progress on myself! |
I wouldn't mind pushing merge, but don't know enough javascript to give a more critical evaluation or fix hard things if they break (but at least I can help revert it if needed...). But if it's easier to add someone than change the technical limits and you ask me to push merge, I'm happy to! |
Done! https://github.com/executablebooks/sphinx-copybutton/invitations I don't think we have the luxury of bottlenecking decision-making only on people that know JavaScript well, I certainly do not consider myself one of those people :-) |
Thanks for the invite! I assume this means I should merge when I can. |
I'll go ahead and merge this one, but I welcome reviews and merges in the future from you! If others are interested in maintainer status I am happy to share this if you are willing to help out with the repository. |
Hi! I am using this
I am confused about whether the implementation of the line number exclusion depends on web browser or it is not well supported by readthedocs.io. |
could this be because it is not yet released? or has somebody made a release of this already? |
The version of |
That is indeed very confusing - can you open an issue to explain the bug, expected behavior, when it breaks, examples, etc? That will be easier to track. |
I have found the function is OK when visiting the web page with Safari on several other MacBooks. |
Could it be some sort of javascript blocker or adblocker (or other
extension)? That often messes up sites for me (but not this
sphinx-copybutton case with my particular settings...)
|
@rkdarst @choldgraf is it possible that this PR clashes with settings like
This doesn't do what the documentation says anymore. I think the reason is that by default sphinx-copybutton/sphinx_copybutton/_static/copybutton.js_t Lines 154 to 157 in 4345c48
setting
stops filtering |
Oh, interesting. You know, I didn't even know about those settings. But also, in theory that shouldn't be needed. In your case, do you highlight with the pygments language But Hm... what to do... at least docs need to be updated right away.
|
@rkdarst I don't have a strong preference where the filtering should happen, but it does seem like |
Could somebody please open an issue to track this bug and how to reproduce it + links to examples? I think that will be easiest at figuring out how to fix it. I am happy to review PRs if somebody thinks they know how to resolve this |
yes, I will open a new issue once I have time, and describe the two conflicting strategies and the trade-offs. + update docs to say the current state. |
Please make sure example works for empty lines in code ie prompts with and without a trailing space: See #194 |
This is an update of #138, rebased to remove the conflicts. In a local test, it seems to work.
I haven't adjusted any of the code from that PR. It seems the only conflict was with the docs rearrangement, I excluded that from the rebase and then re-added it back.
I did add
.gp
to the defaultcopybutton_exclude
value. The reasoning behind that is here (and previous comments): #138 (comment)I think that if default Sphinx excludes
.gp
, it is best to copy that into our defaults. In the long-term, it is fair to ask "should the exclusion information be in two places", but the previous PR was adjusted to use existing info (= detect what is un-selectable) to duplicating.linenos
being configured, so I guess we stick with that for now.Note that I am just the messenger here, all actual work on this comes from @bicarlsen (and commit authorship is preserved)
Closes: #138