github-markdown-preview 2.0.0 → 2.1.0
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.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +4 -0
- data/lib/github-markdown-preview/html_preview.rb +40 -27
- data/lib/github-markdown-preview/version.rb +1 -1
- data/readme.md +3 -1
- data/test/html_preview_test.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8bed903b1a1fd75cbd36702278337c725310bb14
|
4
|
+
data.tar.gz: b2ec291a7ecc75481648c09128a7ab0dc11ff86f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e768067cde5cd2cbac67d5202133e7d88a48db4661ecab1987f96761a1c4f0d068330d5d95a75728920fc860bc58fc2546976e68ed1c5567a14b167dfa446f34
|
7
|
+
data.tar.gz: 50a50c99c7bdd26bf35f41bba912e4bf907c2f58cf72ce827578d0a8137af409c1690cdedcd22522b273caa4e1559b50eaf7e03c40e38954513224663ed85331
|
data/.travis.yml
CHANGED
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
|
-
@
|
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
|
-
|
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
|
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
|
data/test/html_preview_test.rb
CHANGED
@@ -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.
|
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:
|
11
|
+
date: 2014-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: listen
|