nokogiri-html-ext 1.1.0 → 1.2.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
2
  SHA256:
3
- metadata.gz: 9b8892736803e577e871a87e8d2e51ba8c061b8a7ae3be4e4d991587ba460cef
4
- data.tar.gz: 2016820adf0b31271ef8da9351db33d5a158599c1c9cf5aa5712fc611ad52cf6
3
+ metadata.gz: 1a2f019c308dd4179f4846c1526d5c360bbc43883668ccf6c9b9164d953a7f36
4
+ data.tar.gz: ed1e5bc79cc94d68f70608e6e68dfdeb40b557a7abc8156b7364ebc0035f5773
5
5
  SHA512:
6
- metadata.gz: 8ee0db07a2cbd705d4361891d574ca569f4020dfb89a748305e595cdcf09ddbb37797686db4406767e42345ac918c91c7426e994dd95b7e8718ec26334e11fe3
7
- data.tar.gz: e730cac3f1271240ae3afc8c7af1b0a5773c103c909a66826cf9117660c86bd5bd7180ba82c7e3ea25c7b828a7c1817ae30405e5d12f19624c31eefa9b828ff5
6
+ metadata.gz: 4eec44e7836e196f72e0f8f5ec49a29fe4d78ff14696bce15ccd9f3b4256a563169ac7103138a910b00e3858461c7235683daefd3bf7e1d0c52b3e155bf8e30b
7
+ data.tar.gz: 75c20721391a9514ef486b6481a96aff535ba38c821e2bd764f8c4c955261e4653a0e5caacce0d6d4ad6ac4b6242a9b76316797e22601e6e4e46d997b119515d
data/README.md CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  [![Gem](https://img.shields.io/gem/v/nokogiri-html-ext.svg?logo=rubygems&style=for-the-badge)](https://rubygems.org/gems/nokogiri-html-ext)
6
6
  [![Downloads](https://img.shields.io/gem/dt/nokogiri-html-ext.svg?logo=rubygems&style=for-the-badge)](https://rubygems.org/gems/nokogiri-html-ext)
7
+ [![Source](https://img.shields.io/badge/get_it_on_codeberg-2185d0?labelColor=555&logo=codeberg&logoColor=fff&style=for-the-badge)](https://codeberg.org/jgarber/nokogiri-html-ext)
7
8
 
8
9
  ## Key features
9
10
 
@@ -15,7 +16,7 @@
15
16
 
16
17
  Before installing and using nokogiri-html-ext, you'll want to have [Ruby](https://www.ruby-lang.org) 2.7 (or newer) installed. Using a Ruby version managment tool like [rbenv](https://github.com/rbenv/rbenv), [chruby](https://github.com/postmodern/chruby), or [rvm](https://github.com/rvm/rvm) is recommended.
17
18
 
18
- nokogiri-html-ext is developed using Ruby 2.7.8 and is tested against additional Ruby versions using [Forgejo Actions](https://codeberg.org/jgarber/nokogiri-html-ext/actions).
19
+ nokogiri-html-ext is developed using Ruby 3.4 and is tested against additional Ruby versions using [Forgejo Actions](https://codeberg.org/jgarber/nokogiri-html-ext/actions).
19
20
 
20
21
  ## Installation
21
22
 
@@ -140,4 +141,4 @@ nokogiri-html-ext is written and maintained by [Jason Garber](https://sixtwothre
140
141
 
141
142
  ## License
142
143
 
143
- nokogiri-html-ext is freely available under the MIT License. Use it, learn from it, fork it, improve it, change it, tailor it to your needs.
144
+ nokogiri-html-ext is freely available under the [MIT License](https://opensource.org/license/MIT).
@@ -44,7 +44,7 @@ module Nokogiri
44
44
  # one and append it to the document's +<head>+ (creating that element if
45
45
  # necessary).
46
46
  #
47
- # @param url [String, #to_s]
47
+ # @param url [String]
48
48
  #
49
49
  # @return [String]
50
50
  def base_href=(url)
@@ -52,69 +52,75 @@ module Nokogiri
52
52
 
53
53
  set_metadata_element(base)
54
54
 
55
- base["href"] = url.to_s
55
+ base["href"] = url
56
56
  end
57
57
 
58
- # Convert a relative URL to an absolute URL.
58
+ # Convert a relative URL to an absolute URL based on the current document.
59
59
  #
60
- # @param url [String, #to_s]
60
+ # @param url [String]
61
61
  #
62
62
  # @return [String]
63
63
  def resolve_relative_url(url)
64
- url_str = url.to_s
64
+ strs = [doc_url_str, base_href, url]
65
+
66
+ strs.compact!
67
+ strs.map! { |str| uri_parser.escape(str) }
65
68
 
66
69
  # Escape each component before joining (Ruby's +URI.parse+ only likes
67
70
  # ASCII) and subsequently unescaping.
68
- uri_parser.unescape(
69
- uri_parser
70
- .join(*[doc_url_str, base_href, url_str].filter_map { |u| uri_parser.escape(u) unless u.nil? })
71
- .normalize
72
- .to_s
73
- )
71
+ uri_parser.unescape(uri_parser.join(*strs).normalize.to_s)
74
72
  rescue URI::InvalidComponentError, URI::InvalidURIError
75
- url_str
73
+ url
76
74
  end
77
75
 
78
76
  # Convert the document's relative URLs to absolute URLs.
79
77
  #
80
78
  # @return [self]
81
- #
82
- # rubocop:disable Style/PerlBackrefs
83
79
  def resolve_relative_urls!
84
- resolve_relative_urls_for(URL_ATTRIBUTES_MAP) { |value| resolve_relative_url(value.strip) }
80
+ resolve_relative_urls_for(URL_ATTRIBUTES_MAP) { |attribute| resolve_relative_url(attribute.strip) }
81
+
82
+ resolve_relative_urls_for(IMAGE_CANDIDATE_STRINGS_ATTRIBUTES_MAP) do |attribute|
83
+ candidates = attribute.split(/\s*,\s*/)
85
84
 
86
- resolve_relative_urls_for(IMAGE_CANDIDATE_STRINGS_ATTRIBUTES_MAP) do |value|
87
- value
88
- .split(",")
89
- .map { |candidate| candidate.strip.sub(/^(.+?)(\s+.+)?$/) { "#{resolve_relative_url($1)}#{$2}" } }
90
- .join(", ")
85
+ # rubocop:disable Style/PerlBackrefs
86
+ candidates.map! { |candidate| candidate.sub(/^(.+?)(\s+.+)?$/) { "#{resolve_relative_url($1)}#{$2}" } }
87
+ # rubocop:enable Style/PerlBackrefs
88
+
89
+ candidates.join(", ")
91
90
  end
92
91
 
93
92
  self
94
93
  end
95
- # rubocop:enable Style/PerlBackrefs
96
94
 
97
95
  private
98
96
 
99
97
  # +Nokogiri::HTML4::Document#url+ may be double-escaped if the parser
100
98
  # detects non-ASCII characters. For example, +https://[skull emoji].example+
101
99
  # is returned as +"https%3A//%25E2%2598%25A0%25EF%25B8%258F.example+.
100
+ #
101
+ # @return [String]
102
102
  def doc_url_str
103
103
  @doc_url_str ||= uri_parser.unescape(uri_parser.unescape(document.url)).strip
104
104
  end
105
105
 
106
- def resolve_relative_urls_for(attributes_map)
107
- attributes_map.each do |attribute, names|
108
- xpaths = names.map { |name| "//#{name}[@#{attribute}]" }
106
+ # @param attribute [String]
107
+ # @param names [Array<String>]
108
+ #
109
+ # @return [Array<String, Nokogiri::XML::NodeSet>]
110
+ def node_sets_from(attribute, names)
111
+ [attribute, xpath(*names.map { |name| "//#{name}[@#{attribute}]" })]
112
+ end
109
113
 
110
- xpath(*xpaths).each do |node|
111
- node[attribute] = yield node[attribute]
114
+ def resolve_relative_urls_for(attributes_map)
115
+ attributes_map
116
+ .map { |attribute, names| node_sets_from(attribute, names) }
117
+ .each do |attribute, node_set|
118
+ node_set.each { |node| node[attribute] = yield node[attribute] }
112
119
  end
113
- end
114
120
  end
115
121
 
116
122
  def uri_parser
117
- @uri_parser ||= URI::RFC2396_PARSER
123
+ @uri_parser ||= URI::RFC2396_Parser.new
118
124
  end
119
125
  end
120
126
  end
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  Gem::Specification.new do |spec|
4
- spec.required_ruby_version = ">= 3.1"
4
+ spec.required_ruby_version = ">= 2.7"
5
5
 
6
6
  spec.name = "nokogiri-html-ext"
7
- spec.version = "1.1.0"
7
+ spec.version = "1.2.0"
8
8
  spec.authors = ["Jason Garber"]
9
9
  spec.email = ["jason@sixtwothree.org"]
10
10
 
@@ -20,11 +20,13 @@ Gem::Specification.new do |spec|
20
20
  spec.require_paths = ["lib"]
21
21
 
22
22
  spec.metadata = {
23
- "bug_tracker_uri" => "#{spec.homepage}/issues",
24
- "changelog_uri" => "#{spec.homepage}/releases/tag/v#{spec.version}",
23
+ "bug_tracker_uri" => "#{spec.homepage}/issues",
24
+ "changelog_uri" => "#{spec.homepage}/releases/tag/v#{spec.version}",
25
+ "documentation_uri" => "https://rubydoc.info/gems/#{spec.name}/#{spec.version}",
26
+ "homepage_uri" => spec.homepage,
25
27
  "rubygems_mfa_required" => "true",
26
- "source_code_uri" => "#{spec.homepage}/src/tag/v#{spec.version}",
28
+ "source_code_uri" => "#{spec.homepage}/src/tag/v#{spec.version}",
27
29
  }
28
30
 
29
- spec.add_dependency "nokogiri", "~> 1.18"
31
+ spec.add_dependency "nokogiri", "~> 1.14"
30
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nokogiri-html-ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Garber
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: '1.18'
18
+ version: '1.14'
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: '1.18'
25
+ version: '1.14'
26
26
  description: Extend Nokogiri with several useful HTML-centric features.
27
27
  email:
28
28
  - jason@sixtwothree.org
@@ -41,9 +41,11 @@ licenses:
41
41
  - MIT
42
42
  metadata:
43
43
  bug_tracker_uri: https://codeberg.org/jgarber/nokogiri-html-ext/issues
44
- changelog_uri: https://codeberg.org/jgarber/nokogiri-html-ext/releases/tag/v1.1.0
44
+ changelog_uri: https://codeberg.org/jgarber/nokogiri-html-ext/releases/tag/v1.2.0
45
+ documentation_uri: https://rubydoc.info/gems/nokogiri-html-ext/1.2.0
46
+ homepage_uri: https://codeberg.org/jgarber/nokogiri-html-ext
45
47
  rubygems_mfa_required: 'true'
46
- source_code_uri: https://codeberg.org/jgarber/nokogiri-html-ext/src/tag/v1.1.0
48
+ source_code_uri: https://codeberg.org/jgarber/nokogiri-html-ext/src/tag/v1.2.0
47
49
  rdoc_options: []
48
50
  require_paths:
49
51
  - lib
@@ -51,7 +53,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
51
53
  requirements:
52
54
  - - ">="
53
55
  - !ruby/object:Gem::Version
54
- version: '3.1'
56
+ version: '2.7'
55
57
  required_rubygems_version: !ruby/object:Gem::Requirement
56
58
  requirements:
57
59
  - - ">="