ghpreview 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +22 -9
- data/ghpreview.gemspec +1 -0
- data/lib/ghpreview/previewer.rb +21 -9
- data/lib/ghpreview/version.rb +1 -1
- metadata +18 -2
data/README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# ghpreview
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
When you're writing a README for your project, you want a way to preview the
|
4
|
+
Markdown locally before you push it. `ghpreview` is a command-line utility that
|
5
|
+
opens your Markdown file in a browser. It uses Github styling and (optionally)
|
6
|
+
automatically refreshes every time you save your source.
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
source.
|
8
|
+
While README files are the most common use case, `ghpreview` works with any
|
9
|
+
Markdown file.
|
10
10
|
|
11
11
|
## Installation
|
12
12
|
|
@@ -16,19 +16,32 @@ $ gem install ghpreview
|
|
16
16
|
|
17
17
|
## Usage
|
18
18
|
|
19
|
-
`ghpreview` is a command-line utility.
|
20
|
-
|
21
19
|
```bash
|
22
20
|
$ ghpreview README.md
|
23
21
|
```
|
24
22
|
|
25
23
|
This will open your default browser with a preview of README.md exactly as it
|
26
|
-
will appear on Github. For a live-updating preview, use the
|
24
|
+
will appear on Github. For a live-updating preview, use the `-w` (or `--watch`)
|
25
|
+
option:
|
27
26
|
|
28
27
|
```bash
|
29
28
|
$ ghpreview -w README.md
|
30
29
|
```
|
31
30
|
|
31
|
+
## Why is this better than X?
|
32
|
+
|
33
|
+
There are several tools available for previewing Markdown files, and many that
|
34
|
+
provide a Github-like style. I've personally used
|
35
|
+
[Marked](http://markedapp.com), [Mou](http://mouapp.com), and the
|
36
|
+
[vim-markdown](https://github.com/maba/vim-markdown-preview) plugin. All are
|
37
|
+
good tools, but none are able to truly reproduce the custom features added to
|
38
|
+
[Github Flavored Markdown](http://github.github.com/github-flavored-markdown/).
|
39
|
+
This is especially notable with fenced code blocks and syntax highlighting.
|
40
|
+
|
41
|
+
`ghpreview` is an accurate preview because it uses Github's own [HTML
|
42
|
+
processing filters](https://github.com/jch/html-pipeline) to generate the HTML,
|
43
|
+
and Github's own stylesheets to style it.
|
44
|
+
|
32
45
|
## Contributing
|
33
46
|
|
34
47
|
1. Fork it
|
data/ghpreview.gemspec
CHANGED
data/lib/ghpreview/previewer.rb
CHANGED
@@ -1,19 +1,18 @@
|
|
1
1
|
require 'erb'
|
2
|
-
require '
|
2
|
+
require 'html/pipeline'
|
3
3
|
require 'listen'
|
4
|
+
require 'httpclient'
|
4
5
|
|
5
6
|
module GHPreview
|
6
7
|
class Previewer
|
7
|
-
API_URI = 'https://api.github.com/markdown/raw'
|
8
|
-
HOMEPAGE = 'https://github.com'
|
9
8
|
HTML_FILEPATH = '/tmp/ghpreview.html'
|
10
9
|
RAW_TEMPLATE_FILEPATH = "#{File.dirname(__FILE__)}/template.erb"
|
11
10
|
STYLED_TEMPLATE_FILEPATH = "/tmp/ghpreview-template.erb"
|
11
|
+
HOMEPAGE = 'https://github.com'
|
12
|
+
TEMPLATE_CACHE_DURATION = 60 * 60 * 24 * 7 # one week
|
12
13
|
|
13
14
|
def initialize(md_filepath, options = {})
|
14
15
|
@md_filepath = md_filepath
|
15
|
-
@md_filename = md_filepath.split('/').last
|
16
|
-
@md_filedir = md_filepath.split('/').unshift('.').uniq[0..-2].join('/')
|
17
16
|
@http = HTTPClient.new
|
18
17
|
generate_template_with_fingerprinted_stylesheet_links
|
19
18
|
|
@@ -23,7 +22,11 @@ module GHPreview
|
|
23
22
|
def listen
|
24
23
|
puts "Previewing #{@md_filepath}. CTRL-C to stop."
|
25
24
|
open
|
26
|
-
|
25
|
+
|
26
|
+
filename = File.basename(@md_filepath)
|
27
|
+
dirname = File.dirname(File.expand_path(@md_filepath))
|
28
|
+
|
29
|
+
Listen.to(dirname, filter: /#{filename}$/) do |modified|
|
27
30
|
open
|
28
31
|
end
|
29
32
|
end
|
@@ -44,8 +47,17 @@ module GHPreview
|
|
44
47
|
|
45
48
|
def markdown_to_html
|
46
49
|
markdown = File.read(@md_filepath)
|
47
|
-
|
48
|
-
|
50
|
+
pipeline = HTML::Pipeline.new([
|
51
|
+
HTML::Pipeline::MarkdownFilter,
|
52
|
+
HTML::Pipeline::SanitizationFilter,
|
53
|
+
HTML::Pipeline::CamoFilter,
|
54
|
+
HTML::Pipeline::ImageMaxWidthFilter,
|
55
|
+
HTML::Pipeline::HttpsFilter,
|
56
|
+
HTML::Pipeline::MentionFilter,
|
57
|
+
HTML::Pipeline::EmojiFilter,
|
58
|
+
HTML::Pipeline::SyntaxHighlightFilter
|
59
|
+
], gfm: false)
|
60
|
+
result = pipeline.call(markdown)[:output].to_s
|
49
61
|
end
|
50
62
|
|
51
63
|
def generate_template_with_fingerprinted_stylesheet_links
|
@@ -62,7 +74,7 @@ module GHPreview
|
|
62
74
|
|
63
75
|
def stale_template?(filepath)
|
64
76
|
return true unless File.exists?(filepath)
|
65
|
-
File.mtime(filepath) < (Time.now -
|
77
|
+
File.mtime(filepath) < (Time.now - TEMPLATE_CACHE_DURATION)
|
66
78
|
end
|
67
79
|
|
68
80
|
def wrap_content_with_full_document(content)
|
data/lib/ghpreview/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ghpreview
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: listen
|
@@ -43,6 +43,22 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: html-pipeline
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
46
62
|
- !ruby/object:Gem::Dependency
|
47
63
|
name: httpclient
|
48
64
|
requirement: !ruby/object:Gem::Requirement
|