relaton-bib 1.13.4 → 1.13.5

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: b16ceaaf0f86b9834a58c3a39008309f76d26de2347cb21fd2fef40cabc2fb0d
4
- data.tar.gz: 98348d372d278546dfa04579b80e6f7b1b9fa289ce794c728716cd73b97787e0
3
+ metadata.gz: 0caab7f3d9965a4a482826d13169b71667104909e0e88b5da5e0f26e63ae2949
4
+ data.tar.gz: 07fb1078b43b5490685e9219569fa304a0c3f9024145aad4a1406eec103fcfd6
5
5
  SHA512:
6
- metadata.gz: 97b3b1e729dfcae82196f3aff635c92a199cdae6ca0fa5c338321ef0f86bc3412212b83a3871c1aae7585e71d9db5bc6c6406327e1a7c43cb1f2ca1524e11ebb
7
- data.tar.gz: eab637a2d826cfa98d7d1cbda52509d05a59949ef7617ef04e066e1abbe4b9326d9a7313db64495925ee345fb1214f08b2381f66acce9a8b3e5e1a21ce95809d
6
+ metadata.gz: afdba375985986ad6be85d4491f4477c69bf61c8adf998684d037d8100e4298cc8edb7734b311f0a9adeb3252da08b961e6499263a814b6edcbb92919ebc98b0
7
+ data.tar.gz: ea84abe94491d7f43e29aca0b5a7a2334876f419d653ca6f2f340c05d1a5ae0c3cbee226731969d4489179767362547e0d3ce4474143e670f35bdd7b5fc03981
@@ -31,6 +31,62 @@ module RelatonBib
31
31
  super
32
32
  end
33
33
 
34
+ #
35
+ # Encode content.
36
+ #
37
+ # @param [String] cnt content
38
+ #
39
+ # @return [String] encoded content
40
+ #
41
+ def encode(cnt) # rubocop:disable Metrics/MethodLength
42
+ return unless cnt
43
+ return escp(cnt) unless format == "text/html"
44
+
45
+ parts = cnt.scan(%r{
46
+ <(?<tago>\w+)(?<attrs>[^>]*)> | # tag open
47
+ </(?<tagc>\w+)> | # tag close
48
+ (?<cmt><!--.*?-->) | # comment
49
+ (?<cnt>.+?)(?=<|$) # content
50
+ }x)
51
+ scan_xml parts
52
+ end
53
+
54
+ #
55
+ # Scan XML and escape HTML entities.
56
+ #
57
+ # @param [Array<Array<String,nil>>] parts XML parts
58
+ #
59
+ # @return [String] output string
60
+ #
61
+ def scan_xml(parts) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength
62
+ return "" unless parts.any?
63
+
64
+ out = ""
65
+ while parts.any? && (parts.first[3] || parts.first[4])
66
+ _, _, _, cmt, cnt = parts.shift
67
+ out += "#{cmt}#{escp(cnt)}"
68
+ end
69
+ unless out.empty?
70
+ out += scan_xml(parts) if parts.any? && parts.first[0]
71
+ return out
72
+ end
73
+
74
+ tago, attrs, tagc, = parts.shift
75
+ out = if tago && attrs && attrs[-1] == "/"
76
+ "<#{tago}#{attrs}>"
77
+ elsif tago
78
+ inr = scan_xml parts
79
+ _, _, tagc, = parts.shift
80
+ if tago == tagc
81
+ "<#{tago}#{attrs}>#{inr}</#{tagc}>"
82
+ else
83
+ "#{escp("<#{tago}#{attrs}>")}#{inr}#{escp("</#{tagc}>")}"
84
+ end
85
+ end
86
+ out += scan_xml(parts) if parts.any? && (parts.first[0] || parts.first[3] || parts.first[4])
87
+ out
88
+ end
89
+
34
90
  # @return [Hash]
35
91
  def to_hash
36
92
  hash = super
@@ -46,7 +102,7 @@ module RelatonBib
46
102
  # @return [String]
47
103
  def to_asciibib(prefix = "", count = 1, has_attrs = false)
48
104
  has_attrs ||= !(format.nil? || format.empty?)
49
- pref = prefix.empty? ? prefix : prefix + "."
105
+ pref = prefix.empty? ? prefix : "#{prefix}."
50
106
  # out = count > 1 ? "#{prefix}::\n" : ""
51
107
  out = super
52
108
  out += "#{pref}format:: #{format}\n" if format
@@ -76,51 +76,7 @@ module RelatonBib
76
76
  # @return [String] encoded content
77
77
  #
78
78
  def encode(cnt) # rubocop:disable Metrics/MethodLength
79
- return unless cnt
80
-
81
- parts = cnt.scan(%r{
82
- <(?<tago>\w+)(?<attrs>[^>]*)> | # tag open
83
- </(?<tagc>\w+)> | # tag close
84
- (?<cmt><!--.*?-->) | # comment
85
- (?<cnt>.+?)(?=<|$) # content
86
- }x)
87
- scan_xml parts
88
- end
89
-
90
- #
91
- # Scan XML and escape HTML entities.
92
- #
93
- # @param [Array<Array<String,nil>>] parts XML parts
94
- #
95
- # @return [String] output string
96
- #
97
- def scan_xml(parts) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength
98
- return "" unless parts.any?
99
-
100
- out = ""
101
- while parts.any? && (parts.first[3] || parts.first[4])
102
- _, _, _, cmt, cnt = parts.shift
103
- out += "#{cmt}#{escp(cnt)}"
104
- end
105
- unless out.empty?
106
- out += scan_xml(parts) if parts.any? && parts.first[0]
107
- return out
108
- end
109
-
110
- tago, attrs, tagc, = parts.shift
111
- out = if tago && attrs && attrs[-1] == "/"
112
- "<#{tago}#{attrs}>"
113
- elsif tago
114
- inr = scan_xml parts
115
- _, _, tagc, = parts.shift
116
- if tago == tagc
117
- "<#{tago}#{attrs}>#{inr}</#{tagc}>"
118
- else
119
- "#{escp("<#{tago}#{attrs}>")}#{inr}#{escp("</#{tagc}>")}"
120
- end
121
- end
122
- out += scan_xml(parts) if parts.any? && (parts.first[0] || parts.first[3] || parts.first[4])
123
- out
79
+ escp cnt
124
80
  end
125
81
 
126
82
  #
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "1.13.4".freeze
2
+ VERSION = "1.13.5".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-bib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.13.4
4
+ version: 1.13.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.