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条回答
smile是对你的礼貌
2楼-- · 2019-01-07 02:06

I recently made what you want, because I was in need to generate documentation from Markdown files and the GitHub style is pretty nice. Try it. It is written in Node.js.

gfm

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

This is mostly a follow-on to @barry-staes's answer for using Pandoc. Homebrew has it as well, if you're on a Mac:

brew install pandoc

Pandoc supports GFM as an input format via the markdown_github name.

Output to file

cat foo.md | pandoc -f markdown_github > foo.html

Open in Lynx

cat foo.md | pandoc -f markdown_github | lynx -stdin # To open in Lynx

Open in the default browser on OS X

cat foo.md | pandoc -f markdown_github > foo.html && open foo.html # To open in the default browser on OS X`

TextMate Integration

You can always pipe the current selection or current document to one of the above, as most editors allow you to do. You can also easily configure the environment so that pandoc replaces the default Markdown processor used by the Markdown bundle.

First, create a shell script with the following contents (I'll call it ghmarkdown):

#!/bin/bash
# Note included, optional --email-obfuscation arg
pandoc -f markdown_github --email-obfuscation=references

You can then set the TM_MARKDOWN variable (in Preferences→Variables) to /path/to/ghmarkdown, and it will replace the default Markdown processor.

查看更多
Anthone
4楼-- · 2019-01-07 02:07

My final solution was to use Python Markdown. I rolled my own extension that fixed the fence blocks.

查看更多
beautiful°
5楼-- · 2019-01-07 02:07

Late addition but showdownjs has a CLI tool you can use to parse MD to HTML.

查看更多
来,给爷笑一个
6楼-- · 2019-01-07 02:09

Maybe this might help:

gem install github-markdown

No documentation exists, but I got it from the gollum documentation. Looking at rubydoc.info, it looks like you can use:

require 'github/markdown'  
puts GitHub::Markdown.render_gfm('your markdown string')

in your Ruby code. You can wrap that easily in a script to turn it into a command line utility:

#!/usr/bin/env ruby

# render.rb
require 'github/markdown'

puts GitHub::Markdown.render_gfm File.read(ARGV[0])

Execute it with ./render.rb path/to/my/markdown/file.md. Note that this is not safe for use in production without sanitization.

查看更多
我想做一个坏孩纸
7楼-- · 2019-01-07 02:12

pandoc with browser works well for me.

Usage: cat README.md | pandoc -f markdown_github | browser

Installation (Assuming you are using Mac OSX):

  • $ brew install pandoc

  • $ brew install browser

Or on Debian/Ubuntu: apt-get install pandoc browser

查看更多
登录 后发表回答