-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Added copy to clipboard button for console tab commands #2431
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
base: main
Are you sure you want to change the base?
Conversation
|
This looks nice 🌻 I'd recommend installing git hooks (you can follow the last section of the readme) and rebasing the PR to have a bit more clear history. |
ad9d2d6 to
24e3b21
Compare
bb03309 to
07c155d
Compare
c22de90 to
cd6cf4c
Compare
|
Hi @ulgens , |
adamzap
left a comment
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.
Here are some initial thoughts. Thanks for attempting this!
| }); | ||
|
|
||
| function on_success(el) { | ||
| function on_success() { |
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.
Why add an unused argument here and on line 145?
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.
Good catch! Just to clarify — I actually removed the unused el parameter here, since it wasn't being used (the functions access success_el via closure instead). Happy to keep it if you prefer consistency with other patterns in the codebase.
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.
Oh, thanks! Sorry for my misunderstanding here.
| // Console tabs: extract text excluding prompts (.gp) and output (.go) | ||
| const pre_el = console_section.querySelector('.highlight pre'); | ||
| text = ''; | ||
| if (pre_el) { |
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.
In what case is there not a <pre> element?
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.
You're right — since Pygments always generates the <pre> element, this check isn't strictly necessary.
I'll remove it to keep the code cleaner. Thanks for pointing this out!
| const pre_el = console_section.querySelector('.highlight pre'); | ||
| text = ''; | ||
| if (pre_el) { | ||
| pre_el.childNodes.forEach(function (node) { |
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.
Do you think it would be more elegant to grab the text content like the old code was doing and just left trim the prompt?
(...).textContent.trim().replace(/^\$ /, '')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.
Great question! I went with the node-based approach mainly because:
- It also handles the Windows tab (which uses
...>prompts) - It excludes command output marked with
.go(in case any examples show output)
That said, if the console blocks only ever show simple $ prompts without output, a regex would definitely be simpler. I'm happy to switch to:
text = pre_el.textContent.trim().replace(/^(\$ |\.\.\.>)/gm, '');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.
Let me know which approach you'd prefer!
cd6cf4c to
b3cf678
Compare
|
Updated per feedback — removed the |
Summary
Adds a copy-to-clipboard button to console tab code blocks (Unix / Windows installation commands).
Fixes: #1276, #2399
Builds on feedback from @sabderemane in PR #1434.
Changes
JavaScript
djangoproject/static/js/djangoproject.js.gp— e.g.$,...>).go)SCSS
djangoproject/scss/_console-tabs.scssposition: relativeto console tab sections.btn-clipboardstyling using absolute positioning (nofloat)Visual Comparison
Before
After
Video.Project.mp4