relaton-doi 2.1.3 → 2.1.4

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: 953aa1acd54cd1a21fb180ba132e24da1a1f9bb310496bfc4bc454e6d8d73621
4
- data.tar.gz: 3a60c3a21e9eb9b1b32bc62a57bdea14f8efbad2beddf490648dbc073c63cf7d
3
+ metadata.gz: 1f985958ac631dbcb90d8d435d4cd8d771ef1eb661096bd62d0aa05ea0739291
4
+ data.tar.gz: f0e7a7392db7ff8e082682c92afa15eabdad7230d35cb96335068f5ddaebd14f
5
5
  SHA512:
6
- metadata.gz: 3061d50b8b594725c9ae4ca531fe593ccda1d9825a51ea6fce7b046367684920e068470fbb8b95f3ef29a76469f3b5f9281938bf9adffadd573c046bfc9a526b
7
- data.tar.gz: 4a04be0cdde3781c793db668665c5a4d2f66530af19b505c646a9bb535a9276ab9984b09efee690aad0ff79a32ec128f6f48b5021cfabed7ac204783e18b5ec2
6
+ metadata.gz: e1474c8687f0772f77aa5a29cd5394722c12700a041bdb70cfab7fd2f84cb36d16f4cee676de366d262a2344075197b2fd6b18ea615c373495fc83f94756591d
7
+ data.tar.gz: fd1d94c456aed217671bd968d60815f5e06ed5d87bad05efd950f04fe43e6e1a46cbb1c8f8c28f8a57f90520894c384de29a29da7fd1a051533342ea5eac6fb8
data/CLAUDE.md CHANGED
@@ -43,9 +43,19 @@ Key classes in `lib/relaton/doi/`:
43
43
  - `TYPES` — maps 23 Crossref document types to Relaton types (e.g., `"book-chapter"` → `"inbook"`)
44
44
  - `REALATION_TYPES` — maps 37 Crossref relation types to Relaton relation types
45
45
  - `COUNTRIES` — `%w[USA]`, used by `parse_place` to distinguish country vs region
46
- - `TAG_RE`, `NS_PREFIX_RE`, `NS_PLACEHOLDER`, `SAVE_OPTS` — used by `normalize_markup` and
47
- `drop_namespaces` to remove the `jats:` and `xlink:` prefixes that Crossref puts on
48
- abstract and title markup. Relaton never declares those prefixes, so the output would
49
- otherwise fail every namespace-aware parser downstream, including relaton-render
50
- (metanorma-pdfa#99). The helper declares each prefix on a wrapper element, removes the
51
- namespaces with Nokogiri, and returns the content unchanged when it does not parse.
46
+
47
+ ## Crossref Markup Handling
48
+
49
+ `Parser#normalize_markup` decodes the HTML entities of raw Crossref content. Crossref
50
+ sometimes returns the JATS markup entity-encoded, and the relaton-bib sanitizer detects a
51
+ tag by a real `<`, so it would treat the encoded form as plain text.
52
+
53
+ `Bib::Title` and `Bib::Abstract` are `LocalizedMarkedUpString` subclasses, so their
54
+ `content=` setter runs `Relaton::Bib::Sanitizer` on assignment. Since relaton-bib 2.1.9 that
55
+ sanitizer also removes the `jats:` and `xlink:` namespace prefixes. Relaton never declares
56
+ those prefixes, so leaving them in place made the output fail every namespace-aware parser
57
+ downstream, including relaton-render (metanorma-pdfa#99). relaton-doi carried its own prefix
58
+ stripping until 2.1.9 shipped that fix, which is why the gemspec pins `~> 2.1.9`.
59
+
60
+ The sanitizer removes only the prefixes it could not resolve. A namespace that the content
61
+ declares itself survives, such as the MathML `xmlns` inside a `<stem>`.
@@ -73,22 +73,6 @@ module Relaton
73
73
  ATTRS = %i[type fetched title docidentifier date source abstract contributor place
74
74
  ext relation extent series medium].freeze
75
75
 
76
- # Matches content that looks like markup. Same shape as the tag detector
77
- # of `Relaton::Bib::Sanitizer`, so both agree on what to parse.
78
- TAG_RE = %r{<[a-zA-Z/!?]}
79
-
80
- # Captures a namespace prefix, on a tag or on an attribute: the `jats` of
81
- # `<jats:p>` and `</jats:italic>`, and the `xlink` of `xlink:href`.
82
- NS_PREFIX_RE = %r{(?:</?|\s)([A-Za-z_][\w.-]*):(?=[A-Za-z_])}
83
-
84
- # Placeholder namespace, used only to make an undeclared prefix parseable.
85
- NS_PLACEHOLDER = "urn:x-relaton-doi:%s".freeze
86
-
87
- # Serialize without the FORMAT option, so the round trip through the
88
- # parser does not add indentation to the content.
89
- SAVE_OPTS = Nokogiri::XML::Node::SaveOptions::AS_XML |
90
- Nokogiri::XML::Node::SaveOptions::NO_DECLARATION
91
-
92
76
  CROSSREF_API_URL = "https://api.crossref.org/works?query=%{query}&filter=%{filter}".freeze
93
77
  MAX_RETRIES = 3
94
78
 
@@ -230,62 +214,22 @@ module Relaton
230
214
  end
231
215
 
232
216
  #
233
- # Prepare raw Crossref markup for the relaton-bib sanitizer.
217
+ # Decode the HTML entities of raw Crossref content.
218
+ #
219
+ # Crossref sometimes returns the JATS markup as HTML entities. The
220
+ # relaton-bib sanitizer detects a tag by a real `<`, so it treats the
221
+ # encoded form as plain text and leaves it alone. Decode the entities
222
+ # here, and the sanitizer maps the markup to the basicdoc set.
234
223
  #
235
- # Crossref returns JATS markup. It sometimes encodes the markup as HTML
236
- # entities, and it prefixes the elements with the `jats:` namespace
237
- # prefix. The prefix is never declared in the Relaton output, so a
238
- # namespace-aware parser rejects the document, and the relaton-bib
239
- # sanitizer skips content that it cannot parse. Decode the entities and
240
- # remove the prefixes, so the sanitizer maps the elements to the
241
- # basicdoc set. See metanorma-pdfa#99.
224
+ # The sanitizer removes the `jats:` and `xlink:` namespace prefixes
225
+ # itself since relaton-bib 2.1.9, so this method no longer does.
242
226
  #
243
227
  # @param [String] str The raw Crossref content.
244
228
  #
245
- # @return [String] The content without entities and namespace prefixes.
229
+ # @return [String] The content without HTML entities.
246
230
  #
247
231
  def normalize_markup(str)
248
- cnt = CGI.unescapeHTML(str)
249
- cnt.match?(TAG_RE) ? drop_namespaces(cnt) : cnt
250
- end
251
-
252
- #
253
- # Remove the namespace prefixes from markup.
254
- #
255
- # Declare every prefix that the content uses on a wrapper element, so the
256
- # parser accepts the content, then let Nokogiri remove the namespaces from
257
- # both the elements and the attributes. Return the content unchanged when
258
- # it does not parse, which keeps the conservative behaviour of the
259
- # relaton-bib sanitizer for text that only looks like markup.
260
- #
261
- # @param [String] cnt The markup.
262
- #
263
- # @return [String] The markup without namespace prefixes.
264
- #
265
- def drop_namespaces(cnt)
266
- doc = parse_with_prefixes(cnt) or return cnt
267
-
268
- doc.remove_namespaces!
269
- doc.root.children.map do |c|
270
- c.to_xml encoding: "UTF-8", save_with: SAVE_OPTS
271
- end.join
272
- end
273
-
274
- #
275
- # Parse markup that uses undeclared namespace prefixes.
276
- #
277
- # @param [String] cnt The markup.
278
- #
279
- # @return [Nokogiri::XML::Document, nil] The document, or nil when the
280
- # content uses no prefix or does not parse.
281
- #
282
- def parse_with_prefixes(cnt)
283
- prefixes = cnt.scan(NS_PREFIX_RE).flatten.uniq - ["xmlns"]
284
- return if prefixes.empty?
285
-
286
- decl = prefixes.map { |p| %(xmlns:#{p}="#{format NS_PLACEHOLDER, p}") }
287
- doc = Nokogiri::XML "<r #{decl.join ' '}>#{cnt}</r>"
288
- doc if doc.errors.empty?
232
+ CGI.unescapeHTML(str)
289
233
  end
290
234
 
291
235
  #
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Relaton
4
4
  module Doi
5
- VERSION = "2.1.3"
5
+ VERSION = "2.1.4"
6
6
  end
7
7
  end
data/relaton-doi.gemspec CHANGED
@@ -34,7 +34,7 @@ Gem::Specification.new do |spec|
34
34
  # Uncomment to register a new dependency of your gem
35
35
  # spec.add_dependency "example-gem", "~> 1.0"
36
36
 
37
- spec.add_dependency "relaton-bib", "~> 2.1.8"
37
+ spec.add_dependency "relaton-bib", "~> 2.1.9"
38
38
  spec.add_dependency "relaton-bipm", "~> 2.1.0"
39
39
  spec.add_dependency "relaton-ieee", "~> 2.1.0"
40
40
  spec.add_dependency "relaton-ietf", "~> 2.1.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-doi
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
4
+ version: 2.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.1.8
19
+ version: 2.1.9
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.1.8
26
+ version: 2.1.9
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: relaton-bipm
29
29
  requirement: !ruby/object:Gem::Requirement