devcenter-parser 2.2.3 → 2.2.9
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 +5 -5
- data/Gemfile.lock +15 -10
- data/devcenter-parser.gemspec +2 -2
- data/lib/devcenter-parser.rb +17 -11
- data/lib/devcenter-parser/version.rb +1 -1
- data/test/devcenter-parser_test.rb +21 -5
- metadata +12 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4517ced26a3c0b03ada92affbbaafb25545d0f9bd05ae347a6da9c7567c5b858
|
4
|
+
data.tar.gz: '05685be056b302fb593c431dc2db6247404f607c382d7e3784cd0cfd267826be'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73e20f5674e995e617b74cf6192032d0ee1d80db4bfdd13246c15b872def1cfb09e27c875cd77ea2ff8d795b1f93787c1d48f0fa7d5ce577e055b9709572af07
|
7
|
+
data.tar.gz: 69b95cdbd69ff72cb8afaa940b5479730ed2e3781ceccfd22570e1093ba25c8a4c9ab198cb031e2983143016b70b047dc161c6cf4c100f7fa66617e7cb46ea47
|
data/Gemfile.lock
CHANGED
@@ -1,22 +1,27 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
devcenter-parser (2.2.
|
4
|
+
devcenter-parser (2.2.8)
|
5
5
|
nokogiri (>= 1.7.1)
|
6
|
-
redcarpet (= 3.
|
7
|
-
sanitize (
|
6
|
+
redcarpet (= 3.5.0)
|
7
|
+
sanitize (~> 5.2.1)
|
8
8
|
|
9
9
|
GEM
|
10
10
|
remote: http://rubygems.org/
|
11
11
|
specs:
|
12
|
-
|
12
|
+
crass (1.0.6)
|
13
|
+
mini_portile2 (2.4.0)
|
13
14
|
minitest (5.10.1)
|
14
|
-
nokogiri (1.
|
15
|
-
mini_portile2 (~> 2.
|
15
|
+
nokogiri (1.10.10)
|
16
|
+
mini_portile2 (~> 2.4.0)
|
17
|
+
nokogumbo (2.0.2)
|
18
|
+
nokogiri (~> 1.8, >= 1.8.4)
|
16
19
|
rake (12.0.0)
|
17
|
-
redcarpet (3.
|
18
|
-
sanitize (2.
|
19
|
-
|
20
|
+
redcarpet (3.5.0)
|
21
|
+
sanitize (5.2.1)
|
22
|
+
crass (~> 1.0.2)
|
23
|
+
nokogiri (>= 1.8.0)
|
24
|
+
nokogumbo (~> 2.0)
|
20
25
|
|
21
26
|
PLATFORMS
|
22
27
|
ruby
|
@@ -27,4 +32,4 @@ DEPENDENCIES
|
|
27
32
|
rake
|
28
33
|
|
29
34
|
BUNDLED WITH
|
30
|
-
1.
|
35
|
+
1.17.2
|
data/devcenter-parser.gemspec
CHANGED
@@ -15,8 +15,8 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.require_paths = %w{ lib }
|
16
16
|
|
17
17
|
gem.add_runtime_dependency 'nokogiri', '>= 1.7.1'
|
18
|
-
gem.add_runtime_dependency 'redcarpet', '3.
|
19
|
-
gem.add_runtime_dependency 'sanitize', '2.
|
18
|
+
gem.add_runtime_dependency 'redcarpet', '3.5.0'
|
19
|
+
gem.add_runtime_dependency 'sanitize', '~>5.2.1'
|
20
20
|
|
21
21
|
gem.add_development_dependency 'minitest', '>2.0'
|
22
22
|
gem.add_development_dependency 'rake'
|
data/lib/devcenter-parser.rb
CHANGED
@@ -10,14 +10,14 @@ module DevcenterParser
|
|
10
10
|
class InvalidMarkdownError < Exception; end
|
11
11
|
class InvalidRawHTMLError < Exception; end
|
12
12
|
|
13
|
-
def self.to_html(markdown)
|
14
|
-
sanitize to_unsanitized_html(markdown)
|
13
|
+
def self.to_html(markdown, options = {})
|
14
|
+
sanitize to_unsanitized_html(markdown, options)
|
15
15
|
end
|
16
16
|
|
17
|
-
def self.to_unsanitized_html(markdown)
|
17
|
+
def self.to_unsanitized_html(markdown, options = {})
|
18
18
|
markdown = normalize_markdown(markdown)
|
19
19
|
doc = GitHubParser.parse(markdown)
|
20
|
-
doc_to_html(doc)
|
20
|
+
doc_to_html(doc, options)
|
21
21
|
rescue InvalidRawHTMLError => e
|
22
22
|
raise InvalidMarkdownError, e.message
|
23
23
|
end
|
@@ -28,9 +28,9 @@ module DevcenterParser
|
|
28
28
|
|
29
29
|
private
|
30
30
|
|
31
|
-
def self.doc_to_html(doc)
|
31
|
+
def self.doc_to_html(doc, options = {})
|
32
32
|
HeaderIdGenerator.apply!(doc)
|
33
|
-
convert_to_article_links_all_relative_links_with_missing_initial_slashes(doc)
|
33
|
+
convert_to_article_links_all_relative_links_with_missing_initial_slashes(doc, options)
|
34
34
|
html = doc.to_html(:encoding => 'utf-8')
|
35
35
|
verify_raw_html(html)
|
36
36
|
html
|
@@ -69,7 +69,8 @@ module DevcenterParser
|
|
69
69
|
# Note that Sanitize requires all the elements/attributes downcased
|
70
70
|
def self.sanitize_config
|
71
71
|
return @@sanitize_config if defined?(@@sanitize_config)
|
72
|
-
|
72
|
+
frozen_config = Sanitize::Config::RELAXED
|
73
|
+
config = Marshal.load(Marshal.dump(frozen_config))
|
73
74
|
config[:attributes][:all] += %w{ id class style name width height border align data-next-message data-step-title }
|
74
75
|
config[:attributes]['a'] += %w{ target }
|
75
76
|
config[:elements] += %w{ div span hr tt }
|
@@ -91,10 +92,15 @@ module DevcenterParser
|
|
91
92
|
@@sanitize_config = config.merge({remove_contents: true, allow_comments: true})
|
92
93
|
end
|
93
94
|
|
94
|
-
def self.convert_to_article_links_all_relative_links_with_missing_initial_slashes(doc)
|
95
|
+
def self.convert_to_article_links_all_relative_links_with_missing_initial_slashes(doc, options = {})
|
96
|
+
link_prefix = options[:link_prefix] || '/articles'
|
95
97
|
doc.css('a').each do |node|
|
96
|
-
|
97
|
-
|
98
|
+
next if node['href'].nil? || node['href'] =~ /\Ahttp|\A\/|\Amailto\:|\A#/
|
99
|
+
|
100
|
+
if node['href'].start_with? 'categories/'
|
101
|
+
node['href'] = "/#{node['href']}"
|
102
|
+
else
|
103
|
+
node['href'] = "#{link_prefix}/#{node['href']}".gsub('/articles/articles/', '/articles/')
|
98
104
|
end
|
99
105
|
end
|
100
106
|
end
|
@@ -123,7 +129,7 @@ module DevcenterParser
|
|
123
129
|
end
|
124
130
|
|
125
131
|
def self.iframe_has_invalid_src?(node)
|
126
|
-
node.attributes['src'].value !~ /\Ahttps:\/\/player.vimeo.com\//i
|
132
|
+
node.attributes['src'].value !~ /\Ahttps:\/\/player.vimeo.com\//i && node.attributes['src'].value !~ /\Ahttps:\/\/www.youtube.com\/embed/i
|
127
133
|
end
|
128
134
|
|
129
135
|
def self.iframe?(node)
|
@@ -43,7 +43,7 @@ describe 'DevcenterParser' do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'allows embedding vimeo videos' do
|
46
|
-
src = '<iframe src="https://player.vimeo.com/video/61044807?title=0&byline=0&portrait=0&color=a086ee" width="50" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>'
|
46
|
+
src = '<iframe src="https://player.vimeo.com/video/61044807?title=0&byline=0&portrait=0&color=a086ee" width="50" height="281" frameborder="0" webkitallowfullscreen="" mozallowfullscreen="" allowfullscreen=""></iframe>'
|
47
47
|
assert_parsing_result src, src
|
48
48
|
end
|
49
49
|
|
@@ -234,7 +234,7 @@ And that's it.
|
|
234
234
|
more callout</p>
|
235
235
|
</div>
|
236
236
|
|
237
|
-
<p class="devcenter-parser-special-block-separator" style="display:none"
|
237
|
+
<p class="devcenter-parser-special-block-separator" style="display:none"> </p>
|
238
238
|
|
239
239
|
<blockquote>
|
240
240
|
<p>normal</p>
|
@@ -263,7 +263,7 @@ more callout</p>
|
|
263
263
|
<p>foo</p>
|
264
264
|
</div>
|
265
265
|
|
266
|
-
<p class="devcenter-parser-special-block-separator" style="display:none"
|
266
|
+
<p class="devcenter-parser-special-block-separator" style="display:none"> </p>
|
267
267
|
|
268
268
|
<div class="note">
|
269
269
|
<p>bar</p>
|
@@ -336,13 +336,21 @@ HTML
|
|
336
336
|
end
|
337
337
|
|
338
338
|
it 'converts relative links with missing initial slashes to article links' do
|
339
|
-
['foo', 'foo/bar', 'foo#bar', '123'].each do |href|
|
339
|
+
['foo', 'foo/bar', 'foo#bar', '123', 'categories'].each do |href|
|
340
340
|
md = "[link](#{href})"
|
341
341
|
html = "<p><a href=\"/articles/#{href}\">link</a></p>"
|
342
342
|
assert_parsing_result md, html
|
343
343
|
end
|
344
344
|
end
|
345
345
|
|
346
|
+
it 'ignores links with missing initial slashes IFF they start with `categories/`' do
|
347
|
+
['categories/foo', 'categories/foo/bar', 'categories/foo#bar', 'categories/123'].each do |href|
|
348
|
+
md = "[link](#{href})"
|
349
|
+
html = "<p><a href=\"/#{href}\">link</a></p>"
|
350
|
+
assert_parsing_result md, html
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
346
354
|
it 'converts "articles/foo relative links with missing initial slashes to article links' do
|
347
355
|
md = '[link](articles/foo)'
|
348
356
|
html = '<p><a href="/articles/foo">link</a></p>'
|
@@ -353,6 +361,14 @@ HTML
|
|
353
361
|
assert_parsing_result md, html
|
354
362
|
end
|
355
363
|
|
364
|
+
it 'adds a link prefix from options for relative dev center links' do
|
365
|
+
md = '[link](foo)'
|
366
|
+
expected = '<p><a href="/ja/articles/foo">link</a></p>'
|
367
|
+
|
368
|
+
result = DevcenterParser.to_html(md, { link_prefix: '/ja/articles' })
|
369
|
+
assert_equal expected.strip, result.strip, "Failed when parsing\n#{md}\n.\n\nExpected:\n#{expected}\n\nActual result:\n#{result}\n\n"
|
370
|
+
end
|
371
|
+
|
356
372
|
it 'does not alter relative links with initial slashes nor absolute links nor anchor links to the same doc' do
|
357
373
|
['http://foo.com', 'https://foo.com', '/foo', '/foo/bar', '/foo#bar', '#foo', '/123', 'mailto:foo@foobar.com'].each do |href|
|
358
374
|
md = "[link](#{href})"
|
@@ -380,7 +396,7 @@ HTML
|
|
380
396
|
<p>foo</p>
|
381
397
|
</blockquote>
|
382
398
|
|
383
|
-
<p class="devcenter-parser-special-block-separator" style="display:none"
|
399
|
+
<p class="devcenter-parser-special-block-separator" style="display:none"> </p>
|
384
400
|
|
385
401
|
<blockquote>
|
386
402
|
<p>bar</p>
|
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: 2.2.
|
4
|
+
version: 2.2.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Heroku
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -30,28 +30,28 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 3.
|
33
|
+
version: 3.5.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 3.
|
40
|
+
version: 3.5.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: sanitize
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 2.
|
47
|
+
version: 5.2.1
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 2.
|
54
|
+
version: 5.2.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: minitest
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -103,7 +103,7 @@ files:
|
|
103
103
|
homepage: https://devcenter.heroku.com
|
104
104
|
licenses: []
|
105
105
|
metadata: {}
|
106
|
-
post_install_message:
|
106
|
+
post_install_message:
|
107
107
|
rdoc_options: []
|
108
108
|
require_paths:
|
109
109
|
- lib
|
@@ -118,9 +118,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
118
|
- !ruby/object:Gem::Version
|
119
119
|
version: '0'
|
120
120
|
requirements: []
|
121
|
-
|
122
|
-
|
123
|
-
signing_key:
|
121
|
+
rubygems_version: 3.0.3
|
122
|
+
signing_key:
|
124
123
|
specification_version: 4
|
125
124
|
summary: Parser for Heroku Dev Center's content
|
126
125
|
test_files:
|