Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highlight Bash/shell code in Markdown files

How can I highlight the Bash/shell commands in Markdown files?


For example, to highlight js, I write:

```js function () { return "This code is highlighted as Javascript!"} ``` 

To highlight HTML code I use ```html.

How can we highlight Bash/shell commands?

like image 389
Ionică Bizău Avatar asked Nov 30 '13 18:11

Ionică Bizău


People also ask

How do you highlight code in Markdown?

Many Markdown processors support syntax highlighting for fenced code blocks. This feature allows you to add color highlighting for whatever language your code was written in. To add syntax highlighting, specify a language next to the backticks before the fenced code block.

How do you add a code snippet in Markdown?

There are two ways to format code in Markdown. You can either use inline code, by putting backticks (`) around parts of a line, or you can use a code block, which some renderers will apply syntax highlighting to.

How do you comment code in bash?

When writing bash scripts, any text after a hash sign ( # ) indicates the start of a comment, and any text after # in the same line does not execute. When using a text editor or IDE, comments are colored differently from the rest of the code.

How do you create a table of contents in Markdown?

Press CTRL + SHIFT + P. Select Markdown: Create Table of Contents.


2 Answers

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 ``` 

GitHub Markdown preview tab screenshot

like image 195
Anton Strogonoff Avatar answered Sep 25 '22 13:09

Anton Strogonoff


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.

like image 24
hek2mgl Avatar answered Sep 22 '22 13:09

hek2mgl