jekyll-target-blank 1.2.0 → 2.0.2

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
2
  SHA256:
3
- metadata.gz: 8591bd504286af36dc7a53c951b0fc1bd9dd259773b80c4bdab1ca26f35f14a0
4
- data.tar.gz: 6e6044b68e2c9af9ebbc014b4a09940d40ce22767a91b5a8a6e129657386615a
3
+ metadata.gz: d09306731b5daf78557b35c07d12b01ce9454066f6bbff6366a586f8eff3ef77
4
+ data.tar.gz: 5a4b74d1e06d47c1f00ba015df4eae7ba90ff91f3ed7a2a237639d2eaa853244
5
5
  SHA512:
6
- metadata.gz: c58bc3be1cd528461cb0ecd82542ec7ecb31c93393a9a10a8a38311cbef20211ee13a5f22cfc35d606343edf1cc891cf9bd6994ca2143e8db2d09065cd8a850e
7
- data.tar.gz: 71ce36b1541549b289bf04207808c9d50f54ea659f4cf7f35539ed1ca4cea1f2e72e38441528f77cc66679f89e4c980a4e246daf80a8a0cf3fd4884c38216cc2
6
+ metadata.gz: c672f8fcdc9464870295b847e901f13733c66e33628a25026078bd2f87b4cc3f1a1bb0ebf02f4c05b5007c1f778dbe856bf09962c68422480bcad9c59ddf7040
7
+ data.tar.gz: 000db26fb7adb11f4f5f0c7c675eb6625e7253f43d8d5097cb6c50d4ca7e2039eb31f7cae99a2a5508a5d3f55de01281fa27264a02ce1f3cb28df44250ea9902
data/.gitignore CHANGED
@@ -2,4 +2,6 @@
2
2
  /*.gem
3
3
  Gemfile.lock
4
4
  dev_notes.md
5
- .vscode
5
+ .vscode
6
+ spec/fixtures/unit/.jekyll-cache
7
+ pkg
data/.rubocop.yml CHANGED
@@ -1,12 +1,11 @@
1
- inherit_gem:
2
- jekyll: .rubocop.yml
1
+
3
2
 
4
3
  AllCops:
5
- TargetRubyVersion: 2.3
4
+ TargetRubyVersion: 2.6
6
5
  Exclude:
7
6
  - vendor/**/*
8
7
 
9
- Metrics/LineLength:
8
+ Layout/LineLength:
10
9
  Exclude:
11
10
  - spec/**/*
12
11
  - jekyll-target-blank.gemspec
data/.travis.yml CHANGED
@@ -2,7 +2,7 @@ language: ruby
2
2
  rvm:
3
3
  - 2.5
4
4
  - 2.4
5
- - 2.3
5
+ - 2.6
6
6
  before_install:
7
7
  - gem update --system
8
8
  - gem install bundler
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source "https://rubygems.org"
3
+ source 'https://rubygems.org'
4
4
 
5
5
  gemspec
data/README.md CHANGED
@@ -113,7 +113,7 @@ target-blank:
113
113
  noreferrer: false
114
114
  ```
115
115
 
116
- __To exclude both `noopner` and `noreferrer` values:__
116
+ __To exclude both `noopener` and `noreferrer` values:__
117
117
 
118
118
  ```yaml
119
119
  target-blank:
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec)
@@ -1,27 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path("lib", __dir__)
3
+ lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require "jekyll-target-blank/version"
5
+ require 'jekyll-target-blank/version'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
- spec.name = "jekyll-target-blank"
8
+ spec.name = 'jekyll-target-blank'
9
9
  spec.version = JekyllTargetBlank::VERSION
10
- spec.authors = ["Keith Mifsud"]
11
- spec.email = ["mifsud.k@gmail.com"]
12
- spec.summary = "Target Blank automatically changes the external links to open in a new browser."
13
- spec.description = "Target Blank automatically changes the external links to open in a new browser for Jekyll sites."
14
- spec.homepage = "https://github.com/keithmifsud/jekyll-target-blank"
15
- spec.license = "MIT"
10
+ spec.authors = ['Keith Mifsud']
11
+ spec.email = ['mifsud.k@gmail.com']
12
+ spec.summary = 'Target Blank automatically changes the external links to open in a new browser.'
13
+ spec.description = 'Target Blank automatically changes the external links to open in a new browser for Jekyll sites.'
14
+ spec.homepage = 'https://github.com/keithmifsud/jekyll-target-blank'
15
+ spec.license = 'MIT'
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
- spec.require_paths = ["lib"]
18
- spec.required_ruby_version = ">= 2.3.0"
17
+ spec.require_paths = ['lib']
18
+ spec.required_ruby_version = '>= 2.3.0'
19
+ spec.add_dependency 'jekyll', '>= 3.0', '<5.0'
20
+ spec.add_dependency 'nokogiri', '~> 1.10'
21
+ spec.add_development_dependency 'bundler', '~> 2.0'
22
+ spec.add_development_dependency 'rake', '~> 12.0'
23
+ spec.add_development_dependency 'rspec', '~> 3.0'
24
+ spec.add_development_dependency 'rubocop', '~> 1'
25
+ spec.add_development_dependency "rubocop-jekyll", "~> 0.12.0"
19
26
 
20
- spec.add_dependency "jekyll", "~> 3.0"
21
- spec.add_dependency "nokogiri", "~> 1.10.4"
22
-
23
- spec.add_development_dependency "bundler", "~> 2.0"
24
- spec.add_development_dependency "rake", "~> 12.0"
25
- spec.add_development_dependency "rspec", "~> 3.0"
26
- spec.add_development_dependency "rubocop", "0.55"
27
27
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllTargetBlank
4
- VERSION = "1.2.0"
4
+ VERSION = "2.0.2"
5
5
  end
@@ -7,7 +7,7 @@ require "uri"
7
7
  module Jekyll
8
8
  class TargetBlank
9
9
  BODY_START_TAG = "<body"
10
- OPENING_BODY_TAG_REGEX = %r!<body([^<>]*)>\s*!
10
+ OPENING_BODY_TAG_REGEX = %r!<body([^<>]*)>\s*!.freeze
11
11
 
12
12
  class << self
13
13
  # Public: Processes the content and updated the external links
@@ -117,13 +117,9 @@ module Jekyll
117
117
 
118
118
  # Private: Handles the default rel attribute values
119
119
  def add_default_rel_attributes?
120
- if should_not_include_noopener?
121
- @should_add_noopener = false
122
- end
120
+ @should_add_noopener = false if should_not_include_noopener?
123
121
 
124
- if should_not_include_noreferrer?
125
- @should_add_noreferrrer = false
126
- end
122
+ @should_add_noreferrrer = false if should_not_include_noreferrer?
127
123
  end
128
124
 
129
125
  # Private: Sets any extra rel attribute values
@@ -142,7 +138,7 @@ module Jekyll
142
138
  if @should_add_css_classes
143
139
  existing_classes = get_existing_css_classes(link)
144
140
  existing_classes = " " + existing_classes unless existing_classes.to_s.empty?
145
- link["class"] = @css_classes_to_add + existing_classes
141
+ link["class"] = @css_classes_to_add + existing_classes
146
142
  end
147
143
  end
148
144
 
@@ -157,28 +153,31 @@ module Jekyll
157
153
  #
158
154
  # link = Nokogiri node.
159
155
  def add_rel_attributes(link)
160
- rel = ""
161
- if @should_add_noopener
162
- rel = "noopener"
163
- end
156
+ rel = link["rel"] || ""
157
+ rel = add_noopener_to_rel(rel)
164
158
 
165
159
  if @should_add_noreferrrer
166
- unless rel.empty?
167
- rel += " "
168
- end
160
+ rel += " " unless rel.empty?
169
161
  rel += "noreferrer"
170
162
  end
171
163
 
172
164
  if @should_add_extra_rel_attribute_values
173
- unless rel.empty?
174
- rel += " "
175
- end
165
+ rel += " " unless rel.empty?
176
166
  rel += @extra_rel_attribute_values
177
167
  end
178
168
 
179
- unless rel.empty?
180
- link["rel"] = rel
169
+ link["rel"] = rel unless rel.empty?
170
+ end
171
+
172
+ # Private: Adds noopener attribute.
173
+ #
174
+ # rel = string
175
+ def add_noopener_to_rel(rel)
176
+ if @should_add_noopener
177
+ rel += " " unless rel.empty?
178
+ rel += "noopener"
181
179
  end
180
+ rel
182
181
  end
183
182
 
184
183
  # Private: Checks if the link is a mailto url.
@@ -193,7 +192,7 @@ module Jekyll
193
192
  #
194
193
  # link - a url.
195
194
  def external?(link)
196
- if link =~ URI.regexp(%w(http https))
195
+ if link&.match?(URI.regexp(%w(http https)))
197
196
  URI.parse(link).host != URI.parse(@site_url).host
198
197
  end
199
198
  end
@@ -332,6 +331,6 @@ module Jekyll
332
331
  end
333
332
 
334
333
  # Hooks into Jekyll's post_render event.
335
- Jekyll::Hooks.register %i[pages documents], :post_render do |doc|
334
+ Jekyll::Hooks.register [:pages, :documents], :post_render do |doc|
336
335
  Jekyll::TargetBlank.process(doc) if Jekyll::TargetBlank.document_processable?(doc)
337
336
  end
@@ -6,53 +6,51 @@ RSpec.describe(Jekyll::TargetBlank) do
6
6
  let(:config_overrides) { {} }
7
7
  let(:config_overrides) do
8
8
  {
9
- "url" => "https://keith-mifsud.me",
10
- "collections" => { "docs" => { "output" => "true" } },
9
+ 'url' => 'https://keith-mifsud.me',
10
+ 'collections' => { 'docs' => { 'output' => 'true' } }
11
11
  }
12
12
  end
13
13
  let(:configs) do
14
14
  Jekyll.configuration(config_overrides.merge(
15
- {
16
- "skip_config_files" => false,
17
- "collections" => { "docs" => { "output" => true } },
18
- "source" => unit_fixtures_dir,
19
- "destination" => unit_fixtures_dir("_site"),
20
- }
21
- ))
15
+ 'skip_config_files' => false,
16
+ 'collections' => { 'docs' => { 'output' => true } },
17
+ 'source' => unit_fixtures_dir,
18
+ 'destination' => unit_fixtures_dir('_site')
19
+ ))
22
20
  end
23
21
  let(:target_blank) { described_class }
24
22
  let(:site) { Jekyll::Site.new(configs) }
25
23
  let(:posts) { site.posts.docs.sort.reverse }
26
24
 
27
25
  # get some fixtures
28
- let(:post_with_external_markdown_link) { find_by_title(posts, "Post with external markdown link") }
26
+ let(:post_with_external_markdown_link) { find_by_title(posts, 'Post with external markdown link') }
29
27
 
30
- let(:post_with_multiple_external_markdown_links) { find_by_title(posts, "Post with multiple external markdown links") }
28
+ let(:post_with_multiple_external_markdown_links) { find_by_title(posts, 'Post with multiple external markdown links') }
31
29
 
32
- let(:post_with_relative_markdown_link) { find_by_title(posts, "Post with relative markdown link") }
30
+ let(:post_with_relative_markdown_link) { find_by_title(posts, 'Post with relative markdown link') }
33
31
 
34
- let(:post_with_absolute_internal_markdown_link) { find_by_title(posts, "Post with absolute internal markdown link") }
32
+ let(:post_with_absolute_internal_markdown_link) { find_by_title(posts, 'Post with absolute internal markdown link') }
35
33
 
36
- let(:post_with_html_anchor_tag) { find_by_title(posts, "Post with html anchor tag") }
34
+ let(:post_with_html_anchor_tag) { find_by_title(posts, 'Post with html anchor tag') }
37
35
 
38
- let(:post_with_plain_text_link) { find_by_title(posts, "Post with plain text link") }
36
+ let(:post_with_plain_text_link) { find_by_title(posts, 'Post with plain text link') }
39
37
 
40
- let(:document_with_a_processable_link) { find_by_title(site.collections["docs"].docs, "Document with a processable link") }
38
+ let(:document_with_a_processable_link) { find_by_title(site.collections['docs'].docs, 'Document with a processable link') }
41
39
 
42
- let(:text_file) { find_by_title(site.collections["docs"].docs, "Text file") }
40
+ let(:text_file) { find_by_title(site.collections['docs'].docs, 'Text file') }
43
41
 
44
- let(:post_with_code_block) { find_by_title(posts, "Post with code block") }
45
- let(:document_with_liquid_tag) { find_by_title(site.collections["docs"].docs, "Document with liquid tag") }
42
+ let(:post_with_code_block) { find_by_title(posts, 'Post with code block') }
43
+ let(:document_with_liquid_tag) { find_by_title(site.collections['docs'].docs, 'Document with liquid tag') }
46
44
 
47
- let(:document_with_include) { find_by_title(site.collections["docs"].docs, "Document with include") }
45
+ let(:document_with_include) { find_by_title(site.collections['docs'].docs, 'Document with include') }
48
46
 
49
- let(:post_with_mailto_link) { find_by_title(posts, "Post with mailto link") }
47
+ let(:post_with_mailto_link) { find_by_title(posts, 'Post with mailto link') }
50
48
 
51
- let(:post_with_external_html_link_and_random_css_classes) { find_by_title(posts, "Post with external html link and random css classes") }
49
+ let(:post_with_external_html_link_and_random_css_classes) { find_by_title(posts, 'Post with external html link and random css classes') }
52
50
 
53
- let(:post_with_html_link_containing_the_specified_css_class) { find_by_title(posts, "Post with html link containing the specified css class") }
51
+ let(:post_with_html_link_containing_the_specified_css_class) { find_by_title(posts, 'Post with html link containing the specified css class') }
54
52
 
55
- let(:post_with_external_link_containing_the_specified_css_class_and_other_css_classes) { find_by_title(posts, "Post with external link containing the specified css class and other css classes") }
53
+ let(:post_with_external_link_containing_the_specified_css_class_and_other_css_classes) { find_by_title(posts, 'Post with external link containing the specified css class and other css classes') }
56
54
 
57
55
  # define common wrappers.
58
56
  def para(content)
@@ -66,50 +64,50 @@ RSpec.describe(Jekyll::TargetBlank) do
66
64
  site.render
67
65
  end
68
66
 
69
- context "Without entries in config file" do
67
+ context 'Without entries in config file' do
70
68
  let(:config_overrides) do
71
- { "target-blank" => { "add_css_classes" => false } }
69
+ { 'target-blank' => { 'add_css_classes' => false } }
72
70
  end
73
71
 
74
- it "should add target attribute to external markdown link" do
72
+ it 'should add target attribute to external markdown link' do
75
73
  expect(post_with_external_markdown_link.output).to include(para('Link to <a href="https://google.com" target="_blank" rel="noopener noreferrer">Google</a>.'))
76
74
  end
77
75
 
78
- it "should add target attribute to multiple external markdown links" do
76
+ it 'should add target attribute to multiple external markdown links' do
79
77
  expect(post_with_multiple_external_markdown_links.output).to include('<p>This post contains three links. The first link is to <a href="https://google.com" target="_blank" rel="noopener noreferrer">Google</a>, the second link is, well, to <a href="https://keithmifsud.github.io" target="_blank" rel="noopener noreferrer">my website</a> and since <a href="https://github.com" target="_blank" rel="noopener noreferrer">GitHub</a> is so awesome, why not link to them too?</p>')
80
78
  end
81
79
 
82
- it "should not add target attribute to relative markdown link" do
80
+ it 'should not add target attribute to relative markdown link' do
83
81
  expect(post_with_relative_markdown_link.output).to include(para('Link to <a href="/contact">contact page</a>.'))
84
82
 
85
83
  expect(post_with_relative_markdown_link.output).to_not include(para('Link to <a href="/contact" target="_blank" rel="noopener noreferrer">contact page</a>'))
86
84
  end
87
85
 
88
- it "should not add target attribute to absolute internal link" do
86
+ it 'should not add target attribute to absolute internal link' do
89
87
  expect(post_with_absolute_internal_markdown_link.output).to include('<p>This is an absolute internal <a href="https://keith-mifsud.me/contact">link</a>.</p>')
90
88
  end
91
89
 
92
- it "should correctly handle existing html anchor tag" do
90
+ it 'should correctly handle existing html anchor tag' do
93
91
  expect(post_with_html_anchor_tag.output).to include('<p>This is an <a href="https://google.com" target="_blank" rel="noopener noreferrer">anchor tag</a>.</p>')
94
92
  end
95
93
 
96
- it "should not interfere with plain text link" do
97
- expect(post_with_plain_text_link.output).to include("<p>This is a plain text link to https://google.com.</p>")
94
+ it 'should not interfere with plain text link' do
95
+ expect(post_with_plain_text_link.output).to include('<p>This is a plain text link to https://google.com.</p>')
98
96
  end
99
97
 
100
- it "should process external links in collections" do
98
+ it 'should process external links in collections' do
101
99
  expect(document_with_a_processable_link.output).to include('<p>This is a valid <a href="https://google.com" target="_blank" rel="noopener noreferrer">link</a>.</p>')
102
100
  end
103
101
 
104
- it "should process external links in pages" do
102
+ it 'should process external links in pages' do
105
103
  expect(site.pages.first.output).to include('<p>This is a valid <a href="https://google.com" target="_blank" rel="noopener noreferrer">link</a>.</p>')
106
104
  end
107
105
 
108
- it "should not process links in non html files" do
109
- expect(text_file.output).to eq("Valid [link](https://google.com).")
106
+ it 'should not process links in non html files' do
107
+ expect(text_file.output).to eq('Valid [link](https://google.com).')
110
108
  end
111
109
 
112
- it "should not process link in code block but process link outside of block" do
110
+ it 'should not process link in code block but process link outside of block' do
113
111
  expect(post_with_code_block.output).to include('<span class="s1">\'https://google.com\'</span>')
114
112
 
115
113
  expect(post_with_code_block.output).not_to include('<span class="s1"><a href="https://google.com" target="_blank" rel="noopener noreferrer">https://google.com</a></span>')
@@ -117,307 +115,307 @@ RSpec.describe(Jekyll::TargetBlank) do
117
115
  expect(post_with_code_block.output).to include('<p>Valid <a href="https://google.com" target="_blank" rel="noopener noreferrer">link</a></p>')
118
116
  end
119
117
 
120
- it "should not break layouts" do
118
+ it 'should not break layouts' do
121
119
  expect(site.pages.first.output).to include('<html lang="en-US">')
122
120
  expect(site.pages.first.output).to include('<body class="wrap">')
123
121
  end
124
122
 
125
- it "should not interfere with liquid tags" do
123
+ it 'should not interfere with liquid tags' do
126
124
  expect(document_with_liquid_tag.output).to include('<p>This <a href="/docs/document-with-liquid-tag.html">_docs/document-with-liquid-tag.md</a> is a document with a liquid tag.</p>')
127
125
  end
128
126
 
129
- it "should not interfere with includes" do
130
- expect(document_with_include.output).to include("<p>This is a document with an include: This is an include.</p>")
127
+ it 'should not interfere with includes' do
128
+ expect(document_with_include.output).to include('<p>This is a document with an include: This is an include.</p>')
131
129
  end
132
130
 
133
- it "should not break layout content" do
134
- expect(site.pages.first.output).to include("<div>Layout content started.</div>")
131
+ it 'should not break layout content' do
132
+ expect(site.pages.first.output).to include('<div>Layout content started.</div>')
135
133
 
136
- expect(site.pages.first.output).to include("<div>Layout content ended.</div>")
134
+ expect(site.pages.first.output).to include('<div>Layout content ended.</div>')
137
135
  end
138
136
 
139
- it "should not duplicate post content" do
137
+ it 'should not duplicate post content' do
140
138
  expect(post_with_external_markdown_link.output).to eq(post_with_layout_result)
141
139
  end
142
140
 
143
- it "should ignore mailto links" do
141
+ it 'should ignore mailto links' do
144
142
  expect(post_with_mailto_link.output).to include(para('This is a <a href="mailto:mifsud.k@gmail.com?Subject=Just%20an%20email">mailto link</a>.'))
145
143
  end
146
144
  end
147
145
 
148
- context "With a specified css class name" do
149
- let(:target_blank_css_class) { "ext-link" }
146
+ context 'With a specified css class name' do
147
+ let(:target_blank_css_class) { 'ext-link' }
150
148
  let(:config_overrides) do
151
149
  {
152
- "target-blank" => {
153
- "css_class" => target_blank_css_class,
154
- "add_css_classes" => false,
155
- },
150
+ 'target-blank' => {
151
+ 'css_class' => target_blank_css_class,
152
+ 'add_css_classes' => false
153
+ }
156
154
  }
157
155
  end
158
156
 
159
- it "should not add target attribute to external markdown link that does not have the specified css class" do
157
+ it 'should not add target attribute to external markdown link that does not have the specified css class' do
160
158
  expect(post_with_external_markdown_link.output).to_not include(para('Link to <a href="https://google.com" target="_blank">Google</a>.'))
161
159
  end
162
160
 
163
- it "should not add target attribute to external markdown link that does not have the specified css class even if it does have other css classes" do
161
+ it 'should not add target attribute to external markdown link that does not have the specified css class even if it does have other css classes' do
164
162
  expect(post_with_external_html_link_and_random_css_classes.output).to include(para('<a href="https://google.com" class="random-class another-random-class">Link</a>.'))
165
163
 
166
164
  expect(post_with_external_html_link_and_random_css_classes.output).to_not include('target="_blank" rel="noopener noreferrer"')
167
165
  end
168
166
 
169
- it "should add target attribute to an external link containing the specified css class" do
167
+ it 'should add target attribute to an external link containing the specified css class' do
170
168
  expect(post_with_html_link_containing_the_specified_css_class.output).to include(para('<a href="https://google.com" class="ext-link" target="_blank" rel="noopener noreferrer">Link with the css class specified in config</a>.'))
171
169
  end
172
170
 
173
- it "should add target attribute to an external link containing the specified css class even when other css classes are specified" do
171
+ it 'should add target attribute to an external link containing the specified css class even when other css classes are specified' do
174
172
  expect(post_with_external_link_containing_the_specified_css_class_and_other_css_classes.output).to include(para('This is <a href="https://not-keith-mifsud.me" class="random-class ext-link another-random-class" target="_blank" rel="noopener noreferrer">a link containing the specified css class and two other random css classes</a>.'))
175
173
  end
176
174
  end
177
175
 
178
- context "Adds a CSS classes to the links" do
179
- let(:target_blank_add_css_class) { "some-class" }
176
+ context 'Adds a CSS classes to the links' do
177
+ let(:target_blank_add_css_class) { 'some-class' }
180
178
  let(:config_overrides) do
181
- { "target-blank" => { "add_css_classes" => target_blank_add_css_class } }
179
+ { 'target-blank' => { 'add_css_classes' => target_blank_add_css_class } }
182
180
  end
183
181
 
184
- it "should add the CSS class specified in config" do
182
+ it 'should add the CSS class specified in config' do
185
183
  expect(post_with_external_markdown_link.output).to include(para('Link to <a href="https://google.com" target="_blank" rel="noopener noreferrer" class="some-class">Google</a>.'))
186
184
  end
187
185
 
188
- it "should add the CSS class specified in config even when the link already has a CSS class specified" do
186
+ it 'should add the CSS class specified in config even when the link already has a CSS class specified' do
189
187
  expect(post_with_html_link_containing_the_specified_css_class.output).to include(para('<a href="https://google.com" class="some-class ext-link" target="_blank" rel="noopener noreferrer">Link with the css class specified in config</a>.'))
190
188
  end
191
189
 
192
- it "should add the CSS class specified in config even when the link has more than CSS classes already included" do
190
+ it 'should add the CSS class specified in config even when the link has more than CSS classes already included' do
193
191
  expect(post_with_external_link_containing_the_specified_css_class_and_other_css_classes.output).to include(para('This is <a href="https://not-keith-mifsud.me" class="some-class random-class ext-link another-random-class" target="_blank" rel="noopener noreferrer">a link containing the specified css class and two other random css classes</a>.'))
194
192
  end
195
193
  end
196
194
 
197
- context "When more than one CSS classes are specified in config" do
198
- it "should add the CSS classes specified in config" do
195
+ context 'When more than one CSS classes are specified in config' do
196
+ it 'should add the CSS classes specified in config' do
199
197
  expect(post_with_external_markdown_link.output).to include(para('Link to <a href="https://google.com" target="_blank" rel="noopener noreferrer" class="some-class other-some-class another-some-class">Google</a>.'))
200
198
  end
201
199
 
202
- it "should add the CSS classes specified in config even when the link already has a CSS class included" do
200
+ it 'should add the CSS classes specified in config even when the link already has a CSS class included' do
203
201
  expect(post_with_html_link_containing_the_specified_css_class.output).to include(para('<a href="https://google.com" class="some-class other-some-class another-some-class ext-link" target="_blank" rel="noopener noreferrer">Link with the css class specified in config</a>.'))
204
202
  end
205
203
 
206
- it "should add the CSS classes specified in config even when the link already has more than one CSS classes included" do
204
+ it 'should add the CSS classes specified in config even when the link already has more than one CSS classes included' do
207
205
  expect(post_with_external_link_containing_the_specified_css_class_and_other_css_classes.output).to include(para('This is <a href="https://not-keith-mifsud.me" class="some-class other-some-class another-some-class random-class ext-link another-random-class" target="_blank" rel="noopener noreferrer">a link containing the specified css class and two other random css classes</a>.'))
208
206
  end
209
207
  end
210
208
 
211
- context "When noopener is set to false in config" do
209
+ context 'When noopener is set to false in config' do
212
210
  let(:noopener) { false }
213
211
  let(:config_overrides) do
214
212
  {
215
- "target-blank" => {
216
- "add_css_classes" => false,
217
- "noopener" => noopener,
218
- },
213
+ 'target-blank' => {
214
+ 'add_css_classes' => false,
215
+ 'noopener' => noopener
216
+ }
219
217
  }
220
218
  end
221
219
 
222
- it "should not add noopener value to the rel attribute" do
220
+ it 'should not add noopener value to the rel attribute' do
223
221
  expect(post_with_external_markdown_link.output).to_not include(para('Link to <a href="https://google.com" target="_blank" rel="noopener noreferrer">Google</a>.'))
224
222
  end
225
223
 
226
- it "should still add noreferrer value to the rel attribute" do
224
+ it 'should still add noreferrer value to the rel attribute' do
227
225
  expect(post_with_external_markdown_link.output).to include(para('Link to <a href="https://google.com" target="_blank" rel="noreferrer">Google</a>.'))
228
226
  end
229
227
  end
230
228
 
231
- context "When noreferrer is set to false in config" do
229
+ context 'When noreferrer is set to false in config' do
232
230
  let(:noreferrer) { false }
233
231
  let(:config_overrides) do
234
232
  {
235
- "target-blank" => {
236
- "add_css_classes" => false,
237
- "noreferrer" => noreferrer,
238
- },
233
+ 'target-blank' => {
234
+ 'add_css_classes' => false,
235
+ 'noreferrer' => noreferrer
236
+ }
239
237
  }
240
238
  end
241
239
 
242
- it "should not add noreferrer value to the rel attribute" do
240
+ it 'should not add noreferrer value to the rel attribute' do
243
241
  expect(post_with_external_markdown_link.output).to_not include(para('Link to <a href="https://google.com" target="_blank" rel="noopener noreferrer">Google</a>.'))
244
242
  end
245
243
 
246
- it "should still add noopener value to the rel attribute" do
244
+ it 'should still add noopener value to the rel attribute' do
247
245
  expect(post_with_external_markdown_link.output).to include(para('Link to <a href="https://google.com" target="_blank" rel="noopener">Google</a>.'))
248
246
  end
249
247
  end
250
248
 
251
- context "When both noopener and noreferrer values are set to false in config" do
249
+ context 'When both noopener and noreferrer values are set to false in config' do
252
250
  let(:noopener) { false }
253
251
  let(:noreferrer) { false }
254
252
  let(:config_overrides) do
255
253
  {
256
- "target-blank" => {
257
- "add_css_classes" => false,
258
- "noopener" => noopener,
259
- "noreferrer" => noreferrer,
260
- },
254
+ 'target-blank' => {
255
+ 'add_css_classes' => false,
256
+ 'noopener' => noopener,
257
+ 'noreferrer' => noreferrer
258
+ }
261
259
  }
262
260
  end
263
261
 
264
- it "should not include the rel attribute values" do
262
+ it 'should not include the rel attribute values' do
265
263
  expect(post_with_external_markdown_link.output).to_not include(para('Link to <a href="https://google.com" target="_blank" rel="noopener noreferrer">Google</a>.'))
266
264
  end
267
265
 
268
- it "should not include the rel attribute noopener value" do
266
+ it 'should not include the rel attribute noopener value' do
269
267
  expect(post_with_external_markdown_link.output).to_not include(para('Link to <a href="https://google.com" target="_blank" rel="noreferrer">Google</a>.'))
270
268
  end
271
269
 
272
- it "should not include the rel attribute noreferrer value" do
270
+ it 'should not include the rel attribute noreferrer value' do
273
271
  expect(post_with_external_markdown_link.output).to_not include(para('Link to <a href="https://google.com" target="_blank" rel="noopener">Google</a>.'))
274
272
  end
275
273
 
276
- it "should not include any rel attributes" do
274
+ it 'should not include any rel attributes' do
277
275
  expect(post_with_external_markdown_link.output).to include(para('Link to <a href="https://google.com" target="_blank">Google</a>.'))
278
276
  end
279
277
  end
280
278
 
281
- context "When one additional rel attribute is added in config" do
282
- let(:rel_attribute) { "nofollow" }
279
+ context 'When one additional rel attribute is added in config' do
280
+ let(:rel_attribute) { 'nofollow' }
283
281
  let(:config_overrides) do
284
282
  {
285
- "target-blank" => {
286
- "add_css_classes" => false,
287
- "rel" => rel_attribute,
288
- },
283
+ 'target-blank' => {
284
+ 'add_css_classes' => false,
285
+ 'rel' => rel_attribute
286
+ }
289
287
  }
290
288
  end
291
289
 
292
- it "should add the extra rel attribute together with the default ones" do
290
+ it 'should add the extra rel attribute together with the default ones' do
293
291
  expect(post_with_external_markdown_link.output).to include(para('Link to <a href="https://google.com" target="_blank" rel="noopener noreferrer nofollow">Google</a>.'))
294
292
  end
295
293
  end
296
294
 
297
- context "When more than one additional rel attributes are added in config" do
298
- let(:rel_attribute) { "nofollow tag" }
295
+ context 'When more than one additional rel attributes are added in config' do
296
+ let(:rel_attribute) { 'nofollow tag' }
299
297
  let(:config_overrides) do
300
298
  {
301
- "target-blank" => {
302
- "add_css_classes" => false,
303
- "rel" => rel_attribute,
304
- },
299
+ 'target-blank' => {
300
+ 'add_css_classes' => false,
301
+ 'rel' => rel_attribute
302
+ }
305
303
  }
306
304
  end
307
305
 
308
- it "should add the extra rel attributes together with the default ones" do
306
+ it 'should add the extra rel attributes together with the default ones' do
309
307
  expect(post_with_external_markdown_link.output).to include(para('Link to <a href="https://google.com" target="_blank" rel="noopener noreferrer nofollow tag">Google</a>.'))
310
308
  end
311
309
  end
312
310
 
313
- context "When one extra rel attribute value are set in config and noopener is set to false" do
314
- let(:rel_attribute) { "nofollow" }
311
+ context 'When one extra rel attribute value are set in config and noopener is set to false' do
312
+ let(:rel_attribute) { 'nofollow' }
315
313
  let(:noopener) { false }
316
314
  let(:config_overrides) do
317
315
  {
318
- "target-blank" => {
319
- "add_css_classes" => false,
320
- "noopener" => noopener,
321
- "rel" => rel_attribute,
322
- },
316
+ 'target-blank' => {
317
+ 'add_css_classes' => false,
318
+ 'noopener' => noopener,
319
+ 'rel' => rel_attribute
320
+ }
323
321
  }
324
322
  end
325
323
 
326
- it "should the extra rel attribute value and not add the default noopener value" do
324
+ it 'should the extra rel attribute value and not add the default noopener value' do
327
325
  expect(post_with_external_markdown_link.output).to include(para('Link to <a href="https://google.com" target="_blank" rel="noreferrer nofollow">Google</a>.'))
328
326
  end
329
327
  end
330
328
 
331
- context "When more than one extra rel attribute values are set in config and noopener is set to false" do
332
- let(:rel_attribute) { "nofollow tag" }
329
+ context 'When more than one extra rel attribute values are set in config and noopener is set to false' do
330
+ let(:rel_attribute) { 'nofollow tag' }
333
331
  let(:noopener) { false }
334
332
  let(:config_overrides) do
335
333
  {
336
- "target-blank" => {
337
- "add_css_classes" => false,
338
- "noopener" => noopener,
339
- "rel" => rel_attribute,
340
- },
334
+ 'target-blank' => {
335
+ 'add_css_classes' => false,
336
+ 'noopener' => noopener,
337
+ 'rel' => rel_attribute
338
+ }
341
339
  }
342
340
  end
343
341
 
344
- it "should the extra rel attribute values and not add the default noopener value" do
342
+ it 'should the extra rel attribute values and not add the default noopener value' do
345
343
  expect(post_with_external_markdown_link.output).to include(para('Link to <a href="https://google.com" target="_blank" rel="noreferrer nofollow tag">Google</a>.'))
346
344
  end
347
345
  end
348
346
 
349
- context "When one extra rel attributes is set in config and both noopener and noreferer are set to false" do
350
- let(:rel_attribute) { "nofollow" }
347
+ context 'When one extra rel attributes is set in config and both noopener and noreferer are set to false' do
348
+ let(:rel_attribute) { 'nofollow' }
351
349
  let(:noopener) { false }
352
350
  let(:noreferrer) { false }
353
351
  let(:config_overrides) do
354
352
  {
355
- "target-blank" => {
356
- "add_css_classes" => false,
357
- "noopener" => noopener,
358
- "noreferrer" => noreferrer,
359
- "rel" => rel_attribute,
360
- },
353
+ 'target-blank' => {
354
+ 'add_css_classes' => false,
355
+ 'noopener' => noopener,
356
+ 'noreferrer' => noreferrer,
357
+ 'rel' => rel_attribute
358
+ }
361
359
  }
362
360
  end
363
361
 
364
- it "should add the extra rel attribute value and no default ones" do
362
+ it 'should add the extra rel attribute value and no default ones' do
365
363
  expect(post_with_external_markdown_link.output).to include(para('Link to <a href="https://google.com" target="_blank" rel="nofollow">Google</a>.'))
366
364
  end
367
365
  end
368
366
 
369
- context "When more than one extra rel attribute values are set in config and both noopener and noreferer are set to false" do
370
- let(:rel_attribute) { "nofollow tag" }
367
+ context 'When more than one extra rel attribute values are set in config and both noopener and noreferer are set to false' do
368
+ let(:rel_attribute) { 'nofollow tag' }
371
369
  let(:noopener) { false }
372
370
  let(:noreferrer) { false }
373
371
  let(:config_overrides) do
374
372
  {
375
- "target-blank" => {
376
- "add_css_classes" => false,
377
- "noopener" => noopener,
378
- "noreferrer" => noreferrer,
379
- "rel" => rel_attribute,
380
- },
373
+ 'target-blank' => {
374
+ 'add_css_classes' => false,
375
+ 'noopener' => noopener,
376
+ 'noreferrer' => noreferrer,
377
+ 'rel' => rel_attribute
378
+ }
381
379
  }
382
380
  end
383
381
 
384
- it "should add the extra rel attribute values and no default ones" do
382
+ it 'should add the extra rel attribute values and no default ones' do
385
383
  expect(post_with_external_markdown_link.output).to include(para('Link to <a href="https://google.com" target="_blank" rel="nofollow tag">Google</a>.'))
386
384
  end
387
385
  end
388
386
 
389
- context "When noopener is set to false in config but added to the rel config property" do
390
- let(:rel_attribute) { "noopener" }
387
+ context 'When noopener is set to false in config but added to the rel config property' do
388
+ let(:rel_attribute) { 'noopener' }
391
389
  let(:noopener) { false }
392
390
  let(:config_overrides) do
393
391
  {
394
- "target-blank" => {
395
- "add_css_classes" => false,
396
- "noopener" => noopener,
397
- "rel" => rel_attribute,
398
- },
392
+ 'target-blank' => {
393
+ 'add_css_classes' => false,
394
+ 'noopener' => noopener,
395
+ 'rel' => rel_attribute
396
+ }
399
397
  }
400
398
  end
401
399
 
402
- it "should still include the noopener rel attribute value" do
400
+ it 'should still include the noopener rel attribute value' do
403
401
  expect(post_with_external_markdown_link.output).to include(para('Link to <a href="https://google.com" target="_blank" rel="noreferrer noopener">Google</a>.'))
404
402
  end
405
403
  end
406
404
 
407
- context "When noopener is set to false in config but added t0 the rel config property alongside one more extra rel attribute value." do
408
- let(:rel_attribute) { "noopener nofollow" }
405
+ context 'When noopener is set to false in config but added t0 the rel config property alongside one more extra rel attribute value.' do
406
+ let(:rel_attribute) { 'noopener nofollow' }
409
407
  let(:noopener) { false }
410
408
  let(:config_overrides) do
411
409
  {
412
- "target-blank" => {
413
- "add_css_classes" => false,
414
- "noopener" => noopener,
415
- "rel" => rel_attribute,
416
- },
410
+ 'target-blank' => {
411
+ 'add_css_classes' => false,
412
+ 'noopener' => noopener,
413
+ 'rel' => rel_attribute
414
+ }
417
415
  }
418
416
  end
419
417
 
420
- it "should still include the noopener rel attribute value along the extra one" do
418
+ it 'should still include the noopener rel attribute value along the extra one' do
421
419
  expect(post_with_external_markdown_link.output).to include(para('Link to <a href="https://google.com" target="_blank" rel="noreferrer noopener nofollow">Google</a>.'))
422
420
  end
423
421
  end
@@ -425,22 +423,22 @@ RSpec.describe(Jekyll::TargetBlank) do
425
423
  private
426
424
 
427
425
  def post_with_layout_result
428
- <<-RESULT
429
- <!DOCTYPE HTML>
430
- <html lang="en-US">
431
- <head>
432
- <meta charset="UTF-8">
433
- <title>Post with external markdown link</title>
434
- <meta name="viewport" content="width=device-width,initial-scale=1">
435
- <link rel="stylesheet" href="/css/screen.css">
436
- </head>
437
- <body class="wrap">
438
- <div>Layout content started.</div>
439
- <p>Link to <a href="https://google.com" target="_blank" rel="noopener noreferrer">Google</a>.</p>
440
-
441
- <div>Layout content ended.</div>
442
- </body>
443
- </html>
426
+ <<~RESULT
427
+ <!DOCTYPE HTML>
428
+ <html lang="en-US">
429
+ <head>
430
+ <meta charset="UTF-8">
431
+ <title>Post with external markdown link</title>
432
+ <meta name="viewport" content="width=device-width,initial-scale=1">
433
+ <link rel="stylesheet" href="/css/screen.css">
434
+ </head>
435
+ <body class="wrap">
436
+ <div>Layout content started.</div>
437
+ <p>Link to <a href="https://google.com" target="_blank" rel="noopener noreferrer">Google</a>.</p>
438
+
439
+ <div>Layout content ended.</div>
440
+ </body>
441
+ </html>
444
442
  RESULT
445
443
  end
446
444
  end
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require File.expand_path("../lib/jekyll-target-blank.rb", __dir__)
3
+ require File.expand_path('../lib/jekyll-target-blank.rb', __dir__)
4
4
 
5
5
  RSpec.configure do |config|
6
- UNIT_FIXTURES_DIR = File.expand_path("fixtures/unit", __dir__)
6
+ UNIT_FIXTURES_DIR = File.expand_path('fixtures/unit', __dir__)
7
7
 
8
- INTEGRATION_FIXTURES_DIR = File.expand_path("fixtures/integration", __dir__)
8
+ INTEGRATION_FIXTURES_DIR = File.expand_path('fixtures/integration', __dir__)
9
9
 
10
10
  def unit_fixtures_dir(*paths)
11
11
  File.join(UNIT_FIXTURES_DIR, *paths)
@@ -16,7 +16,7 @@ RSpec.configure do |config|
16
16
  end
17
17
 
18
18
  def find_by_title(docs, title)
19
- docs.find { |d| d.data["title"] == title }
19
+ docs.find { |d| d.data['title'] == title }
20
20
  end
21
21
 
22
22
  # rspec-expectations config goes here. You can use an alternate
metadata CHANGED
@@ -1,43 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-target-blank
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Mifsud
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-12 00:00:00.000000000 Z
11
+ date: 2023-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '3.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: nokogiri
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
37
  - - "~>"
32
38
  - !ruby/object:Gem::Version
33
- version: 1.10.4
39
+ version: '1.10'
34
40
  type: :runtime
35
41
  prerelease: false
36
42
  version_requirements: !ruby/object:Gem::Requirement
37
43
  requirements:
38
44
  - - "~>"
39
45
  - !ruby/object:Gem::Version
40
- version: 1.10.4
46
+ version: '1.10'
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: bundler
43
49
  requirement: !ruby/object:Gem::Requirement
@@ -84,16 +90,30 @@ dependencies:
84
90
  name: rubocop
85
91
  requirement: !ruby/object:Gem::Requirement
86
92
  requirements:
87
- - - '='
93
+ - - "~>"
88
94
  - !ruby/object:Gem::Version
89
- version: '0.55'
95
+ version: '1'
90
96
  type: :development
91
97
  prerelease: false
92
98
  version_requirements: !ruby/object:Gem::Requirement
93
99
  requirements:
94
- - - '='
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '1'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rubocop-jekyll
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: 0.12.0
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
95
115
  - !ruby/object:Gem::Version
96
- version: '0.55'
116
+ version: 0.12.0
97
117
  description: Target Blank automatically changes the external links to open in a new
98
118
  browser for Jekyll sites.
99
119
  email:
@@ -157,8 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
177
  - !ruby/object:Gem::Version
158
178
  version: '0'
159
179
  requirements: []
160
- rubyforge_project:
161
- rubygems_version: 2.7.6
180
+ rubygems_version: 3.3.5
162
181
  signing_key:
163
182
  specification_version: 4
164
183
  summary: Target Blank automatically changes the external links to open in a new browser.