Skip to content

Improve shell syntax highlighting - #47

Open
adesso-os wants to merge 1 commit into
getsops:mainfrom
adesso-os:feat/code-blocks
Open

Improve shell syntax highlighting#47
adesso-os wants to merge 1 commit into
getsops:mainfrom
adesso-os:feat/code-blocks

Conversation

@adesso-os

Copy link
Copy Markdown
Contributor

As is, there are several code blocks with lines prefixed with $, indicating to me that they want to mimic a shell session. These code blocks are marked with either sh or bash tags, to suggest syntax highlighting appropriate for such shell sessions.

This doesn't seem ideal, because command output is highlighted just as if it was another shell command.

Before

image

Hugo uses the Chroma syntax highlighter, which provides a dedicated lexer specifically for such scenarios. This change makes use of that lexer to improve the formatting.

After

image

There were several cases where lines in these code blocks wanted to indicate comments using #, which indicates a comment in a shell script. However, because # commonly indicates the prompt of a root shell, such lines had to be adjusted to correctly reflect shell usage, where the comment would be entered on the prompt. This felt weird initially, but the consistent behavior and correctness ultimately made me prefer it.

The type console was specifically chosen in favor over other tags (like bash-session), because the docsy theme specifically supports this language tag to improve the user experience on such code blocks. The copy-to-clipboard behavior will not copy command output, or the prompt character, in these cases.

https://github.com/google/docsy/blob/62f3ca81a9e4f7fb683e1f94a7ac25cb9236430d/theme/assets/scss/td/_code.scss#L93-L104

Clipboard Content Before

$ sops edit mynewtestfile.yaml
mynewtestfile.yaml doesn't exist, creating it.
please wait while an encryption key is being generated and stored in a secure fashion
file written to mynewtestfile.yaml

Clipboard Content After

sops edit mynewtestfile.yaml

For the more complex usage scenarios in the Advanced Usage section, I switched the prompt prefix to % to use $ for the sub-shell, to align with Chroma expectations.

I also applied the console tag consistently throughout the code base to encourage adopting this approach, instead of using the other shell types that might feel more appropriate when not used to this specific behavior.

@netlify

netlify Bot commented Jul 30, 2026

Copy link
Copy Markdown

Deploy Preview for getsops ready!

Name Link
🔨 Latest commit f40de40
🔍 Latest deploy log https://app.netlify.com/projects/getsops/deploys/6a6b5146815cf80008ba79c3
😎 Deploy Preview https://deploy-preview-47--getsops.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

As is, there are several code blocks with lines prefixed with `$`, indicating to me that they want to mimic a shell session. These code blocks are marked with either `sh` or `bash` tags, to suggest syntax highlighting appropriate for such shell sessions.

This doesn't seem ideal, because command output is highlighted just as if it was another shell command.

Hugo uses the Chroma syntax highlighter, which provides a dedicated lexer specifically for such scenarios. This change makes use of that lexer to improve the formatting.

There were several cases where lines in these code blocks wanted to indicate comments using `#`, which indicates a comment in a shell script. However, because `#` commonly indicates the prompt of a root shell, such lines had to be adjusted to correctly reflect shell usage, where the comment would be entered on the prompt.

The type `console` was specifically chosen in favor over other tags (like `bash-session`), because the docsy theme specifically supports this language tag to improve the user experience on such code blocks. The copy-to-clipboard behavior will not copy command output, or the prompt character, in these cases.

Signed-off-by: Oliver Salzburg <oliver.salzburg@adesso.de>
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.

1 participant