relaton-bib 1.11.5 → 1.11.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4879a622c8f133828b75abffc19166c9bc8047d9ecff25bbcd7b8cdc472acde4
4
- data.tar.gz: 27b37f70ddf22ded981996ac98ae58b284b99790ff0d1bb96a55c100fc08a850
3
+ metadata.gz: b67e36718ab80cde1c79a95f8233240641a49ef1faacadf94816d19f4d410b48
4
+ data.tar.gz: 63caef369d95e108ab09ecfb266db82528e76f29c3107f5ebb5b5a6ce3f6eab5
5
5
  SHA512:
6
- metadata.gz: 46fdb1f657ae745e28ac3e4b11fa17b4bd42a75fef5c9aca29b7834796df6f75bdff1f73ef81222784f9dae07ea200a821d8d3ad10d754f5ee75eebded5e8fd1
7
- data.tar.gz: 4a86ff51080029116ce9a0745f8411442fa6ce8da5a89b278a3a0dc38ffd4368fc36b516d9ea631662e74fc3704284889dfa1af758dba209520371824fe6321f
6
+ metadata.gz: 680f63959cde0cb1f151ae84afcf41696e52ba7c4777b84415b22f50a10c32d188e471a4c5d5bce2922326c76889a7402f3105c192004a4d94ed3aa1de8b07aa
7
+ data.tar.gz: c5d7df8e301a1518b1acdd2ca5dc5ae7bd88b24d0464b5e0428a41a446e660fac58f6658a992cbfc17369ca9986a7460cee0ffbfd606b690c53eb1df55f743e8
@@ -56,10 +56,67 @@ module RelatonBib
56
56
  else
57
57
  builder.parent["language"] = language.join(",") if language&.any?
58
58
  builder.parent["script"] = script.join(",") if script&.any?
59
- builder.text content
59
+ builder.parent.inner_html = encode content
60
60
  end
61
61
  end
62
62
 
63
+ #
64
+ # Encode content.
65
+ #
66
+ # @param [String] cnt content
67
+ #
68
+ # @return [String] encoded content
69
+ #
70
+ def encode(cnt) # rubocop:disable Metrics/MethodLength
71
+ regex = /(?<prf>.*?)(?<xml><(?<tag>\w+)>.*<\/\k<tag>>)(?<sfx>.*)/m
72
+ if cnt.match(regex)
73
+ prf = Regexp.last_match(:prf).lstrip
74
+ xml = Regexp.last_match[:xml]
75
+ sfx = Regexp.last_match(:sfx).rstrip
76
+ parts = xml.scan(/\s*<(?<tago>\w+)>(?<cnt1>.*?)(?=<\/?\w+>)|(?<cnt2>.*?)<\/(?<tagc>\w+)>/)
77
+ out = scan_xml parts
78
+ "#{escp(prf)}#{out}#{escp(sfx)}"
79
+ else
80
+ escp cnt
81
+ end
82
+ end
83
+
84
+ #
85
+ # Scan XML and escape HTML entities.
86
+ #
87
+ # @param [Array<Array<String,nik>>] parts XML parts
88
+ #
89
+ # @return [String] output string
90
+ #
91
+ def scan_xml(parts) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength
92
+ return "" unless parts.any? && parts.first[0]
93
+
94
+ tago, cnt1, = parts.shift
95
+ if tago && tago == parts.first[3]
96
+ _, _, cnt2, tagc = parts.shift
97
+ "<#{tago}>#{escp(cnt1)}#{escp(cnt2)}</#{tagc}>"
98
+ elsif tago
99
+ inr = scan_xml parts
100
+ _, _, cnt2, tagc = parts.shift
101
+ if tago == tagc
102
+ "<#{tago}>#{escp(cnt1)}#{inr}#{escp(cnt2)}</#{tagc}>"
103
+ else
104
+ "#{escp("<#{tago}>#{cnt1}")}#{inr}#{escp("#{cnt2}</#{tagc}>")}"
105
+ end
106
+ end + scan_xml(parts)
107
+ end
108
+
109
+ #
110
+ # Escope HTML entities.
111
+ #
112
+ # @param [String] str input string
113
+ #
114
+ # @return [String] output string
115
+ #
116
+ def escp(str)
117
+ HTMLEntities.new.encode str
118
+ end
119
+
63
120
  # @return [Hash]
64
121
  def to_hash # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
65
122
  if content.is_a? String
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "1.11.5".freeze
2
+ VERSION = "1.11.6".freeze
3
3
  end
@@ -354,7 +354,7 @@ module RelatonBib
354
354
  # @return [Array<RelatonBib::FormattedString>]
355
355
  def fetch_abstract(item)
356
356
  item.xpath("./abstract").map do |a|
357
- c = a.text.strip # children.to_s
357
+ c = a.inner_html(encoding: "utf-8").strip
358
358
  FormattedString.new(content: c, language: a[:language],
359
359
  script: a[:script], format: a[:format])
360
360
  end
data/lib/relaton_bib.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "forwardable"
2
2
  require "yaml"
3
+ require "htmlentities"
3
4
  require "relaton_bib/version"
4
5
  require "relaton_bib/deep_dup"
5
6
  require "relaton_bib/localized_string"
data/relaton-bib.gemspec CHANGED
@@ -35,6 +35,7 @@ Gem::Specification.new do |spec|
35
35
 
36
36
  spec.add_dependency "addressable"
37
37
  spec.add_dependency "bibtex-ruby"
38
+ spec.add_dependency "htmlentities"
38
39
  spec.add_dependency "iso639"
39
40
  spec.add_dependency "nokogiri", "~> 1.13.0"
40
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-bib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.5
4
+ version: 1.11.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-12 00:00:00.000000000 Z
11
+ date: 2022-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -164,6 +164,20 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: htmlentities
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: iso639
169
183
  requirement: !ruby/object:Gem::Requirement