Improve shell syntax highlighting - #47
Conversation
✅ Deploy Preview for getsops ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
1b945bb to
31c0f3d
Compare
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>
31c0f3d to
f40de40
Compare
felixfontein
left a comment
There was a problem hiding this comment.
Thanks for working on this! I agree that $ # looks kind of ugly (that was my first impression), but as you wrote, the result is better that way...
Co-authored-by: Felix Fontein <felix@fontein.de> Signed-off-by: Oliver Salzburg (adesso) <112879907+adesso-os@users.noreply.github.com>
Co-authored-by: Felix Fontein <felix@fontein.de> Signed-off-by: Oliver Salzburg (adesso) <112879907+adesso-os@users.noreply.github.com>
I looked at the lexer for some time, trying to figure out if there's a more elegant way to add this information. One way I could see would be to make it appear just like regular command output, but that also seems confusing in terms of consistency. Another approach would be to split up, and move these comments out of the code blocks. This also didn't feel quite right, but would have the benefit of making the copy-to-clipboard feature slightly more useful, because it would copy smaller steps. |
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 eithershorbashtags, 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
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
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
consolewas specifically chosen in favor over other tags (likebash-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
Clipboard Content After
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
consoletag 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. It also makes the copy-to-clipboard feature consistently not copy the prompt prefix.