docker / docs

Source repo for Docker's Documentation
https://docs.docker.com
Apache License 2.0
4.18k stars 7.32k forks source link

code blocks include prompt chars when copied #21316

Open palfvin opened 2 weeks ago

palfvin commented 2 weeks ago

Is this a docs issue?

Type of issue

Other

Description

The code blocks for docker shell commands typically show a prompt of "/ # ", but this prompt is not recognized by the shell lexer associated with the console language. As a result, when the code is copied using the copy icon, the prompt is included in the copied text, causing errors when pasted.

Location

https://docs.docker.com/get-started/workshop/05_persisting_data/

Suggestion

If I'm following things correctly, the console/shell lexer that this github page is using is read-only and there aren't any other lexers with more comprehensive notion of shell prompts. As such, I'd suggest removing the prompt from the code block until such time as a suitable lexer is available.

dvdksn commented 2 weeks ago

Hello. Thanks for reaching out.

We're using the lexer from chroma to generate these code blocks. Not that it matters - chroma also does not recognize the shell prompt format in these examples. Even if it did, the shell prompt is actually manually excluded from the copied text with a regex: https://github.com/docker/docs/blob/8dd24764e2e5ff1967c1db0ed82711566450d7be/layouts/_default/_markup/render-codeblock.html#L7

We could add something like [/\w]+\s[#$] to the above regex to exclude it from the copied contents. But it's already hacky as it is... maybe there is a more elegant solution. E.g. a custom component we could use to render console I/O examples...