Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 663
McLeopold Avatar asked Oct 08 '11 04:10

McLeopold


People also ask

How does GitHub render Markdown?

GitHub uses its own Markdown processor; GitHub Pages uses jekyll-commonmark. This means your README.md file will look different on GitHub's website than on your GitHub Pages website. For example, emoji are rendered on GitHub's website, but not on websites generated using GitHub Pages.

What GitHub Flavored Markdown is and how it is used?

GitHub Flavored Markdown, often shortened as GFM, is the dialect of Markdown that is currently supported for user content on GitHub.com and GitHub Enterprise. This formal specification, based on the CommonMark Spec, defines the syntax and semantics of this dialect. GFM is a strict superset of CommonMark.

What is render Markdown?

renderMarkdown transforms the markdown text provided by the user in either the file or text variable. The transformation is either written to the output file or returned to the user. The default rendering target is "HTML".

How do I convert Markdown to HTML?

To convert Markdown to HTML using Typora, click File —> Export —> HTML. Then save the file in your preferred location. The image below shows that the HTML output looks exactly as how the Markdown is displayed inside Typora.


2 Answers

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.

like image 122
Joe Avatar answered Sep 22 '22 17:09

Joe


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 $@ 
like image 38
Alister Bulman Avatar answered Sep 23 '22 17:09

Alister Bulman