Skip to content

Commit

Permalink
Merge pull request #3 from picandocodigo/html_pipeline
Browse files Browse the repository at this point in the history
Use Html pipeline locally instead of hitting the Github API
  • Loading branch information
adamlogic committed Nov 29, 2012
2 parents 5448266 + ce0414b commit ea7b6c2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -38,8 +38,8 @@ good tools, but none are able to truly reproduce the custom features added to
[Github Flavored Markdown](http://github.github.com/github-flavored-markdown/).
This is especially notable with fenced code blocks and syntax highlighting.

`ghpreview` is an accurate preview because it uses Github's own [Markdown
Rendering API](http://developer.github.com/v3/markdown/) to generate the HTML,
`ghpreview` is an accurate preview because it uses Github's own [HTML
processing filters](https://github.com/jch/html-pipeline) to generate the HTML,
and Github's own stylesheets to style it.

## Contributing
Expand Down
1 change: 1 addition & 0 deletions ghpreview.gemspec
Expand Up @@ -19,5 +19,6 @@ Gem::Specification.new do |gem|

gem.add_dependency 'listen'
gem.add_dependency 'rb-fsevent'
gem.add_dependency 'html-pipeline'
gem.add_dependency 'httpclient'
end
19 changes: 14 additions & 5 deletions lib/ghpreview/previewer.rb
@@ -1,14 +1,14 @@
require 'erb'
require 'httpclient'
require 'html/pipeline'
require 'listen'
require 'httpclient'

module GHPreview
class Previewer
API_URI = 'https://api.github.com/markdown/raw'
HOMEPAGE = 'https://github.com'
HTML_FILEPATH = '/tmp/ghpreview.html'
RAW_TEMPLATE_FILEPATH = "#{File.dirname(__FILE__)}/template.erb"
STYLED_TEMPLATE_FILEPATH = "/tmp/ghpreview-template.erb"
HOMEPAGE = 'https://github.com'

def initialize(md_filepath, options = {})
@md_filepath = md_filepath
Expand Down Expand Up @@ -46,8 +46,17 @@ def open

def markdown_to_html
markdown = File.read(@md_filepath)
message = @http.post API_URI, body: markdown, header: {'Content-Type' => 'text/plain'}
message.body
pipeline = HTML::Pipeline.new([
HTML::Pipeline::MarkdownFilter,
HTML::Pipeline::SanitizationFilter,
HTML::Pipeline::CamoFilter,
HTML::Pipeline::ImageMaxWidthFilter,
HTML::Pipeline::HttpsFilter,
HTML::Pipeline::MentionFilter,
HTML::Pipeline::EmojiFilter,
HTML::Pipeline::SyntaxHighlightFilter
], gfm: false)
result = pipeline.call(markdown)[:output].to_s
end

def generate_template_with_fingerprinted_stylesheet_links
Expand Down

0 comments on commit ea7b6c2

Please sign in to comment.