github-markdown-preview 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 934cef69d969c91a47e1a83202610d45ae2b9eb5
4
- data.tar.gz: e428f16a7f79b7e75d0c660b97176be16d8cf223
3
+ metadata.gz: 8bed903b1a1fd75cbd36702278337c725310bb14
4
+ data.tar.gz: b2ec291a7ecc75481648c09128a7ab0dc11ff86f
5
5
  SHA512:
6
- metadata.gz: ffdacce3bc2c2e0ece0bc594884e17fd8fb6d4eb364ee25df2028a288062a555f0774ce8644455f4311795b4b12d485639f7e9ca03abc0adbe64b9ea755a4b1c
7
- data.tar.gz: 7819d7183b111e3e5f3567bf23bb14018d50c5a1a4d7b71dcd4c07664f2abf62475b730b6fef36e3a0cf6be36e75ca073608f09b2025e1099e65a2137b6b8779
6
+ metadata.gz: e768067cde5cd2cbac67d5202133e7d88a48db4661ecab1987f96761a1c4f0d068330d5d95a75728920fc860bc58fc2546976e68ed1c5567a14b167dfa446f34
7
+ data.tar.gz: 50a50c99c7bdd26bf35f41bba912e4bf907c2f58cf72ce827578d0a8137af409c1690cdedcd22522b273caa4e1559b50eaf7e03c40e38954513224663ed85331
data/.travis.yml CHANGED
@@ -3,6 +3,7 @@ rvm:
3
3
  - "1.8.7"
4
4
  - "1.9.3"
5
5
  - "2.0.0"
6
+ - "2.1.0"
6
7
  env:
7
8
  - INCLUDE_LINGUIST=true
8
9
  - INCLUDE_LINGUIST=false
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## v2.1.0
4
+ * Add option `:preview_file` for specifying a custom preview file
5
+ * Refactor so the filters and context used to configure html-pipeline can be easily overriden/monkey-patched
6
+
3
7
  ## v2.0.0
4
8
  * Add the ability to render a [preview of how Github renders comments/issues](https://github.com/dmarcotte/github-markdown-preview#comment-mode)
5
9
  * Make the `github-linguist` dependency [optional](https://github.com/dmarcotte/github-markdown-preview/pull/14)
@@ -22,42 +22,22 @@ module GithubMarkdownPreview
22
22
  raise FileNotFoundError.new("Cannot find source file: #{source_file}")
23
23
  end
24
24
 
25
+ @source_file = Pathname.new(source_file).realpath.to_s
26
+
25
27
  options = {
26
28
  :delete_on_exit => false,
27
- :comment_mode => false
29
+ :comment_mode => false,
30
+ :preview_file => @source_file + '.html'
28
31
  }.merge(options)
29
32
 
30
- @source_file = Pathname.new(source_file).realpath.to_s
31
-
32
- @preview_file = @source_file + '.html'
33
+ @preview_file = options[:preview_file]
33
34
  @preview_width = options[:comment_mode] ? 712 : 722
34
35
 
35
36
  @update_callbacks = []
36
37
 
37
- @pipeline_context = {
38
- :asset_root => "https://a248.e.akamai.net/assets.github.com/images/icons/",
39
- :base_url => "https://github.com/",
40
- :gfm => options[:comment_mode]
41
- }
42
-
43
- filters = [
44
- HTML::Pipeline::MarkdownFilter,
45
- HTML::Pipeline::SanitizationFilter,
46
- HTML::Pipeline::ImageMaxWidthFilter,
47
- HTML::Pipeline::HttpsFilter,
48
- HTML::Pipeline::EmojiFilter
49
- ]
50
-
51
- if HtmlPreview::SYNTAX_HIGHLIGHTS
52
- filters << HTML::Pipeline::SyntaxHighlightFilter
53
- end
38
+ @pipeline_context = pipeline_context(options)
54
39
 
55
- if options[:comment_mode]
56
- filters << HTML::Pipeline::MentionFilter
57
- filters << GithubMarkdownPreview::Pipeline::TaskListFilter
58
- end
59
-
60
- @preview_pipeline = HTML::Pipeline.new filters
40
+ @preview_pipeline = HTML::Pipeline.new pipeline_filters(options)
61
41
 
62
42
  # generate initial preview
63
43
  update
@@ -83,6 +63,39 @@ module GithubMarkdownPreview
83
63
  end
84
64
  end
85
65
 
66
+ ##
67
+ # Compute the context to pass to html-pipeline based on the given options
68
+ def pipeline_context(options)
69
+ {
70
+ :asset_root => "https://a248.e.akamai.net/assets.github.com/images/icons/",
71
+ :base_url => "https://github.com/",
72
+ :gfm => options[:comment_mode]
73
+ }
74
+ end
75
+
76
+ ##
77
+ # Compute the filters to use in the html-pipeline based on the given options
78
+ def pipeline_filters(options)
79
+ filters = [
80
+ HTML::Pipeline::MarkdownFilter,
81
+ HTML::Pipeline::SanitizationFilter,
82
+ HTML::Pipeline::ImageMaxWidthFilter,
83
+ HTML::Pipeline::HttpsFilter,
84
+ HTML::Pipeline::EmojiFilter
85
+ ]
86
+
87
+ if HtmlPreview::SYNTAX_HIGHLIGHTS
88
+ filters << HTML::Pipeline::SyntaxHighlightFilter
89
+ end
90
+
91
+ if options[:comment_mode]
92
+ filters << HTML::Pipeline::MentionFilter
93
+ filters << GithubMarkdownPreview::Pipeline::TaskListFilter
94
+ end
95
+
96
+ filters
97
+ end
98
+
86
99
  ##
87
100
  # Update the preview file
88
101
  def update
@@ -1,3 +1,3 @@
1
1
  module GithubMarkdownPreview
2
- VERSION = '2.0.0'
2
+ VERSION = '2.1.0'
3
3
  end
data/readme.md CHANGED
@@ -54,7 +54,9 @@ preview = GithubMarkdownPreview::HtmlPreview.new('source_file.md')
54
54
  # you can also configure your preview with a couple of options
55
55
  preview = GithubMarkdownPreview::HtmlPreview.new('source_file.md', {
56
56
  :delete_on_exit => true, # delete the preview when the program exits
57
- :comment_mode => true # render using the rules for Github comments/issues
57
+ :comment_mode => true, # render using the rules for Github comments/issues
58
+ :preview_file => 'custom_preview_file.html' # write preview to the given filename,
59
+ # rather than the default 'source_file.md.html'
58
60
  })
59
61
 
60
62
  # access the preview information
@@ -223,4 +223,15 @@ class TestHtmlPreview < Minitest::Test
223
223
  end
224
224
  end
225
225
 
226
+ def test_custom_preview_file
227
+ write(@source_file_path, '## foo')
228
+ custom_preview = File.join(Dir.tmpdir, 'custom_preview.html')
229
+ markdown_preview = @ghp.new( @source_file_path, { :preview_file => custom_preview} )
230
+ assert_equal custom_preview,
231
+ markdown_preview.preview_file
232
+ assert_match /.*<h2>foo<\/h2>.*/,
233
+ read(markdown_preview.preview_file),
234
+ 'Should write to the custom preview file'
235
+ end
236
+
226
237
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github-markdown-preview
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Marcotte
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-31 00:00:00.000000000 Z
11
+ date: 2014-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: listen