Highlight Bash/shell code in Markdown files
Solution 1:
If you are looking to highlight a shell session command sequence as it looks to the user (with prompts, not just as contents of a hypothetical script file), then the right identifier to use at the moment is console:
```console
foo@bar:~$ whoami
foo
```
Solution 2:
It depends on the Markdown rendering engine and the Markdown flavour. There is no standard for this. If you mean GitHub flavoured Markdown for example, shell
should work fine. Aliases are sh
, bash
or zsh
. You can find the list of available syntax lexers here.
Solution 3:
I found a good description at Markdown Cheatsheet:
Code blocks are part of the Markdown spec, but syntax highlighting isn't.
However, many renderers -- like GitHub's and Markdown Here -- support syntax highlighting. Which languages are supported and how those language names should be written will vary from renderer to renderer. Markdown Here supports highlighting for dozens of languages (and not-really-languages, like diffs and HTTP headers); to see the complete list, and how to write the language names, see the highlight.js demo page.
Although I could not find any official GitHub documentation about using highlight.js
, I've tested lots of languages and seemed to be working
To see list of languages I used https://github.com/highlightjs/highlight.js/blob/master/SUPPORTED_LANGUAGES.md
Some shell samples:
Shell: console, shell
Bash: bash, sh, zsh
PowerShell: powershell, ps
DOS: dos, bat, cmd
Example:
```bat
cd \
copy a b
ping 192.168.0.1
```