relaton-bib 1.11.4 → 1.11.7

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: 66d703af6f525fba6b4cd25e054ab2f5f64e0d5040b75430c04296990a6a12ca
4
- data.tar.gz: c0c85e99f1e3b511fbc329b9b631349ed63afee1a1779a2147a1756e6dbf0559
3
+ metadata.gz: 9dffbd3f78b2468d48d601dd2cb1fa883c94d16d0b6c16a213219f85bbeef4c3
4
+ data.tar.gz: b04d3b2db08c74e0ba9599c36a35ebd00dc62501ce0847bbce046cbcc9892fa8
5
5
  SHA512:
6
- metadata.gz: d8f4ef1047ad4d3ab345c3d67079ca66e986b707871f243c11eb8c52ba5792202bf046bbcb1b3722d957d3e882e3ce645b30d9f5a422a8f8ccd2ac38eb7a7d12
7
- data.tar.gz: 2974513d8a823bc2efbbfe51e4bc9a88c7e7f77b3aa117e2835b5e13d6b33f366b0c15e7987afcb2dc1b5f5aa9f63d5a45e0df384ffb321132df30d2ed6ebe09
6
+ metadata.gz: adf68e1aa4a1c7f8fc719cf51bfc1b74d0e8ae49374647d70140021d5250908c52b0728219cb5eda9aed442eaf3f12674648ac1e61af744ffce345d0e81c7b91
7
+ data.tar.gz: 29690620969a335e11ab867163f33b530072cea8ceaab4d2980c60eadf14c9eaddb2976c02826cdf13ad677dd2ef781539419a014929481bce0e90274cc6dad7
@@ -10,23 +10,4 @@ on:
10
10
 
11
11
  jobs:
12
12
  rake:
13
- name: Test on Ruby ${{ matrix.ruby }} ${{ matrix.os }}
14
- runs-on: ${{ matrix.os }}
15
- continue-on-error: ${{ matrix.experimental }}
16
- strategy:
17
- fail-fast: false
18
- matrix:
19
- ruby: [ '3.0', '2.7', '2.6' ]
20
- os: [ ubuntu-latest, windows-latest, macos-latest ]
21
- experimental: [ false ]
22
- steps:
23
- - uses: actions/checkout@v2
24
- with:
25
- submodules: true
26
-
27
- - uses: ruby/setup-ruby@v1
28
- with:
29
- ruby-version: ${{ matrix.ruby }}
30
- bundler-cache: true
31
-
32
- - run: bundle exec rake
13
+ uses: relaton/support/.github/workflows/rake.yml@master
data/.rubocop.yml CHANGED
@@ -7,6 +7,6 @@ require: rubocop-rails
7
7
  inherit_from:
8
8
  - https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
9
9
  AllCops:
10
- TargetRubyVersion: 2.5
10
+ TargetRubyVersion: 2.6
11
11
  Rails:
12
12
  Enabled: false
@@ -37,7 +37,9 @@ module RelatonBib
37
37
  TYPES = %W[article book booklet conference manual proceedings presentation
38
38
  thesis techreport standard unpublished map electronic\sresource
39
39
  audiovisual film video broadcast graphic_work music patent
40
- inbook incollection inproceedings journal].freeze
40
+ inbook incollection inproceedings journal software website
41
+ webresource dataset archival social_media alert message
42
+ conversation misc].freeze
41
43
 
42
44
  # @return [TrueClass, FalseClass, NilClass]
43
45
  attr_accessor :all_parts
@@ -7,7 +7,7 @@ module RelatonBib
7
7
  FLAVOR = nil
8
8
 
9
9
  ORGNAMES = {
10
- "IEEE" => "Istitute of Electrical and Electronics Engineers",
10
+ "IEEE" => "Institute of Electrical and Electronics Engineers",
11
11
  "W3C" => "World Wide Web Consortium",
12
12
  "3GPP" => "3rd Generation Partnership Project",
13
13
  }.freeze
@@ -194,7 +194,7 @@ module RelatonBib
194
194
  # @return [Array<RelatonBib::FormattedString>]
195
195
  def abstracts(ref)
196
196
  ref.xpath("./front/abstract").map do |a|
197
- c = a.children.to_s.gsub(/\s*(<\/?)t(>)\s*/, '\1p\2')
197
+ c = a.inner_html.gsub(/\s*(<\/?)t(>)\s*/, '\1p\2')
198
198
  .gsub(/[\t\n]/, " ").squeeze " "
199
199
  FormattedString.new(content: c, language: language(ref), script: "Latn",
200
200
  format: "text/html")
@@ -56,12 +56,65 @@ 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.parent << escaped_content # .encode(xml: :text)
59
+ builder.parent.inner_html = encode content
60
60
  end
61
61
  end
62
62
 
63
- def escaped_content
64
- content.encode("UTF-8") # .gsub(/&/, "&amp;").gsub(/"/, "&quot;").gsub(/'/, "&apos;")
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
65
118
  end
66
119
 
67
120
  # @return [Hash]
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "1.11.4".freeze
2
+ VERSION = "1.11.7".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.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.4
4
+ version: 1.11.7
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-10 00:00:00.000000000 Z
11
+ date: 2022-06-01 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