html-pipeline-external_link 0.1.0 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: cf5f9945c83ae837b193681f7bb890be4fc686b5
4
- data.tar.gz: b3dc770eb611e417c4e483f9c3ca32866f371b2e
2
+ SHA256:
3
+ metadata.gz: da6ed99e0395de1cfaaeea9f8271d9a0fb5282f076a861a84598247c78075917
4
+ data.tar.gz: af9bb610f2f2fc88d59cec575ce2d53f361abb10016bd26f15a4cecfee95ae2b
5
5
  SHA512:
6
- metadata.gz: 73bcf306f658d3609a89d3b5a4ebb495f9184121349a6f2a8ab5bada093c63cff2ad550cc7a3e96d16cae7d1b9d1a09d7177b453ac6ba178bfe508c5cccfb52e
7
- data.tar.gz: b9641d013a6d7c5bd362ed8faf1ae6ef03c8ea3199d6cfe389334e317a32626a66062984b98ceab9ebcd05b8ae7ea77cd06479a6b89f27f231f70594568f626f
6
+ metadata.gz: 404c836a60d9e2141dbf250c611a71ae33b814e4e18688863ac26cfb95871de778f3eacfb9e7a7679e9930647810271cca5272719dabcac6ff8523629255f4c7
7
+ data.tar.gz: eeca6131952066c0d70059ca6ca947f9a4232491baa57b6ec5f4a04db1d02b43a2fcaa73649552ed4a858b177b587f72537a9590580730d17616eadd456f22b4
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ Gemfile.lock
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Html::Pipeline::ExternalLink
1
+ # HtmlPipeline::ExternalLink
2
2
 
3
- External link filter for [html\-pipeline](https://github.com/jch/html-pipeline).
3
+ External link `NodeFilter` for [html\-pipeline](https://github.com/jch/html-pipeline).
4
4
 
5
5
  ## Installation
6
6
 
@@ -21,7 +21,7 @@ Or install it yourself as:
21
21
  ## Usage
22
22
 
23
23
  ```ruby
24
- filter = HTML::Pipeline::ExternalLinkFilter.new('<a href="https://google.com/">https://google.com/</a>', hostname: 'microsoft.com')
24
+ filter = HTMLPipeline::ExternalLinkFilter.call('<a href="https://google.com/">https://google.com/</a>', context: { hostname: 'microsoft.com' })
25
25
  filter.call.to_s # => '<a href="https://google.com/" rel="nofollow noopener" target="_blank">https://google.com/</a>'
26
26
  ```
27
27
 
@@ -41,4 +41,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
41
41
 
42
42
  ## Code of Conduct
43
43
 
44
- Everyone interacting in the Html::Pipeline::ExternalLink project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/html-pipeline-external_link/blob/master/CODE_OF_CONDUCT.md).
44
+ Everyone interacting in the HtmlPipeline::ExternalLink project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/html-pipeline-external_link/blob/master/CODE_OF_CONDUCT.md).
@@ -5,7 +5,7 @@ require "html/pipeline/external_link/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "html-pipeline-external_link"
8
- spec.version = HTML::Pipeline::ExternalLink::VERSION
8
+ spec.version = HTMLPipeline::ExternalLink::VERSION
9
9
  spec.authors = ["aki77"]
10
10
  spec.email = ["aki77@users.noreply.github.com"]
11
11
 
@@ -22,8 +22,8 @@ Gem::Specification.new do |spec|
22
22
  spec.require_paths = ["lib"]
23
23
 
24
24
  spec.add_dependency "addressable"
25
- spec.add_dependency "html-pipeline"
26
- spec.add_development_dependency "bundler", "~> 1.16"
27
- spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_dependency "html-pipeline", "~> 3.0"
26
+ spec.add_development_dependency "bundler", "~> 2.0"
27
+ spec.add_development_dependency "rake", ">= 12.3.3"
28
28
  spec.add_development_dependency "rspec", "~> 3.0"
29
29
  end
@@ -1,42 +1,39 @@
1
- require 'html/pipeline'
1
+ require 'html_pipeline'
2
2
  require "addressable/uri"
3
3
 
4
4
  # SEE: https://github.com/increments/qiita-markdown/blob/master/lib/qiita/markdown/filters/external_link.rb
5
- module HTML
6
- class Pipeline
7
- class ExternalLinkFilter < Filter
8
- def call
9
- doc.search("a").each do |anchor|
10
- next unless anchor["href"]
11
- href = anchor["href"].strip
12
- href_host = host_of(href)
13
- next unless href_host
14
- if href_host != hostname
15
- anchor["rel"] = "nofollow noopener"
16
- anchor["target"] = "_blank"
17
- end
18
- end
19
-
20
- doc
21
- end
22
-
23
- def validate
24
- needs :hostname
25
- end
26
-
27
- private
28
-
29
- def host_of(url)
30
- uri = Addressable::URI.parse(url)
31
- uri.host
32
- rescue Addressable::URI::InvalidURIError
33
- nil
34
- end
35
-
36
- def hostname
37
- context[:hostname]
38
- end
5
+ class HTMLPipeline
6
+ class ExternalLinkFilter < NodeFilter
7
+ SELECTOR = Selma::Selector.new(match_element: %(a[href^="http"]))
39
8
 
9
+ def selector
10
+ SELECTOR
11
+ end
12
+
13
+ def handle_element(element)
14
+ return unless element["href"]
15
+
16
+ href = element["href"].strip
17
+ href_host = host_of(href)
18
+ return unless href_host
19
+
20
+ if href_host != hostname
21
+ element["rel"] = "nofollow noopener"
22
+ element["target"] = "_blank"
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def host_of(url)
29
+ uri = Addressable::URI.parse(url)
30
+ uri.host
31
+ rescue Addressable::URI::InvalidURIError
32
+ nil
33
+ end
34
+
35
+ def hostname
36
+ context[:hostname] || raise("Missing context :hostname for #{self.class.name}")
40
37
  end
41
38
  end
42
39
  end
@@ -1,7 +1,5 @@
1
- module HTML
2
- class Pipeline
3
- module ExternalLink
4
- VERSION = "0.1.0"
5
- end
1
+ class HTMLPipeline
2
+ module ExternalLink
3
+ VERSION = "1.0.0"
6
4
  end
7
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html-pipeline-external_link
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - aki77
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-02 00:00:00.000000000 Z
11
+ date: 2024-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -28,44 +28,44 @@ dependencies:
28
28
  name: html-pipeline
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '3.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: '0'
40
+ version: '3.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.16'
47
+ version: '2.0'
48
48
  type: :development
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: '1.16'
54
+ version: '2.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '10.0'
61
+ version: 12.3.3
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '10.0'
68
+ version: 12.3.3
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -92,7 +92,6 @@ files:
92
92
  - ".travis.yml"
93
93
  - CODE_OF_CONDUCT.md
94
94
  - Gemfile
95
- - Gemfile.lock
96
95
  - LICENSE.txt
97
96
  - README.md
98
97
  - Rakefile
@@ -106,7 +105,7 @@ homepage: https://github.com/aki77/html-pipeline-external_link
106
105
  licenses:
107
106
  - MIT
108
107
  metadata: {}
109
- post_install_message:
108
+ post_install_message:
110
109
  rdoc_options: []
111
110
  require_paths:
112
111
  - lib
@@ -121,9 +120,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
120
  - !ruby/object:Gem::Version
122
121
  version: '0'
123
122
  requirements: []
124
- rubyforge_project:
125
- rubygems_version: 2.6.14
126
- signing_key:
123
+ rubygems_version: 3.4.10
124
+ signing_key:
127
125
  specification_version: 4
128
126
  summary: External link filter for html-pipeline.
129
127
  test_files: []
data/Gemfile.lock DELETED
@@ -1,58 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- html-pipeline-external_link (0.1.0)
5
- addressable
6
- html-pipeline
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- activesupport (5.2.0)
12
- concurrent-ruby (~> 1.0, >= 1.0.2)
13
- i18n (>= 0.7, < 2)
14
- minitest (~> 5.1)
15
- tzinfo (~> 1.1)
16
- addressable (2.5.2)
17
- public_suffix (>= 2.0.2, < 4.0)
18
- concurrent-ruby (1.0.5)
19
- diff-lcs (1.3)
20
- html-pipeline (2.8.3)
21
- activesupport (>= 2)
22
- nokogiri (>= 1.4)
23
- i18n (1.0.1)
24
- concurrent-ruby (~> 1.0)
25
- mini_portile2 (2.3.0)
26
- minitest (5.11.3)
27
- nokogiri (1.8.3)
28
- mini_portile2 (~> 2.3.0)
29
- public_suffix (3.0.2)
30
- rake (10.5.0)
31
- rspec (3.7.0)
32
- rspec-core (~> 3.7.0)
33
- rspec-expectations (~> 3.7.0)
34
- rspec-mocks (~> 3.7.0)
35
- rspec-core (3.7.1)
36
- rspec-support (~> 3.7.0)
37
- rspec-expectations (3.7.0)
38
- diff-lcs (>= 1.2.0, < 2.0)
39
- rspec-support (~> 3.7.0)
40
- rspec-mocks (3.7.0)
41
- diff-lcs (>= 1.2.0, < 2.0)
42
- rspec-support (~> 3.7.0)
43
- rspec-support (3.7.1)
44
- thread_safe (0.3.6)
45
- tzinfo (1.2.5)
46
- thread_safe (~> 0.1)
47
-
48
- PLATFORMS
49
- ruby
50
-
51
- DEPENDENCIES
52
- bundler (~> 1.16)
53
- html-pipeline-external_link!
54
- rake (~> 10.0)
55
- rspec (~> 3.0)
56
-
57
- BUNDLED WITH
58
- 1.16.0