Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

github markdown - preserve Linux terminal output

Is there a way to preserve the colors of a terminal output when creating github flavored markdown? For example if I want to include some examples of a terminal including the results of ls which would have different colors for directories, executable etc?

image for example:

enter image description here

like image 946
Dr.Avalanche Avatar asked May 25 '26 04:05

Dr.Avalanche


2 Answers

1

```console
foo@bar:~$ whoami
foo
```

enter image description here

2

```shell-session
foo@bar:~$ whoami
foo
```

from: https://stackoverflow.com/a/49004070/2193455

like image 129
kangear Avatar answered Jun 01 '26 02:06

kangear


Usually, Markdown is parsed into HTML. You can try use <span style="color: red;">...</span> tags and your parser might let that through.

Note that you wouldn't be able to use HTML tags inside a code block. You would have to implement the code blocks themselves with HTML and CSS, and at that point it kind of stops bring worth it.

Even worse, sometimes Markdown to HTML parsers will strip all or most HTML tags. If you're posting on GitHub, I think this would be the case. Then your only option would be to embed an image.

like image 35
Yatharth Agarwal Avatar answered Jun 01 '26 01:06

Yatharth Agarwal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!