devcenter-parser 2.2.6 → 2.2.8
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/Gemfile.lock +6 -6
- data/lib/devcenter-parser.rb +9 -8
- data/lib/devcenter-parser/version.rb +1 -1
- data/test/devcenter-parser_test.rb +8 -0
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd5edad9607dc8de72a80982f035a865ab6f04c09908f772d72c55d01de2ac6e
|
4
|
+
data.tar.gz: f64c21cc67a7d1679f3af2419ccab6cd641bb3a249c72b72ceabff19327b497b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c3071a154a46f5605436a073e2109cec8a99f4c2776292f79e43551dda3956e7e6aa633c1f80dd51f883c1a098084e04e2b2c37cdb69f39cbcdf66bfaaa4feb
|
7
|
+
data.tar.gz: da887be8d774e63819a817492eb00adf5e43d835767ee747d06dded34cb24490404c359c2079d54687236537aa41144b9f4b6d13324ee2be013e80f17e2f4222
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
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
6
|
redcarpet (= 3.3.4)
|
7
7
|
sanitize (~> 4.6.3)
|
@@ -9,11 +9,11 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: http://rubygems.org/
|
11
11
|
specs:
|
12
|
-
crass (1.0.
|
13
|
-
mini_portile2 (2.
|
12
|
+
crass (1.0.6)
|
13
|
+
mini_portile2 (2.4.0)
|
14
14
|
minitest (5.10.1)
|
15
|
-
nokogiri (1.
|
16
|
-
mini_portile2 (~> 2.
|
15
|
+
nokogiri (1.10.9)
|
16
|
+
mini_portile2 (~> 2.4.0)
|
17
17
|
nokogumbo (1.5.0)
|
18
18
|
nokogiri
|
19
19
|
rake (12.0.0)
|
@@ -32,4 +32,4 @@ DEPENDENCIES
|
|
32
32
|
rake
|
33
33
|
|
34
34
|
BUNDLED WITH
|
35
|
-
1.
|
35
|
+
1.17.2
|
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
|
@@ -92,14 +92,15 @@ module DevcenterParser
|
|
92
92
|
@@sanitize_config = config.merge({remove_contents: true, allow_comments: true})
|
93
93
|
end
|
94
94
|
|
95
|
-
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'
|
96
97
|
doc.css('a').each do |node|
|
97
98
|
next if node['href'].nil? || node['href'] =~ /\Ahttp|\A\/|\Amailto\:|\A#/
|
98
99
|
|
99
100
|
if node['href'].start_with? 'categories/'
|
100
101
|
node['href'] = "/#{node['href']}"
|
101
102
|
else
|
102
|
-
node['href'] = "
|
103
|
+
node['href'] = "#{link_prefix}/#{node['href']}".gsub('/articles/articles/', '/articles/')
|
103
104
|
end
|
104
105
|
end
|
105
106
|
end
|
@@ -361,6 +361,14 @@ HTML
|
|
361
361
|
assert_parsing_result md, html
|
362
362
|
end
|
363
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
|
+
|
364
372
|
it 'does not alter relative links with initial slashes nor absolute links nor anchor links to the same doc' do
|
365
373
|
['http://foo.com', 'https://foo.com', '/foo', '/foo/bar', '/foo#bar', '#foo', '/123', 'mailto:foo@foobar.com'].each do |href|
|
366
374
|
md = "[link](#{href})"
|
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.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Heroku
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -118,8 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
118
|
- !ruby/object:Gem::Version
|
119
119
|
version: '0'
|
120
120
|
requirements: []
|
121
|
-
|
122
|
-
rubygems_version: 2.7.6
|
121
|
+
rubygems_version: 3.0.3
|
123
122
|
signing_key:
|
124
123
|
specification_version: 4
|
125
124
|
summary: Parser for Heroku Dev Center's content
|