Is there a command line utility for rendering GitH

2019-01-07 01:10发布

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 content. I've cloned the repository on my server and would then like to process it into regular HTML. It's important to me that what appears on GitHub is exactly how it should look for my website. I'd also really like to use the fenced blocks with ~~~, so I'd rather not use standard Markdown syntax only.

I've looked a bit into the JavaScript live preview thinking I could hook it into Node.js, but they say it is deprecated. I've looked at the redcarpet repository, but it doesn't look like it has a command line interface.

I rolled my own solution, however, since no solution here is clearly better than the others, I'll leave the question without a selected answer.

25条回答
Anthone
2楼-- · 2019-01-07 01:53

GitHub has a Markdown API you can use.

查看更多
走好不送
3楼-- · 2019-01-07 01:53

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>
查看更多
Root(大扎)
4楼-- · 2019-01-07 01:56

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 $@
查看更多
倾城 Initia
5楼-- · 2019-01-07 01:57
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.

查看更多
我只想做你的唯一
6楼-- · 2019-01-07 02:00

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
查看更多
劳资没心,怎么记你
7楼-- · 2019-01-07 02:01

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

查看更多
登录 后发表回答