Local Github Markdown Preview
Use your favorite editor plus the usual edit/refresh cycle to quickly write and polish your markdown for Github.
This program marries html-pipeline with the Listen file watcher to provide a high-fidelity preview (in your local browser, automatically updating on edit) of how Github will render your markdown.
Installation
gem install github-markdown-preview
Usage
Generate a preview of how Github renders markdown files in a repository:
$ github-markdown-preview <path/to/markdown/file.md>
- The
.html
preview is written beside your .md
file so that you can validate relative links locally - The
.html
preview is deleted when the script exits
Use the -c
switch to generate a preview of how Github renders comments/issues, which differs from repository markdown files in a few ways:
- newlines are rendered as hard breaks
@mentions
are linked to the user's home page- Note: auto-linked references are not rendered as links. See #17
$ github-markdown-preview -c <path/to/comment/draft.md>
Enable syntax highlighting for code blocks
To enable syntax highlighting for code blocks, you will need to install github-linguist
:
gem install github-linguist -v 3.3.1
gem install rugged -v 0.23.0
Note that this install will fail unless your system meets the requirements needed to build its native extensions:
- You will to either
brew install icu4c
or apt-get install libicu-dev
- On Mac, you will need to have XCode installed (seems like a full install is required, not just the Command Line Tools)
Code
Here's a sample file demonstrating how to call github-markdown-preview
from your own code:
require 'github-markdown-preview'
preview = GithubMarkdownPreview::HtmlPreview.new('source_file.md')
preview = GithubMarkdownPreview::HtmlPreview.new('source_file.md', {
:delete_on_exit => true,
:comment_mode => true,
:preview_file => 'custom_preview_file.html'
})
preview.source_file
preview.preview_file
preview.update
preview.watch
preview.watch!
preview.update { puts 'Preview updated!' }
preview.end_watch
preview.delete
Development
$ bundle install
$ rake test
Alternatively, to test with optional dependencies
$ BUNDLE_GEMFILE=Gemfile.optional bundle install
$ BUNDLE_GEMFILE=Gemfile.optional rake test
To run your development copy of the main script without installing it
$ bundle exec bin/github-markdown-preview
To install the your development copy to your system
$ rake install
Contributing
Contributions welcome!