devcenter-parser 1.3.2 → 1.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/devcenter-parser.rb +19 -2
- data/test/devcenter-parser_test.rb +94 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00864c53d10600e6cccd5e25c00d06f137f64f7e
|
4
|
+
data.tar.gz: 84f810e795e30e8da6f0a9ac870caf3120b20ef7
|
5
5
|
!binary "U0hBNTEy":
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b7343fe802c7a3940b47b8c8ab8651dc694d65db9ecb5eeafe47e862c9707a71415c6a35839dff891f39ca80ef60a0ba68bd69337539d69849013cf53d50beb
|
7
|
+
data.tar.gz: fffb99dddf5e8cb7102a7129d8ee0022e04d6547e419baf8149fb47af5a73b1145d63fe16585d5e8580117a77a7e1840049d69a21459acae5947a873f69bb205
|
data/lib/devcenter-parser.rb
CHANGED
@@ -6,7 +6,7 @@ require 'sanitize'
|
|
6
6
|
|
7
7
|
module DevcenterParser
|
8
8
|
|
9
|
-
VERSION = '1.3.
|
9
|
+
VERSION = '1.3.4'
|
10
10
|
|
11
11
|
AVAILABLE_FLAVOURS = [:github, :maruku]
|
12
12
|
|
@@ -23,7 +23,24 @@ module DevcenterParser
|
|
23
23
|
sanitize(html)
|
24
24
|
end
|
25
25
|
|
26
|
+
# The current parsers consider something like:
|
27
|
+
# > foo
|
28
|
+
#
|
29
|
+
# > bar
|
30
|
+
# as a single blockquote, while we want it to be two different ones.
|
31
|
+
# This method adds an empty paragraph between consecutive blocks so parsers process them separately
|
32
|
+
def self.separate_consecutive_blockquote_blocks(markdown)
|
33
|
+
separator = '<p class="devcenter-parser-special-block-separator" style="display:none"> </p>'
|
34
|
+
markdown.gsub(/^>(.*)?\s\s>/, '>\1' + "\n\n#{separator}\n\n>")
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.normalize_newlines(markdown)
|
38
|
+
markdown.lines.map{ |l| l.chomp }.join("\n")
|
39
|
+
end
|
40
|
+
|
26
41
|
def self.to_unsanitized_html(markdown, flavour)
|
42
|
+
markdown = normalize_newlines(markdown)
|
43
|
+
markdown = separate_consecutive_blockquote_blocks(markdown)
|
27
44
|
doc = case flavour.to_sym
|
28
45
|
when :maruku
|
29
46
|
html = Maruku.new(markdown, :on_error => :raise).to_html
|
@@ -55,7 +72,7 @@ module DevcenterParser
|
|
55
72
|
private
|
56
73
|
|
57
74
|
def self.github_parser
|
58
|
-
@@github_parser ||= Redcarpet::Markdown.new(HTMLWithPantsRenderer, fenced_code_blocks: true)
|
75
|
+
@@github_parser ||= Redcarpet::Markdown.new(HTMLWithPantsRenderer, fenced_code_blocks: true, tables: true)
|
59
76
|
end
|
60
77
|
|
61
78
|
def self.sanitize_config
|
@@ -193,9 +193,13 @@ And that's it.
|
|
193
193
|
|
194
194
|
<div class="callout">
|
195
195
|
<p><strong>strong</strong></p>
|
196
|
+
</div>
|
197
|
+
|
198
|
+
<p class="devcenter-parser-special-block-separator" style="display:none"> </p>
|
196
199
|
|
200
|
+
<blockquote>
|
197
201
|
<p>normal</p>
|
198
|
-
</
|
202
|
+
</blockquote>
|
199
203
|
|
200
204
|
<p>And that’s it.</p>
|
201
205
|
HTML
|
@@ -206,6 +210,60 @@ And that's it.
|
|
206
210
|
end
|
207
211
|
end
|
208
212
|
|
213
|
+
it 'github markdown generates separate special blocks from blockquotes separated by empty lines' do
|
214
|
+
md = <<-MARKDOWN
|
215
|
+
> warning
|
216
|
+
> foo
|
217
|
+
|
218
|
+
> note
|
219
|
+
> bar
|
220
|
+
MARKDOWN
|
221
|
+
|
222
|
+
html = <<-HTML
|
223
|
+
<div class="warning">
|
224
|
+
<p>foo</p>
|
225
|
+
</div>
|
226
|
+
|
227
|
+
<p class="devcenter-parser-special-block-separator" style="display:none"> </p>
|
228
|
+
|
229
|
+
<div class="note">
|
230
|
+
<p>bar</p>
|
231
|
+
</div>
|
232
|
+
HTML
|
233
|
+
|
234
|
+
assert_github_result md, html
|
235
|
+
end
|
236
|
+
|
237
|
+
it 'github markdown supports tables' do
|
238
|
+
md = <<-MARKDOWN
|
239
|
+
| A | B |
|
240
|
+
| --- | --- |
|
241
|
+
| 1 | 2 |
|
242
|
+
| 3 | 4 |
|
243
|
+
MARKDOWN
|
244
|
+
|
245
|
+
html = <<-HTML
|
246
|
+
<table>
|
247
|
+
<thead><tr>
|
248
|
+
<th>A</th>
|
249
|
+
<th>B</th>
|
250
|
+
</tr></thead>
|
251
|
+
<tbody>
|
252
|
+
<tr>
|
253
|
+
<td>1</td>
|
254
|
+
<td>2</td>
|
255
|
+
</tr>
|
256
|
+
<tr>
|
257
|
+
<td>3</td>
|
258
|
+
<td>4</td>
|
259
|
+
</tr>
|
260
|
+
</tbody>
|
261
|
+
</table>
|
262
|
+
HTML
|
263
|
+
|
264
|
+
assert_github_result md, html
|
265
|
+
end
|
266
|
+
|
209
267
|
it "does emdashes both in all flavours" do
|
210
268
|
md = "foo -- bar"
|
211
269
|
html = '<p>foo – bar</p>'
|
@@ -236,6 +294,41 @@ And that's it.
|
|
236
294
|
assert_github_result md, "<p>#{md}</p>"
|
237
295
|
end
|
238
296
|
|
297
|
+
|
298
|
+
it 'generates separate blockquotes from blockquotes separated by empty lines' do
|
299
|
+
md = <<-MARKDOWN
|
300
|
+
> foo
|
301
|
+
|
302
|
+
> bar
|
303
|
+
MARKDOWN
|
304
|
+
|
305
|
+
html_maruku = <<-HTML
|
306
|
+
<blockquote>
|
307
|
+
<p>foo</p>
|
308
|
+
</blockquote>
|
309
|
+
<p class="devcenter-parser-special-block-separator" style="display:none"> </p>
|
310
|
+
<blockquote>
|
311
|
+
<p>bar</p>
|
312
|
+
</blockquote>
|
313
|
+
HTML
|
314
|
+
|
315
|
+
assert_maruku_result md, html_maruku
|
316
|
+
|
317
|
+
html_github = <<-HTML
|
318
|
+
<blockquote>
|
319
|
+
<p>foo</p>
|
320
|
+
</blockquote>
|
321
|
+
|
322
|
+
<p class="devcenter-parser-special-block-separator" style="display:none"> </p>
|
323
|
+
|
324
|
+
<blockquote>
|
325
|
+
<p>bar</p>
|
326
|
+
</blockquote>
|
327
|
+
HTML
|
328
|
+
|
329
|
+
assert_github_result md, html_github
|
330
|
+
end
|
331
|
+
|
239
332
|
end
|
240
333
|
|
241
334
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devcenter-parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Heroku
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: maruku
|
@@ -112,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
112
|
version: '0'
|
113
113
|
requirements: []
|
114
114
|
rubyforge_project:
|
115
|
-
rubygems_version: 2.0.
|
115
|
+
rubygems_version: 2.0.3
|
116
116
|
signing_key:
|
117
117
|
specification_version: 4
|
118
118
|
summary: Parser for Heroku Dev Center's content
|