html-pipeline 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/lib/html/pipeline/syntax_highlight_filter.rb +8 -3
- data/lib/html/pipeline/version.rb +1 -1
- data/test/html/pipeline/syntax_highlight_filter_test.rb +22 -0
- metadata +165 -114
- checksums.yaml +0 -7
data/CHANGELOG.md
CHANGED
@@ -11,14 +11,19 @@ module HTML
|
|
11
11
|
class SyntaxHighlightFilter < Filter
|
12
12
|
def call
|
13
13
|
doc.search('pre').each do |node|
|
14
|
-
|
14
|
+
default = context[:highlight] && context[:highlight].to_s
|
15
|
+
next unless lang = node['lang'] || default
|
15
16
|
next unless lexer = Pygments::Lexer[lang]
|
16
17
|
text = node.inner_text
|
17
18
|
|
18
19
|
html = highlight_with_timeout_handling(lexer, text)
|
19
20
|
next if html.nil?
|
20
21
|
|
21
|
-
node.replace(html)
|
22
|
+
node = node.replace(html).first
|
23
|
+
klass = node["class"]
|
24
|
+
klass = [klass, "highlight-#{lang}"].compact.join " "
|
25
|
+
|
26
|
+
node["class"] = klass
|
22
27
|
end
|
23
28
|
doc
|
24
29
|
end
|
@@ -30,4 +35,4 @@ module HTML
|
|
30
35
|
end
|
31
36
|
end
|
32
37
|
end
|
33
|
-
end
|
38
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
SyntaxHighlightFilter = HTML::Pipeline::SyntaxHighlightFilter
|
4
|
+
|
5
|
+
class HTML::Pipeline::SyntaxHighlightFilterTest < Test::Unit::TestCase
|
6
|
+
def test_highlight_default
|
7
|
+
filter = SyntaxHighlightFilter.new \
|
8
|
+
"<pre>hello</pre>", :highlight => "coffeescript"
|
9
|
+
|
10
|
+
doc = filter.call
|
11
|
+
assert !doc.css(".highlight-coffeescript").empty?
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_highlight_default_will_not_override
|
15
|
+
filter = SyntaxHighlightFilter.new \
|
16
|
+
"<pre lang='c'>hello</pre>", :highlight => "coffeescript"
|
17
|
+
|
18
|
+
doc = filter.call
|
19
|
+
assert doc.css(".highlight-coffeescript").empty?
|
20
|
+
assert !doc.css(".highlight-c").empty?
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,136 +1,175 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: html-pipeline
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 19
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
5
11
|
platform: ruby
|
6
|
-
authors:
|
12
|
+
authors:
|
7
13
|
- Ryan Tomayko
|
8
14
|
- Jerry Cheung
|
9
15
|
autorequire:
|
10
16
|
bindir: bin
|
11
17
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
+
|
19
|
+
date: 2013-08-31 00:00:00 -07:00
|
20
|
+
default_executable:
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
18
26
|
- - ~>
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 15
|
29
|
+
segments:
|
30
|
+
- 1
|
31
|
+
- 0
|
32
|
+
version: "1.0"
|
21
33
|
type: :runtime
|
34
|
+
name: gemoji
|
35
|
+
version_requirements: *id001
|
22
36
|
prerelease: false
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
- !ruby/object:Gem::
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 7
|
44
|
+
segments:
|
45
|
+
- 1
|
46
|
+
- 4
|
47
|
+
version: "1.4"
|
48
|
+
- - <
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
hash: 3
|
51
|
+
segments:
|
52
|
+
- 1
|
53
|
+
- 6
|
54
|
+
version: "1.6"
|
35
55
|
type: :runtime
|
56
|
+
name: nokogiri
|
57
|
+
version_requirements: *id002
|
36
58
|
prerelease: false
|
37
|
-
|
38
|
-
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
39
63
|
- - ~>
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
- - ~>
|
47
|
-
- !ruby/object:Gem::Version
|
48
|
-
version: '0.5'
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
hash: 1
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
- 5
|
69
|
+
version: "0.5"
|
49
70
|
type: :runtime
|
71
|
+
name: github-markdown
|
72
|
+
version_requirements: *id003
|
50
73
|
prerelease: false
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
- !ruby/object:Gem::
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
74
|
+
- !ruby/object:Gem::Dependency
|
75
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
hash: 7
|
81
|
+
segments:
|
82
|
+
- 2
|
83
|
+
version: "2"
|
84
|
+
- - <
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
hash: 7
|
87
|
+
segments:
|
88
|
+
- 2
|
89
|
+
- 0
|
90
|
+
- 4
|
91
|
+
version: 2.0.4
|
63
92
|
type: :runtime
|
93
|
+
name: sanitize
|
94
|
+
version_requirements: *id004
|
64
95
|
prerelease: false
|
65
|
-
|
66
|
-
|
96
|
+
- !ruby/object:Gem::Dependency
|
97
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
67
100
|
- - ~>
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
- - ~>
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: '1.7'
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
hash: 1
|
103
|
+
segments:
|
104
|
+
- 1
|
105
|
+
- 7
|
106
|
+
version: "1.7"
|
77
107
|
type: :runtime
|
108
|
+
name: rinku
|
109
|
+
version_requirements: *id005
|
78
110
|
prerelease: false
|
79
|
-
|
80
|
-
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
81
115
|
- - ~>
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
- - ~>
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
version: '0.3'
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
hash: 13
|
118
|
+
segments:
|
119
|
+
- 0
|
120
|
+
- 3
|
121
|
+
version: "0.3"
|
91
122
|
type: :runtime
|
123
|
+
name: escape_utils
|
124
|
+
version_requirements: *id006
|
92
125
|
prerelease: false
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
- !ruby/object:Gem::
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
hash: 7
|
133
|
+
segments:
|
134
|
+
- 2
|
135
|
+
version: "2"
|
136
|
+
- - <
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
hash: 11
|
139
|
+
segments:
|
140
|
+
- 4
|
141
|
+
version: "4"
|
105
142
|
type: :development
|
143
|
+
name: activesupport
|
144
|
+
version_requirements: *id007
|
106
145
|
prerelease: false
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
version: '2'
|
112
|
-
- !ruby/object:Gem::Dependency
|
113
|
-
name: github-linguist
|
114
|
-
requirement: !ruby/object:Gem::Requirement
|
115
|
-
requirements:
|
146
|
+
- !ruby/object:Gem::Dependency
|
147
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
148
|
+
none: false
|
149
|
+
requirements:
|
116
150
|
- - ~>
|
117
|
-
- !ruby/object:Gem::Version
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
hash: 19
|
153
|
+
segments:
|
154
|
+
- 2
|
155
|
+
- 6
|
156
|
+
- 2
|
118
157
|
version: 2.6.2
|
119
158
|
type: :development
|
159
|
+
name: github-linguist
|
160
|
+
version_requirements: *id008
|
120
161
|
prerelease: false
|
121
|
-
version_requirements: !ruby/object:Gem::Requirement
|
122
|
-
requirements:
|
123
|
-
- - ~>
|
124
|
-
- !ruby/object:Gem::Version
|
125
|
-
version: 2.6.2
|
126
162
|
description: GitHub HTML processing filters and utilities
|
127
|
-
email:
|
163
|
+
email:
|
128
164
|
- ryan@github.com
|
129
165
|
- jerry@github.com
|
130
166
|
executables: []
|
167
|
+
|
131
168
|
extensions: []
|
169
|
+
|
132
170
|
extra_rdoc_files: []
|
133
|
-
|
171
|
+
|
172
|
+
files:
|
134
173
|
- .gitignore
|
135
174
|
- .travis.yml
|
136
175
|
- CHANGELOG.md
|
@@ -169,34 +208,45 @@ files:
|
|
169
208
|
- test/html/pipeline/mention_filter_test.rb
|
170
209
|
- test/html/pipeline/plain_text_input_filter_test.rb
|
171
210
|
- test/html/pipeline/sanitization_filter_test.rb
|
211
|
+
- test/html/pipeline/syntax_highlight_filter_test.rb
|
172
212
|
- test/html/pipeline/toc_filter_test.rb
|
173
213
|
- test/html/pipeline_test.rb
|
174
214
|
- test/test_helper.rb
|
215
|
+
has_rdoc: true
|
175
216
|
homepage: https://github.com/jch/html-pipeline
|
176
|
-
licenses:
|
217
|
+
licenses:
|
177
218
|
- MIT
|
178
|
-
metadata: {}
|
179
219
|
post_install_message:
|
180
220
|
rdoc_options: []
|
181
|
-
|
221
|
+
|
222
|
+
require_paths:
|
182
223
|
- lib
|
183
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
224
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
225
|
+
none: false
|
226
|
+
requirements:
|
227
|
+
- - ">="
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
hash: 3
|
230
|
+
segments:
|
231
|
+
- 0
|
232
|
+
version: "0"
|
233
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
234
|
+
none: false
|
235
|
+
requirements:
|
236
|
+
- - ">="
|
237
|
+
- !ruby/object:Gem::Version
|
238
|
+
hash: 3
|
239
|
+
segments:
|
240
|
+
- 0
|
241
|
+
version: "0"
|
193
242
|
requirements: []
|
243
|
+
|
194
244
|
rubyforge_project:
|
195
|
-
rubygems_version:
|
245
|
+
rubygems_version: 1.6.2
|
196
246
|
signing_key:
|
197
|
-
specification_version:
|
247
|
+
specification_version: 3
|
198
248
|
summary: Helpers for processing content through a chain of filters
|
199
|
-
test_files:
|
249
|
+
test_files:
|
200
250
|
- test/helpers/mocked_instrumentation_service.rb
|
201
251
|
- test/html/pipeline/absolute_source_filter_test.rb
|
202
252
|
- test/html/pipeline/autolink_filter_test.rb
|
@@ -207,6 +257,7 @@ test_files:
|
|
207
257
|
- test/html/pipeline/mention_filter_test.rb
|
208
258
|
- test/html/pipeline/plain_text_input_filter_test.rb
|
209
259
|
- test/html/pipeline/sanitization_filter_test.rb
|
260
|
+
- test/html/pipeline/syntax_highlight_filter_test.rb
|
210
261
|
- test/html/pipeline/toc_filter_test.rb
|
211
262
|
- test/html/pipeline_test.rb
|
212
263
|
- test/test_helper.rb
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 6e0e0c6ee2235a1a4ce9821e0ad2ff41b4669b31
|
4
|
-
data.tar.gz: 93da7c411b1d922ac996dfccab1fdca4ce22b8cd
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 3cd39361db40f99caeaae06d9ba8a52efd9e71575d17d44c98d5b4b6a0e251da82096a6d758f524933614e414b15ccbeceb62ead54c5b0fdd9f0bcf58265e20d
|
7
|
-
data.tar.gz: 9d130010673d83a2cba28bc831b84505635377e291c3cd18642e6b6e910beb5b5db4afdf2d039e2cacb0867edaf1ba96627360f547d667420f1a7d16cd82be06
|