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

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

    Also see https://softwareengineering.stackexchange.com/a/128721/24257.


    If you're interested in how we [Github] render Markdown files, you might want to check out Redcarpet, our Ruby interface to the Sundown library.

    Ruby-script, which use Redcarpet, will be "command line utility", if you'll have local Ruby

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

    Improving upon @barry-stae and @Sandeep answers for regular users of elinks you would add the following to .bashrc:

    function mdviewer() {
      pandoc $* | elinks --force-html
    }
    

    Don't forget to install pandoc (and elinks).

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

    GitHub has a Markdown API you can use.

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

    Use marked. It supports GitHub Flavored Markdown, can be used as a Node.js module and from the command line.

    An example would be:

    $ marked -o hello.html
    hello world
    ^D
    $ cat hello.html
    <p>hello world</p>
    
    0 讨论(0)
  • 2020-11-28 17:44

    I managed to use a one-line Ruby script for that purpose (although it had to go in a separate file). First, run these commands once on each client machine you'll be pushing docs from:

    gem install github-markup
    gem install commonmarker
    

    Next, install this script in your client image, and call it render-readme-for-javadoc.rb:

    require 'github/markup'
    
    puts GitHub::Markup.render_s(GitHub::Markups::MARKUP_MARKDOWN, File.read('README.md'))
    

    Finally, invoke it like this:

    ruby ./render-readme-for-javadoc.rb >> project/src/main/javadoc/overview.html
    

    ETA: This won't help you with StackOverflow-flavor Markdown, which seems to be failing on this answer.

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

    I've not found a quick and easy method for GitHub-flavoured Markdown, but I have found a slightly more generic version - Pandoc. It converts from/to a number of formats, including Markdown, Rest, HTML and others.

    I've also developed a Makefile to convert all .md files to .html (in large part to the example at Writing, Markdown and Pandoc):

    # 'Makefile'
    MARKDOWN = pandoc --from gfm --to html --standalone
    all: $(patsubst %.md,%.html,$(wildcard *.md)) Makefile
    
    clean:
        rm -f $(patsubst %.md,%.html,$(wildcard *.md))
        rm -f *.bak *~
    
    %.html: %.md
        $(MARKDOWN) $< --output $@
    
    0 讨论(0)
提交回复
热议问题