Search code examples
github-flavored-markdown

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


Solution

  • 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.