relaton-bib 1.12.6 → 1.12.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: ff390021e9158da2d1167e55d988d5dd920c7c9deba9e37838435c7f903d8852
4
- data.tar.gz: a0fd8d9929ff51df3604243e9dc28770d3b38721950e1886dc6995a90fa95b4c
3
+ metadata.gz: be4b986a04f391a2e552c13d8ee897e73c398f3acb27deda3bb203da627f585b
4
+ data.tar.gz: 05540e11934396b938df0c902d926c37b1c49c8aa215b7888827bb42d19d4042
5
5
  SHA512:
6
- metadata.gz: ec5005c4ae8ed03918f6933ed7329990977ab1347eb57626dfdaa1a9dddbd60eada93dc5dfdb365bb1ae06aaf60b8f7fd23ab75837022cbd1f3b6ce4009b797c
7
- data.tar.gz: 864a6000626e238808513075dc9343debc59a9440e5806092c4af5e90e38e8927e62b3767903e1fc6b65611c8af60e6c4c8b5cb697c91d666f7662501ce0b7ec
6
+ metadata.gz: f82094e85351832f3738216ce8ba72c68f7f26e9bcd7379cbe49b2e9a2bc0318ce1d4507462d3dbfed61ba57fc9bc692daf4998cbc84fb3bc2f54a14bed7e72a
7
+ data.tar.gz: 66de7c5f7b612c203694d6adacb0fdbf09dd34380f24bfe6e3d298f50d61d52af844f2803f8e75644839ce0b256726db55fc9058a649f9f42c8c3198f6e279ab
@@ -68,14 +68,17 @@ module RelatonBib
68
68
  # @return [String] encoded content
69
69
  #
70
70
  def encode(cnt) # rubocop:disable Metrics/MethodLength
71
- regex = /(?<prf>.*?)(?<xml><(?<tag>\w+)>.*<\/\k<tag>>)(?<sfx>.*)/m
71
+ return unless cnt
72
+
73
+ # regex = /(?<prf>.*?)(?<xml><(?<tag>\w+)>.*<\/\k<tag>>)(?<sfx>.*)/m
74
+ regex = /(?<prf>.*?)(?<xml><(?<tag>\w+)[^>]*(?:>.*<\/\k<tag>)?>)(?<rest>.*)/m
72
75
  if cnt.match(regex)
73
76
  prf = Regexp.last_match(:prf).lstrip
74
77
  xml = Regexp.last_match[:xml]
75
- sfx = Regexp.last_match(:sfx).rstrip
76
- parts = xml.scan(/\s*<(?<tago>\w+)>(?<cnt1>.*?)(?=<\/?\w+>)|(?<cnt2>.*?)<\/(?<tagc>\w+)>/)
78
+ rest = Regexp.last_match(:rest).rstrip
79
+ parts = xml.scan(/\s*<(?<tago>\w+)(?<attrs>[^>]*)>(?:(?<cnt1>.*?)(?=<\/\w+>|<\w+[^>]*>))?|(?<cnt2>.*?)<\/(?<tagc>\w+)>/)
77
80
  out = scan_xml parts
78
- "#{escp(prf)}#{out}#{escp(sfx)}"
81
+ "#{escp(prf)}#{out}#{encode(rest)}"
79
82
  else
80
83
  escp cnt
81
84
  end
@@ -84,22 +87,24 @@ module RelatonBib
84
87
  #
85
88
  # Scan XML and escape HTML entities.
86
89
  #
87
- # @param [Array<Array<String,nik>>] parts XML parts
90
+ # @param [Array<Array<String,nil>>] parts XML parts
88
91
  #
89
92
  # @return [String] output string
90
93
  #
91
94
  def scan_xml(parts) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength
92
95
  return "" unless parts.any? && parts.first[0]
93
96
 
94
- tago, cnt1, = parts.shift
95
- if tago && tago == parts.first[3]
96
- _, _, cnt2, tagc = parts.shift
97
- "<#{tago}>#{escp(cnt1)}#{escp(cnt2)}</#{tagc}>"
97
+ tago, attrs, cnt1, = parts.shift
98
+ if tago && tago == parts.first&.last
99
+ _, _, _, cnt2, tagc = parts.shift
100
+ "<#{tago}#{attrs}>#{escp(cnt1)}#{escp(cnt2)}</#{tagc}>"
101
+ elsif tago && attrs && attrs[-1] == "/"
102
+ "<#{tago}#{attrs}>"
98
103
  elsif tago
99
104
  inr = scan_xml parts
100
- _, _, cnt2, tagc = parts.shift
105
+ _, _, _, cnt2, tagc = parts.shift
101
106
  if tago == tagc
102
- "<#{tago}>#{escp(cnt1)}#{inr}#{escp(cnt2)}</#{tagc}>"
107
+ "<#{tago}#{attrs}>#{escp(cnt1)}#{inr}#{escp(cnt2)}</#{tagc}>"
103
108
  else
104
109
  "#{escp("<#{tago}>#{cnt1}")}#{inr}#{escp("#{cnt2}</#{tagc}>")}"
105
110
  end
@@ -68,7 +68,7 @@ module RelatonBib
68
68
  # @param [BibTeX::Entry] item bibtex entry
69
69
  #
70
70
  def to_bibtex(item)
71
- tl = titles.detect { |t| t.type == "main" }
71
+ tl = titles.detect { |t| t.type == "main" } || titles.first
72
72
  return unless tl
73
73
 
74
74
  item.title = tl.title.content
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "1.12.6".freeze
2
+ VERSION = "1.12.7".freeze
3
3
  end
@@ -472,7 +472,7 @@ module RelatonBib
472
472
  return unless ident
473
473
 
474
474
  FormattedRef.new(
475
- content: ident&.text, format: ident[:format],
475
+ content: ident.children.to_s, format: ident[:format],
476
476
  language: ident[:language], script: ident[:script]
477
477
  )
478
478
  end
data/lib/relaton_bib.rb CHANGED
@@ -40,7 +40,8 @@ module RelatonBib
40
40
  #
41
41
  # @param [String] date date string
42
42
  # @param [String] format format string
43
- # @param [Boolean] str return string or Date if true
43
+ # @param [Boolean] str return string if true in other case return Date
44
+ # @param [String, nil] outformat output format
44
45
  #
45
46
  # @return [Date, String] date object or formatted date string
46
47
  #
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.12.6
4
+ version: 1.12.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-08-11 00:00:00.000000000 Z
11
+ date: 2022-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug