Highlight Bash/shell code in Markdown files

后端 未结 7 2043
猫巷女王i
猫巷女王i 2021-01-29 17:35

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


For example, to highlight js, I write:



        
7条回答
  •  执笔经年
    2021-01-29 17:55

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

提交回复
热议问题