Is there a command line utility for rendering GitHub flavored Markdown?

后端 未结 25 1711
一个人的身影
一个人的身影 2020-11-28 16:53

I\'m wondering if there is a command line utility for taking a GitHub flavored Markdown file and rendering it to HTML.

I\'m using a GitHub wiki to create website con

25条回答
  •  死守一世寂寞
    2020-11-28 17:56

    Building on this comment I wrote a one-liner to hit the Github Markdown API using curl and jq.

    Paste this bash function onto the command line or into your ~/.bash_profile:

    mdsee(){ 
        HTMLFILE="$(mktemp -u).html"
        cat "$1" | \
          jq --slurp --raw-input '{"text": "\(.)", "mode": "markdown"}' | \
          curl -s --data @- https://api.github.com/markdown > "$HTMLFILE"
        echo $HTMLFILE
        open "$HTMLFILE"
    }
    

    And then to see the rendered HTML in-browser run:

    mdsee readme.md
    

    Replace open "$HTMLFILE" with lynx "$HTMLFILE" if you need a pure terminal solution.

提交回复
热议问题