Skip to content

Conversation

@amoeba
Copy link
Member

@amoeba amoeba commented Sep 23, 2025

Creates and enables an extra.js script adapted from uv's docs that cleans copied code blocks by removing any prompts or output. Also updates some areas in the docs where we weren't using prompt chars that we now can.

Any code blocks with prompt characters must be console not sh for this to work.

Closes #54

We have to use "console" to get the right classes for the clipboard script to work. If you use "sh" and add "$ " to the code block, it doesn't work
@ianmcook
Copy link
Member

ianmcook commented Sep 23, 2025

Very cool! It might be safer to use && instead of ;.

OTOH I think ; will generally work on Windows in cmd.exe and PowerShell but && won't.

@ianmcook
Copy link
Member

I clicked the button to copy the YAML at concepts/driver_manifest and it replaced the line breaks with semicolons.

@ianmcook
Copy link
Member

ianmcook commented Sep 23, 2025

Looks like this doesn't handle # comment characters properly (like in the blocks on the guides/driver_list page). But the solution might be to get rid of the # characters there.

@amoeba
Copy link
Member Author

amoeba commented Sep 24, 2025

Thanks for testing. I also notice that pycon blocks aren't perfect. Fixing these things now.

@amoeba
Copy link
Member Author

amoeba commented Sep 24, 2025

Re: ; vs &&, I went for ; for being as cross plat as possible since, as you note, not all shells support && (even fish didn't for a while). However, I think we can maybe get away with preserving the line breaks. So when a user copies a multi-command code block, they get,

first command
second command
third command

bash and zsh don't like this (though fish handles it gracefully) but I don't think it's an unreasonable choice on our part: The user sees multiple lines of commands and might be expecting their clipboard gets filled with similarly-structured output (i.e., we should preserve whitespace where we can and try to just remove prompt/comment chars).

@amoeba
Copy link
Member Author

amoeba commented Sep 24, 2025

I've done some manually testing and I think the only place this doesn't work great is pycon blocks (we don't preserve whitespace which python needs to parse). This could be hard to do without rewriting the code. Can we skip it?

@ianmcook ianmcook closed this Sep 25, 2025
@ianmcook ianmcook reopened this Sep 25, 2025
@ianmcook
Copy link
Member

With an assist from Claude Code, I fixed the leading whitespace issue and also made the script preserve blank lines. @amoeba please take a look.

@amoeba
Copy link
Member Author

amoeba commented Sep 25, 2025

Seems to work nicely, thanks @ianmcook.

@amoeba
Copy link
Member Author

amoeba commented Sep 25, 2025

Tested in Safari and Firefox.

@amoeba amoeba merged commit 9c6f418 into columnar-tech:main Sep 25, 2025
8 checks passed
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.

docs: add js snippet to copy code blocks without prompt character

2 participants