How can I highlight the Bash/shell commands in Markdown files?
For example, to highlight js
, I write:
Bitbucket uses CodeMirror for syntax highlighting. For Bash or shell you can use sh
, bash
, or zsh
. More information can be found at Configuring syntax highlighting for file extensions and Code mirror language modes.
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.
Using the knitr package:
```{r, engine='bash', code_block_name} ...
E.g.:
```{r, engine='bash', count_lines}
wc -l en_US.twitter.txt
```
You can also use:
engine='sh'
for shellengine='python'
for Pythonengine='perl'
, engine='haskell'
and a bunch of other C-like languages and even gawk
, AWK, etc.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
```
Per the documentation from GitHub regarding GFM syntax highlighted code blocks
We use Linguist to perform language detection and syntax highlighting. You can find out which keywords are valid in the languages YAML file.
Rendered on GitHub, console
makes the lines after the console blue. bash
, sh
, or shell
don't seem to "highlight" much ...and you can use posh
for PowerShell or CMD.
If I need only to highlight the first word as a command, I often use properties
:
```properties
npm run build
```
I obtain something like:
npm run build