Skip to content

Conversation

@Jongmassey
Copy link
Contributor

Fixes #1458

  • Removes >>> and any output lines from copied text when copy button is clicked on a Python code block
  • Removes $ and any output lines from copied text when copy button is clicked on a Shell code block
  • Marginally increases page weight and load time: on load every code copy button on the page has an attribute set which contains the "cleaned" code to be copied

@Jongmassey Jongmassey changed the title Jongmassey/fix terminal code copy Fix terminal code copy Mar 15, 2024
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Mar 15, 2024

Deploying opensafely-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 65f0c9f
Status: ✅  Deploy successful!
Preview URL: https://15973e4f.opensafely-docs.pages.dev
Branch Preview URL: https://jongmassey-fix-terminal-code.opensafely-docs.pages.dev

View logs

@Jongmassey Jongmassey merged commit 3b8f1d9 into main Mar 15, 2024
@Jongmassey Jongmassey deleted the Jongmassey/fix-terminal-code-copy branch March 15, 2024 11:26
eth3lbert added a commit to eth3lbert/uv that referenced this pull request Jul 24, 2024
zanieb added a commit to astral-sh/uv that referenced this pull request Jul 31, 2024
## Summary

This PR improves the copy of the console command example by:

- Preventing the selection of generic prompts and generic output
- Lazily setting copy content by leveraging intersection observer

Most of the changes are inspired by
opensafely/documentation#1461

Some other useful refs:
- squidfunk/mkdocs-material#3647
-
https://mkdocstrings.github.io/recipes/#prevent-selection-of-prompts-and-output-in-python-code-blocks

Resolves #5355

## Test Plan

- 
  ``` shell-session
  mkdocs serve -f mkdocs.public.yml
  ``` 
- Navigate to http://localhost:8000/uv/first-steps/#viewing-the-version
- Try clicking the copy button
- Try copying by selecting the content

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Copying Python code blocks includes ">>>"

3 participants