Last active
December 14, 2015 13:49
-
-
Save indirect/5096633 to your computer and use it in GitHub Desktop.
html-pipeline executable for Github markdown previews
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
ARGV.each do |path| | |
abort "#{path} doesn't exist!" unless File.exist?(path) | |
end | |
require 'html/pipeline' | |
filters = [ | |
HTML::Pipeline::MarkdownFilter, | |
HTML::Pipeline::SanitizationFilter, | |
HTML::Pipeline::ImageMaxWidthFilter, | |
HTML::Pipeline::EmojiFilter, | |
HTML::Pipeline::AutolinkFilter, | |
HTML::Pipeline::TableOfContentsFilter, | |
] | |
begin | |
require 'linguist' | |
filters << HTML::Pipeline::SyntaxHighlightFilter | |
rescue LoadError => e | |
end | |
context = { | |
:asset_root => "/assets", | |
:base_url => "/", | |
:gfm => true | |
} | |
# GitHub-style pipeline | |
puts HTML::Pipeline.new(filters, context).call(ARGF.read)[:output] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment