-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Auto-remove leading $
symbols when copying from docs terminal blocks
#9204
Conversation
✅ Deploy Preview for prefect-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
Sweet! |
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.
Awesome, thank you!
Moved back to draft pending implementation of a simpler and superior solution based on an excellent suggestion by @znicholasbrown 😀 |
Another option is just editing the docs to remove leading In most cases, removing the leading This approach also requires no custom JavaScript, so there's one less thing that could break when updating to new Mkdocs versions. There are a few code blocks that contain a terminal command and its output, and I think a Do you have any thoughts on this, @billpalombi and/or @discdiver? I know you have higher-priority items to tackle, so I'd be happy to update the docs if you think this is workable. @znicholasbrown demonstrated another approach that only requires a little custom JS, and would give docs authors the option to specify alternate code to copy. I think that's still useful, but it seems like a separate feature you'd want even if commands in the docs have no leading |
Hey @rpeden! Thanks for spelling out that case for us. I agree that removing the |
Thank you, Ryan. I support removing the $ for easier copying, standardized formatting, and simplified doc creation. |
Thanks got the quick feedback! Since you plan a separate PR, @billpalombi, I'll close this one. |
See #9875 |
PR #9026 added copy buttons to all code blocks in the docs, so users can now copy the entire block with a single click.
However, many code blocks intended for use in the terminal contain a leading
$
character. Consequently, if the user clicks the copy button and then pastes into a terminal, they'll see an error message when trying to run it.Per a suggestion from @cicdw in #9026, this PR adds JavaScript that removes leading
$
symbols from terminal blocks before the text is copied. It does this invisibly in the background, by creating a hidden element containing the cleaned text, which then gets copied to the clipboard. The $ signs remain in the visiblecode
element on the docs page.The JavaScript only acts on code blocks where we intentionally apply terminal styling, like so:
It leaves regular code blocks alone.
Example and QA
Before
Navigate to a docs code block with leading $ signs, like this one: https://docs.prefect.io/2.10.3/getting-started/installation/#installing-for-development
Click the copy button in the top right of the terminal block.
Paste the commands into a terminal and notice the leading $ characters:
Try to run the commands and see an error message (the exact message will vary depending on which OS and terminal you use):
After
The commands will now run successfully if you press return. Don't actually run them unless you want to clone the Prefect repo and pip install it in dev mode in your current environment. Just to be thorough, I ran the pasted commands in a fresh Conda environment, and everything worked as expected.
Checklist
<link to issue>
"fix
,feature
,enhancement
,docs
.