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

后端 未结 25 1562
一个人的身影
一个人的身影 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:36

    I wrote a small CLI in Python and added GFM support. It's called Grip (Github Readme Instant Preview).

    Install it with:

    $ pip install grip
    

    And to use it, simply:

    $ grip
    

    Then visit localhost:5000 to view the readme.md file at that location.

    You can also specify your own file:

    $ grip CHANGES.md
    

    And change port:

    $ grip 8080
    

    And of course, specifically render GitHub-Flavored Markdown, optionally with repository context:

    $ grip --gfm --context=username/repo issue.md
    

    Notable features:

    • Renders pages to appear exactly like on GitHub
    • Fenced blocks
    • Python API
    • Navigate between linked files (thanks, vladwing!) added in 2.0
    • Export to a single file (thanks, iliggio!) added in 2.0
    • New: Read from stdin and export to stdout added in 3.0

    Hope this helps someone here. Check it out.

    0 讨论(0)
  • 2020-11-28 17:36

    Improving upon @barry-stae's solution. Stick this snippet in ~/.bashrc

    function mdviewer(){
      pandoc $* | lynx -stdin
    }
    

    Then we can quickly view the file from the command-line. Also works nicely over SSH/Telnet sessions.

    mdviewer README.md
    
    0 讨论(0)
  • 2020-11-28 17:37
    pip3 install --user markdown
    python3 -m markdown readme.md > readme.html
    

    It doesn't handle GitHub extensions, but it is better than nothing. I believe you can extend the module to handle the GitHub additions.

    0 讨论(0)
  • 2020-11-28 17:38

    A 'quick-and-dirty' approach is to download the wiki HTML pages using the wget utility, instead of cloning it. For example, this is how I downloaded the Hystrix wiki from GitHub (I'm using Ubuntu Linux):

     $ wget -e robots=off -nH -E -H -k -K -p https://github.com/Netflix/Hystrix/wiki
     $ wget -e robots=off -nH -E -H -k -K -I "Netflix/Hystrix/wiki" -r -l 1 https://github.com/Netflix/Hystrix/wiki
    

    The first call will download the wiki entry page and all its dependencies. The second one will call all sub-pages on it. You can browse now the wiki by opening Netflix/Hystrix/wiki.1.html.

    Note that both calls to wget are necessary. If you just run the second one then you will miss some dependencies required to show the pages properly.

    0 讨论(0)
  • 2020-11-28 17:40

    I created a tool similar to Atom's Preview functionality, but as a standalone application. Not sure if this is what you're looking for, but it might be helpful. -- https://github.com/yoshuawuyts/vmd

    vmd

    0 讨论(0)
  • 2020-11-28 17:41

    To read a README.md file in the terminal I use:

    pandoc README.md | lynx -stdin
    

    Pandoc outputs it in HTML format, which Lynx renders in your terminal.

    It works great: It fills my terminal, shortcuts are shown below, I can scroll through, and the links work! There is only one font size though, but the colors + indentation + alignment make up for that.

    Installation:

    sudo apt-get install pandoc lynx
    
    0 讨论(0)
提交回复
热议问题