isodoc 2.3.4.1 → 2.3.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: 4980e601b33bb1bb8504487e130f19138685d3c47697521eeb1eddbae3c66d8c
4
- data.tar.gz: 165e4fc208233ff0b3f46e19a30882ba188c8f375378342e2bc56533648b4218
3
+ metadata.gz: fa570f1c978671ee699be488fae2f0fe3835db689bfa7c5c0c1183e0a87f1854
4
+ data.tar.gz: 2ae14cde9d26714858c4240012d29e4483b22044d8112256627a709bc2704aee
5
5
  SHA512:
6
- metadata.gz: a1e86611d81ce64faa356b9fe2254c61c7826b1a1aa5cb865030caecc0016adf7023bafec83507913ce2f63dc6c66fa0404ab64fe77d30234476a3dff1ddda9f
7
- data.tar.gz: 6d716cc256f00fe3c5c1e5e55766d98b2eb6a0bb02eafe7b4544ee9d8c6179663297175c3549fee1ee3bbb88945b84fda7dda74fb30e071b615e3dce25da78b9
6
+ metadata.gz: 39d02fd071cd42d4e3771e1d6c6ed938024a2fd0842820d775b35cd5494371c31c09232b39c5526a921b81d660f9e2d9d3222e35c347b899d09c2fab8e35fed1
7
+ data.tar.gz: 3da1407baf7cd7a36e414925755436fbf4547f8f64da8c739c2e53edcda4e7a3d72a40efd5bb9be93bc9f9f28c626f59903b802e58b764f68e571e5172455398
data/isodoc.gemspec CHANGED
@@ -1,8 +1,6 @@
1
1
  # coding: utf-8
2
2
 
3
- lib = File.expand_path("lib", __dir__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require "isodoc/version"
3
+ require_relative "lib/isodoc/version"
6
4
 
7
5
  Gem::Specification.new do |spec|
8
6
  spec.name = "isodoc"
@@ -54,7 +52,6 @@ Gem::Specification.new do |spec|
54
52
  spec.add_development_dependency "guard", "~> 2.14"
55
53
  spec.add_development_dependency "guard-rspec", "~> 4.7"
56
54
  spec.add_development_dependency "rake", "~> 13.0"
57
- spec.add_development_dependency "rexml"
58
55
  spec.add_development_dependency "rspec", "~> 3.6"
59
56
  spec.add_development_dependency "rubocop", "~> 1.5.2"
60
57
  spec.add_development_dependency "sassc", "~> 2.4.0"
@@ -30,6 +30,18 @@
30
30
  padding-left: 50px;
31
31
  }
32
32
 
33
+ .h4 {
34
+ padding-left: 70px;
35
+ }
36
+
37
+ .h5 {
38
+ padding-left: 90px;
39
+ }
40
+
41
+ .h6 {
42
+ padding-left: 110px;
43
+ }
44
+
33
45
  .toc-active, li:hover {
34
46
  background: $colorLinkActiveBg;
35
47
  box-shadow: inset -5px 0px 10px -5px $colorLinkActiveBg !important;
@@ -38,7 +38,7 @@ module IsoDoc
38
38
  # scripts_override: Override scripts file for HTML
39
39
  # scripts_pdf: Scripts file for PDF (not used in XSLT PDF)
40
40
  # datauriimage: Encode images in HTML output as data URIs
41
- # break_up_urls_in_tables: whether to insert spaces in URLs in tables
41
+ # breakupurlsintables: whether to insert spaces in URLs in tables
42
42
  # every 40-odd chars
43
43
  # sectionsplit: split up HTML output on sections
44
44
  # bare: do not insert any prefatory material (coverpage, boilerplate)
@@ -74,7 +74,7 @@ module IsoDoc
74
74
  @olstyle = options[:olstyle]
75
75
  @datauriimage = options[:datauriimage]
76
76
  @suppressheadingnumbers = options[:suppressheadingnumbers]
77
- @break_up_urls_in_tables = options[:break_up_urls_in_tables] == "true"
77
+ @break_up_urls_in_tables = options[:breakupurlsintables]
78
78
  @sectionsplit = options[:sectionsplit] == "true"
79
79
  @suppressasciimathdup = options[:suppressasciimathdup] == "true"
80
80
  @bare = options[:bare]
@@ -151,9 +151,9 @@ module IsoDoc
151
151
  end
152
152
 
153
153
  def init_toc(options)
154
- @wordToClevels = options[:doctoclevels].to_i
154
+ @wordToClevels = (options[:doctoclevels] || options[:toclevels]).to_i
155
155
  @wordToClevels = 2 if @wordToClevels.zero?
156
- @htmlToClevels = options[:htmltoclevels].to_i
156
+ @htmlToClevels = (options[:htmltoclevels] || options[:toclevels]).to_i
157
157
  @htmlToClevels = 2 if @htmlToClevels.zero?
158
158
  @tocfigures = options[:tocfigures]
159
159
  @toctables = options[:toctables]
@@ -26,7 +26,7 @@ module IsoDoc
26
26
  end
27
27
 
28
28
  def table_long_strings_cleanup(docxml)
29
- return unless @break_up_urls_in_tables == true
29
+ return unless @break_up_urls_in_tables
30
30
 
31
31
  docxml.xpath("//td | //th").each do |d|
32
32
  d.traverse do |n|
@@ -2,23 +2,29 @@ module IsoDoc
2
2
  class Metadata
3
3
  def extract_person_names(authors)
4
4
  authors.reduce([]) do |ret, a|
5
- if a.at(ns("./name/completename"))
6
- ret << a.at(ns("./name/completename")).text
7
- else
8
- fn = a.xpath(ns("./name/forename"))
9
- .each_with_object([]) { |f, m| m << f.text }
10
- ret << "#{fn.join(' ')} #{a&.at(ns('./name/surname'))&.text}"
11
- end
5
+ ret << if a.at(ns("./name/completename"))
6
+ a.at(ns("./name/completename")).text
7
+ else
8
+ extract_person_name_from_components(a)
9
+ end
12
10
  end
13
11
  end
14
12
 
13
+ def extract_person_name_from_components(person)
14
+ name = person.xpath(ns("./name/forename"))
15
+ name.empty? and name = person.xpath(ns("./name/formatted-initials"))
16
+ out = name.map(&:text)
17
+ out << person.at(ns("./name/surname"))&.text
18
+ l10n(out.compact.join(" "))
19
+ end
20
+
15
21
  def extract_person_affiliations(authors)
16
22
  authors.reduce([]) do |m, a|
17
- name = a&.at(ns("./affiliation/organization/name"))&.text
18
- subdivs = a&.xpath(ns("./affiliation/organization/subdivision"))&.map(&:text)&.join(", ")
23
+ name = a.at(ns("./affiliation/organization/name"))&.text
24
+ subdivs = a.xpath(ns("./affiliation/organization/subdivision"))&.map(&:text)&.join(", ")
19
25
  name and subdivs and !subdivs.empty? and
20
26
  name = l10n("#{name}, #{subdivs}")
21
- location = a&.at(ns("./affiliation/organization/address/formattedAddress"))&.text
27
+ location = a.at(ns("./affiliation/organization/address/formattedAddress"))&.text
22
28
  m << (if !name.nil? && !location.nil?
23
29
  l10n("#{name}, #{location}")
24
30
  else
@@ -40,7 +46,7 @@ module IsoDoc
40
46
  end
41
47
 
42
48
  def personal_authors(isoxml)
43
- authors = isoxml.xpath(ns("//bibdata/contributor[role/@type = 'author' "\
49
+ authors = isoxml.xpath(ns("//bibdata/contributor[role/@type = 'author' " \
44
50
  "or xmlns:role/@type = 'editor']/person"))
45
51
  set(:authors, extract_person_names(authors))
46
52
  set(:authors_affiliations, extract_person_names_affiliations(authors))
@@ -61,10 +67,10 @@ module IsoDoc
61
67
  def agency1(xml)
62
68
  agency = ""
63
69
  publisher = []
64
- xml.xpath(ns("//bibdata/contributor[xmlns:role/@type = 'publisher']/"\
70
+ xml.xpath(ns("//bibdata/contributor[xmlns:role/@type = 'publisher']/" \
65
71
  "organization")).each do |org|
66
- name = org&.at(ns("./name"))&.text
67
- agency1 = org&.at(ns("./abbreviation"))&.text || name
72
+ name = org.at(ns("./name"))&.text
73
+ agency1 = org.at(ns("./abbreviation"))&.text || name
68
74
  publisher << name if name
69
75
  agency = iso?(org) ? "ISO/#{agency}" : "#{agency}#{agency1}/"
70
76
  end
@@ -79,7 +85,7 @@ module IsoDoc
79
85
  end
80
86
 
81
87
  def agency_addr(xml)
82
- a = xml.at(ns("//bibdata/contributor[xmlns:role/@type = 'publisher'][1]/"\
88
+ a = xml.at(ns("//bibdata/contributor[xmlns:role/@type = 'publisher'][1]/" \
83
89
  "organization")) or return
84
90
  { subdivision: "./subdivision", pub_phone: "./phone[not(@type = 'fax')]",
85
91
  pub_fax: "./phone[@type = 'fax']", pub_email: "./email",
@@ -0,0 +1,168 @@
1
+ require "metanorma-utils"
2
+
3
+ module IsoDoc
4
+ class PresentationXMLConvert < ::IsoDoc::Convert
5
+ def expand_citeas(text)
6
+ text.nil? and return text
7
+ HTMLEntities.new.decode(text.gsub(/&amp;#x/, "&#"))
8
+ end
9
+
10
+ def erefstack1(elem)
11
+ locs = elem.xpath(ns("./eref")).map do |e|
12
+ [e["connective"], e.to_xml]
13
+ end.flatten
14
+ ret = resolve_eref_connectives(locs)
15
+ elem.replace(ret[1])
16
+ end
17
+
18
+ def eref_localities(refs, target, node)
19
+ if can_conflate_eref_rendering?(refs)
20
+ l10n(", #{eref_localities_conflated(refs, target, node)}")
21
+ else
22
+ ret = resolve_eref_connectives(eref_locality_stacks(refs, target, node))
23
+ l10n(ret.join)
24
+ end
25
+ end
26
+
27
+ def eref_localities_conflated(refs, target, node)
28
+ droploc = node["droploc"]
29
+ node["droploc"] = true
30
+ ret = resolve_eref_connectives(eref_locality_stacks(refs, target,
31
+ node))
32
+ node.delete("droploc") unless droploc
33
+ eref_localities1(target,
34
+ refs.first.at(ns("./locality/@type")).text,
35
+ l10n(ret[1..-1].join), nil, node, @lang)
36
+ end
37
+
38
+ def can_conflate_eref_rendering?(refs)
39
+ (refs.size > 1 &&
40
+ refs.all? { |r| r.name == "localityStack" } &&
41
+ refs.all? { |r| r.xpath(ns("./locality")).size == 1 }) or return false
42
+
43
+ first = refs.first.at(ns("./locality/@type")).text
44
+ refs.all? do |r|
45
+ r.at(ns("./locality/@type")).text == first
46
+ end
47
+ end
48
+
49
+ def resolve_eref_connectives(locs)
50
+ locs = resolve_comma_connectives(locs)
51
+ locs = resolve_to_connectives(locs)
52
+ return locs if locs.size < 3
53
+
54
+ locs = locs.each_slice(2).with_object([]) do |a, m|
55
+ m << { conn: a[0], label: a[1] }
56
+ end
57
+ [", ", combine_conn(locs)]
58
+ end
59
+
60
+ def resolve_comma_connectives(locs)
61
+ locs1 = []
62
+ add = ""
63
+ until locs.empty?
64
+ if [", ", " "].include?(locs[1])
65
+ add += locs[0..2].join
66
+ locs.shift(3)
67
+ else
68
+ locs1 << add unless add.empty?
69
+ add = ""
70
+ locs1 << locs.shift
71
+ end
72
+ end
73
+ locs1 << add unless add.empty?
74
+ locs1
75
+ end
76
+
77
+ def resolve_to_connectives(locs)
78
+ locs1 = []
79
+ until locs.empty?
80
+ if locs[1] == "to"
81
+ locs1 << @i18n.chain_to.sub(/%1/, locs[0]).sub(/%2/, locs[2])
82
+ locs.shift(3)
83
+ else locs1 << locs.shift
84
+ end
85
+ end
86
+ locs1
87
+ end
88
+
89
+ def eref_locality_stacks(refs, target, node)
90
+ ret = refs.each_with_index.with_object([]) do |(r, i), m|
91
+ added = eref_locality_stack(r, i, target, node)
92
+ added.empty? and next
93
+ added.each { |a| m << a }
94
+ next if i == refs.size - 1
95
+
96
+ m << eref_locality_delimiter(r)
97
+ end
98
+ ret.empty? ? ret : [", "] + ret
99
+ end
100
+
101
+ def eref_locality_delimiter(ref)
102
+ if ref&.next_element&.name == "localityStack"
103
+ ref.next_element["connective"]
104
+ else locality_delimiter(ref)
105
+ end
106
+ end
107
+
108
+ def eref_locality_stack(ref, idx, target, node)
109
+ ret = []
110
+ if ref.name == "localityStack"
111
+ ref.elements.each_with_index do |rr, j|
112
+ l = eref_localities0(rr, j, target, node) or next
113
+
114
+ ret << l
115
+ ret << locality_delimiter(rr) unless j == ref.elements.size - 1
116
+ end
117
+ else
118
+ l = eref_localities0(ref, idx, target, node) and ret << l
119
+ end
120
+ ret[-1] == ", " and ret.pop
121
+ ret
122
+ end
123
+
124
+ def locality_delimiter(_loc)
125
+ ", "
126
+ end
127
+
128
+ def eref_localities0(ref, _idx, target, node)
129
+ if ref["type"] == "whole" then @i18n.wholeoftext
130
+ else
131
+ eref_localities1(target, ref["type"],
132
+ ref&.at(ns("./referenceFrom"))&.text,
133
+ ref&.at(ns("./referenceTo"))&.text, node, @lang)
134
+ end
135
+ end
136
+
137
+ def eref_localities1_zh(_target, type, from, upto, node)
138
+ ret = "第#{from}" if from
139
+ ret += "&#x2013;#{upto}" if upto
140
+ loc = eref_locality_populate(type, node)
141
+ ret += " #{loc}" unless node["droploc"] == "true"
142
+ ret
143
+ end
144
+
145
+ def eref_localities1(target, type, from, upto, node, lang = "en")
146
+ return nil if type == "anchor"
147
+
148
+ lang == "zh" and
149
+ return l10n(eref_localities1_zh(target, type, from, upto, node))
150
+ ret = eref_locality_populate(type, node)
151
+ ret += " #{from}" if from
152
+ ret += "&#x2013;#{upto}" if upto
153
+ l10n(ret)
154
+ end
155
+
156
+ def eref_locality_populate(type, node)
157
+ return "" if node["droploc"] == "true"
158
+
159
+ loc = type.sub(/^locality:/, "")
160
+ ret = @i18n.locality[loc] || loc
161
+ ret = case node["case"]
162
+ when "lowercase" then loc.downcase
163
+ else Metanorma::Utils.strict_capitalize_first(ret)
164
+ end
165
+ " #{ret}"
166
+ end
167
+ end
168
+ end
@@ -1,5 +1,4 @@
1
1
  require "metanorma-utils"
2
- require_relative "xrefs"
3
2
 
4
3
  module IsoDoc
5
4
  class PresentationXMLConvert < ::IsoDoc::Convert
@@ -19,10 +18,19 @@ module IsoDoc
19
18
  link, node)
20
19
  non_locality_elems(node).each(&:remove)
21
20
  node.add_child(cleanup_entities(link))
21
+ unnest_linkend(node)
22
22
  end
23
23
  # so not <origin bibitemid="ISO7301" citeas="ISO 7301">
24
24
  # <locality type="section"><reference>3.1</reference></locality></origin>
25
25
 
26
+ def unnest_linkend(node)
27
+ return unless node.at(ns("./xref[@nested]"))
28
+
29
+ node.xpath(ns("./xref[@nested]")).each { |x| x.delete("nested") }
30
+ node.xpath(ns("./location | ./locationStack")).each(&:remove)
31
+ node.replace(node.children)
32
+ end
33
+
26
34
  def xref_empty?(node)
27
35
  c1 = non_locality_elems(node).select { |c| !c.text? || /\S/.match(c) }
28
36
  c1.empty?
@@ -30,169 +38,6 @@ module IsoDoc
30
38
 
31
39
  def anchor_id_postprocess(node); end
32
40
 
33
- def expand_citeas(text)
34
- text.nil? and return text
35
- HTMLEntities.new.decode(text.gsub(/&amp;#x/, "&#"))
36
- end
37
-
38
- def erefstack1(elem)
39
- locs = elem.xpath(ns("./eref")).map do |e|
40
- [e["connective"], e.to_xml]
41
- end.flatten
42
- ret = resolve_eref_connectives(locs)
43
- elem.replace(ret[1])
44
- end
45
-
46
- def eref_localities(refs, target, node)
47
- if can_conflate_eref_rendering?(refs)
48
- l10n(", #{eref_localities_conflated(refs, target, node)}")
49
- else
50
- ret = resolve_eref_connectives(eref_locality_stacks(refs, target, node))
51
- l10n(ret.join)
52
- end
53
- end
54
-
55
- def eref_localities_conflated(refs, target, node)
56
- droploc = node["droploc"]
57
- node["droploc"] = true
58
- ret = resolve_eref_connectives(eref_locality_stacks(refs, target,
59
- node))
60
- node.delete("droploc") unless droploc
61
- eref_localities1(target,
62
- refs.first.at(ns("./locality/@type")).text,
63
- l10n(ret[1..-1].join), nil, node, @lang)
64
- end
65
-
66
- def can_conflate_eref_rendering?(refs)
67
- (refs.size > 1 &&
68
- refs.all? { |r| r.name == "localityStack" } &&
69
- refs.all? { |r| r.xpath(ns("./locality")).size == 1 }) or return false
70
-
71
- first = refs.first.at(ns("./locality/@type")).text
72
- refs.all? do |r|
73
- r.at(ns("./locality/@type")).text == first
74
- end
75
- end
76
-
77
- def resolve_eref_connectives(locs)
78
- locs = resolve_comma_connectives(locs)
79
- locs = resolve_to_connectives(locs)
80
- return locs if locs.size < 3
81
-
82
- locs = locs.each_slice(2).with_object([]) do |a, m|
83
- m << { conn: a[0], target: a[1] }
84
- end
85
- [", ", combine_conn(locs)]
86
- end
87
-
88
- def resolve_comma_connectives(locs)
89
- locs1 = []
90
- add = ""
91
- until locs.empty?
92
- if [", ", " "].include?(locs[1])
93
- add += locs[0..2].join
94
- locs.shift(3)
95
- else
96
- locs1 << add unless add.empty?
97
- add = ""
98
- locs1 << locs.shift
99
- end
100
- end
101
- locs1 << add unless add.empty?
102
- locs1
103
- end
104
-
105
- def resolve_to_connectives(locs)
106
- locs1 = []
107
- until locs.empty?
108
- if locs[1] == "to"
109
- locs1 << @i18n.chain_to.sub(/%1/, locs[0]).sub(/%2/, locs[2])
110
- locs.shift(3)
111
- else locs1 << locs.shift
112
- end
113
- end
114
- locs1
115
- end
116
-
117
- def eref_locality_stacks(refs, target, node)
118
- ret = refs.each_with_index.with_object([]) do |(r, i), m|
119
- added = eref_locality_stack(r, i, target, node)
120
- added.empty? and next
121
- added.each { |a| m << a }
122
- next if i == refs.size - 1
123
-
124
- m << eref_locality_delimiter(r)
125
- end
126
- ret.empty? ? ret : [", "] + ret
127
- end
128
-
129
- def eref_locality_delimiter(ref)
130
- if ref&.next_element&.name == "localityStack"
131
- ref.next_element["connective"]
132
- else locality_delimiter(ref)
133
- end
134
- end
135
-
136
- def eref_locality_stack(ref, idx, target, node)
137
- ret = []
138
- if ref.name == "localityStack"
139
- ref.elements.each_with_index do |rr, j|
140
- l = eref_localities0(rr, j, target, node) or next
141
-
142
- ret << l
143
- ret << locality_delimiter(rr) unless j == ref.elements.size - 1
144
- end
145
- else
146
- l = eref_localities0(ref, idx, target, node) and ret << l
147
- end
148
- ret[-1] == ", " and ret.pop
149
- ret
150
- end
151
-
152
- def locality_delimiter(_loc)
153
- ", "
154
- end
155
-
156
- def eref_localities0(ref, _idx, target, node)
157
- if ref["type"] == "whole" then @i18n.wholeoftext
158
- else
159
- eref_localities1(target, ref["type"],
160
- ref&.at(ns("./referenceFrom"))&.text,
161
- ref&.at(ns("./referenceTo"))&.text, node, @lang)
162
- end
163
- end
164
-
165
- def eref_localities1_zh(_target, type, from, upto, node)
166
- ret = "第#{from}" if from
167
- ret += "&#x2013;#{upto}" if upto
168
- loc = eref_locality_populate(type, node)
169
- ret += " #{loc}" unless node["droploc"] == "true"
170
- ret
171
- end
172
-
173
- def eref_localities1(target, type, from, upto, node, lang = "en")
174
- return nil if type == "anchor"
175
-
176
- lang == "zh" and
177
- return l10n(eref_localities1_zh(target, type, from, upto, node))
178
- ret = eref_locality_populate(type, node)
179
- ret += " #{from}" if from
180
- ret += "&#x2013;#{upto}" if upto
181
- l10n(ret)
182
- end
183
-
184
- def eref_locality_populate(type, node)
185
- return "" if node["droploc"] == "true"
186
-
187
- loc = type.sub(/^locality:/, "")
188
- ret = @i18n.locality[loc] || loc
189
- ret = case node["case"]
190
- when "lowercase" then loc.downcase
191
- else Metanorma::Utils.strict_capitalize_first(ret)
192
- end
193
- " #{ret}"
194
- end
195
-
196
41
  def xref(docxml)
197
42
  docxml.xpath(ns("//xref")).each { |f| xref1(f) }
198
43
  docxml.xpath(ns("//xref//xref")).each { |f| f.replace(f.children) }
@@ -200,6 +45,7 @@ module IsoDoc
200
45
 
201
46
  def eref(docxml)
202
47
  docxml.xpath(ns("//eref")).each { |f| xref1(f) }
48
+ docxml.xpath(ns("//eref//xref")).each { |f| f.replace(f.children) }
203
49
  docxml.xpath(ns("//erefstack")).each { |f| erefstack1(f) }
204
50
  end
205
51
 
@@ -209,6 +55,9 @@ module IsoDoc
209
55
 
210
56
  def quotesource(docxml)
211
57
  docxml.xpath(ns("//quote/source")).each { |f| xref1(f) }
58
+ docxml.xpath(ns("//quote/source//xref")).each do |f|
59
+ f.replace(f.children)
60
+ end
212
61
  end
213
62
 
214
63
  def xref1(node)
@@ -24,7 +24,7 @@ module IsoDoc
24
24
  concept1_linkmention(ref, render, opts)
25
25
  concept1_ref(node, ref, opts)
26
26
  concept1_nonital(node, opts)
27
- node.replace(node.children)
27
+ node.replace(node.children.to_xml.strip)
28
28
  end
29
29
 
30
30
  def concept1_nonital(node, opts)
@@ -54,8 +54,8 @@ module IsoDoc
54
54
  return ref.remove if opts[:ref] == "false"
55
55
 
56
56
  r = concept1_ref_content(ref)
57
- ref = r.at("./descendant-or-self::xmlns:xref | "\
58
- "./descendant-or-self::xmlns:eref | "\
57
+ ref = r.at("./descendant-or-self::xmlns:xref | " \
58
+ "./descendant-or-self::xmlns:eref | " \
59
59
  "./descendant-or-self::xmlns:termref")
60
60
  %w(xref eref).include? ref&.name and get_linkend(ref)
61
61
  if opts[:linkref] == "false" && %w(xref eref).include?(ref&.name)
@@ -82,10 +82,10 @@ module IsoDoc
82
82
  ref = node.at(ns("./xref | ./eref | ./termref"))
83
83
  label = @i18n.relatedterms[node["type"]].upcase
84
84
  if p && ref
85
- node.replace(l10n("<p><strong>#{label}:</strong> "\
85
+ node.replace(l10n("<p><strong>#{label}:</strong> " \
86
86
  "<em>#{p.to_xml}</em> (#{ref.to_xml})</p>"))
87
87
  else
88
- node.replace(l10n("<p><strong>#{label}:</strong> "\
88
+ node.replace(l10n("<p><strong>#{label}:</strong> " \
89
89
  "<strong>**RELATED TERM NOT FOUND**</strong></p>"))
90
90
  end
91
91
  end
@@ -125,7 +125,7 @@ module IsoDoc
125
125
 
126
126
  def designation1(desgn)
127
127
  s = desgn.at(ns("./termsource"))
128
- name = desgn.at(ns("./expression/name | ./letter-symbol/name | "\
128
+ name = desgn.at(ns("./expression/name | ./letter-symbol/name | " \
129
129
  "./graphical-symbol")) or return
130
130
 
131
131
  designation_annotate(desgn, name)
@@ -41,8 +41,7 @@ module IsoDoc
41
41
  if node["style"] == "basic" && t then t
42
42
  elsif node["style"] == "full" && t
43
43
  l10n("#{x}, #{t}")
44
- else
45
- x
44
+ else x
46
45
  end
47
46
  end
48
47
 
@@ -58,15 +57,20 @@ module IsoDoc
58
57
  linkend = if can_conflate_xref_rendering?(locs)
59
58
  combine_conflated_xref_locations(locs)
60
59
  else
61
- out = locs.each { |l| l[:target] = anchor_linkend1(l[:node]) }
60
+ out = locs.each { |l| l[:label] = anchor_linkend1(l[:node]) }
62
61
  l10n(combine_conn(out))
63
62
  end
64
63
  capitalise_xref(node, linkend, anchor_value(node["target"]))
65
64
  end
66
65
 
67
66
  def combine_conflated_xref_locations(locs)
68
- out = locs.each { |l| l[:target] = anchor_value(l[:target]) }
69
- ret = l10n("#{locs.first[:elem]} #{combine_conn(out)}")
67
+ out = locs.each { |l| l[:label] = anchor_value(l[:target]) }
68
+ label = @i18n.inflect(locs.first[:elem], number: "pl")
69
+ ret = l10n("#{label} #{combine_conn(out)}")
70
+ combine_conflated_xref_locations_container(locs, ret)
71
+ end
72
+
73
+ def combine_conflated_xref_locations_container(locs, ret)
70
74
  container = @xrefs.anchor(locs.first[:node]["target"], :container,
71
75
  false)
72
76
  prefix_container?(container, locs.first[:node]) and
@@ -85,15 +89,23 @@ module IsoDoc
85
89
  end
86
90
  end
87
91
 
92
+ def loc2xref(entry)
93
+ if entry[:target]
94
+ "<xref nested='true' target='#{entry[:target]}'>#{entry[:label]}</xref>"
95
+ else
96
+ entry[:label]
97
+ end
98
+ end
99
+
88
100
  def combine_conn(list)
89
- return list.first[:target] if list.size == 1
101
+ return list.first[:label] if list.size == 1
90
102
 
91
103
  if list[1..-1].all? { |l| l[:conn] == "and" }
92
- @i18n.boolean_conj(list.map { |l| l[:target] }, "and")
104
+ @i18n.boolean_conj(list.map { |l| loc2xref(l) }, "and")
93
105
  elsif list[1..-1].all? { |l| l[:conn] == "or" }
94
- @i18n.boolean_conj(list.map { |l| l[:target] }, "or")
106
+ @i18n.boolean_conj(list.map { |l| loc2xref(l) }, "or")
95
107
  else
96
- ret = list[0][:target]
108
+ ret = loc2xref(list[0])
97
109
  list[1..-1].each { |l| ret = i18n_chain_boolean(ret, l) }
98
110
  ret
99
111
  end
@@ -101,7 +113,7 @@ module IsoDoc
101
113
 
102
114
  def i18n_chain_boolean(value, entry)
103
115
  @i18n.send("chain_#{entry[:conn]}").sub(/%1/, value)
104
- .sub(/%2/, entry[:target])
116
+ .sub(/%2/, loc2xref(entry))
105
117
  end
106
118
 
107
119
  def can_conflate_xref_rendering?(locs)
@@ -1,5 +1,7 @@
1
1
  require_relative "presentation_function/block"
2
2
  require_relative "presentation_function/terms"
3
+ require_relative "presentation_function/xrefs"
4
+ require_relative "presentation_function/erefs"
3
5
  require_relative "presentation_function/inline"
4
6
  require_relative "presentation_function/math"
5
7
  require_relative "presentation_function/section"
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "2.3.4.1".freeze
2
+ VERSION = "2.3.6".freeze
3
3
  end
@@ -26,41 +26,33 @@ module IsoDoc
26
26
  def insert_toc(intro, docxml, level)
27
27
  toc = ""
28
28
  toc += make_WordToC(docxml, level)
29
- toc += make_TableWordToC(docxml)
30
- toc += make_FigureWordToC(docxml)
31
- toc += make_RecommendationWordToC(docxml)
29
+ toc += make_table_word_toc(docxml)
30
+ toc += make_figure_word_toc(docxml)
31
+ toc += make_recommendation_word_toc(docxml)
32
32
  intro.sub(/WORDTOC/, toc)
33
33
  end
34
34
 
35
35
  def word_toc_entry(toclevel, heading)
36
36
  bookmark = bookmarkid # Random.rand(1000000000)
37
37
  <<~TOC
38
- <p class="MsoToc#{toclevel}"><span class="MsoHyperlink"><span
39
- lang="EN-GB" style='mso-no-proof:yes'>
40
- <a href="#_Toc#{bookmark}">#{heading}<span lang="EN-GB"
41
- class="MsoTocTextSpan">
38
+ <p class="MsoToc#{toclevel}"><span class="MsoHyperlink"><span lang="EN-GB" style='mso-no-proof:yes'>
39
+ <a href="#_Toc#{bookmark}">#{heading}<span lang="EN-GB" class="MsoTocTextSpan">
42
40
  <span style='mso-tab-count:1 dotted'>. </span>
43
41
  </span><span lang="EN-GB" class="MsoTocTextSpan">
44
42
  <span style='mso-element:field-begin'></span></span>
45
- <span lang="EN-GB"
46
- class="MsoTocTextSpan"> PAGEREF _Toc#{bookmark} \\h </span>
47
- <span lang="EN-GB" class="MsoTocTextSpan"><span
48
- style='mso-element:field-separator'></span></span><span
43
+ <span lang="EN-GB" class="MsoTocTextSpan"> PAGEREF _Toc#{bookmark} \\h </span>
44
+ <span lang="EN-GB" class="MsoTocTextSpan"><span style='mso-element:field-separator'></span></span><span
49
45
  lang="EN-GB" class="MsoTocTextSpan">1</span>
50
- <span lang="EN-GB"
51
- class="MsoTocTextSpan"></span><span
52
- lang="EN-GB" class="MsoTocTextSpan"><span
53
- style='mso-element:field-end'></span></span></a></span></span></p>
46
+ <span lang="EN-GB" class="MsoTocTextSpan"></span><span
47
+ lang="EN-GB" class="MsoTocTextSpan"><span style='mso-element:field-end'></span></span></a></span></span></p>
54
48
 
55
49
  TOC
56
50
  end
57
51
 
58
52
  def word_toc_preface(level)
59
- <<~TOC.freeze
60
- <span lang="EN-GB"><span
61
- style='mso-element:field-begin'></span><span
62
- style='mso-spacerun:yes'>&#xA0;</span>TOC
63
- \\o "1-#{level}" \\h \\z \\u <span
53
+ <<~TOC
54
+ <span lang="EN-GB"><span style='mso-element:field-begin'></span><span
55
+ style='mso-spacerun:yes'>&#xA0;</span>TOC \\o "1-#{level}" \\h \\z \\u <span
64
56
  style='mso-element:field-separator'></span></span>
65
57
  TOC
66
58
  end
@@ -82,63 +74,96 @@ module IsoDoc
82
74
  %{\\1#{word_toc_preface(level)}}) + WORD_TOC_SUFFIX1
83
75
  end
84
76
 
85
- WORD_TOC_RECOMMENDATION_PREFACE1 = <<~TOC.freeze
86
- <span lang="EN-GB"><span
87
- style='mso-element:field-begin'></span><span
88
- style='mso-spacerun:yes'>&#xA0;</span>TOC
89
- \\h \\z \\t "RecommendationTitle,RecommendationTestTitle,recommendationtitle,recommendationtesttitle"
90
- <span style='mso-element:field-separator'></span></span>
91
- TOC
77
+ # inheriting gems need to add native Word name of style, if different
78
+ # including both CSS style name and human readable style name.
79
+ # Any human readable style name needs to come first for the Word template
80
+ # to work in regenerating the ToC
81
+ def table_toc_class
82
+ %w(TableTitle tabletitle)
83
+ end
92
84
 
93
- WORD_TOC_TABLE_PREFACE1 = <<~TOC.freeze
94
- <span lang="EN-GB"><span
95
- style='mso-element:field-begin'></span><span
96
- style='mso-spacerun:yes'>&#xA0;</span>TOC
97
- \\h \\z \\t "TableTitle,tabletitle" <span
98
- style='mso-element:field-separator'></span></span>
99
- TOC
85
+ def figure_toc_class
86
+ %w(FigureTitle figuretitle)
87
+ end
100
88
 
101
- WORD_TOC_FIGURE_PREFACE1 = <<~TOC.freeze
102
- <span lang="EN-GB"><span
103
- style='mso-element:field-begin'></span><span
104
- style='mso-spacerun:yes'>&#xA0;</span>TOC
105
- \\h \\z \\t "FigureTitle,figuretitle" <span
106
- style='mso-element:field-separator'></span></span>
107
- TOC
89
+ def reqt_toc_class
90
+ %w(RecommendationTitle RecommendationTestTitle
91
+ recommendationtitle recommendationtesttitle)
92
+ end
108
93
 
109
- def make_TableWordToC(docxml)
110
- (docxml.at("//p[@class = 'TableTitle']") && @toctablestitle) or
111
- return ""
94
+ def toc_word_class_list(classes)
95
+ classes.map do |x|
96
+ / /.match?(x) ? %(&quot;#{x}&quot;) : x
97
+ end.join(",")
98
+ end
99
+
100
+ def word_toc_reqt_preface1
101
+ <<~TOC
102
+ <span lang="EN-GB"><span style='mso-element:field-begin'></span><span
103
+ style='mso-spacerun:yes'>&#xA0;</span>TOC \\h \\z \\t #{toc_word_class_list reqt_toc_class}
104
+ <span style='mso-element:field-separator'></span></span>
105
+ TOC
106
+ end
107
+
108
+ def word_toc_table_preface1
109
+ <<~TOC
110
+ <span lang="EN-GB"><span style='mso-element:field-begin'></span><span style='mso-spacerun:yes'>&#xA0;</span>TOC
111
+ \\h \\z \\t #{toc_word_class_list table_toc_class} <span style='mso-element:field-separator'></span></span>
112
+ TOC
113
+ end
114
+
115
+ def word_toc_figure_preface1
116
+ <<~TOC
117
+ <span lang="EN-GB"><span style='mso-element:field-begin'></span><span style='mso-spacerun:yes'>&#xA0;</span>TOC
118
+ \\h \\z \\t #{toc_word_class_list figure_toc_class} <span style='mso-element:field-separator'></span></span>
119
+ TOC
120
+ end
121
+
122
+ def table_toc_xpath
123
+ attr = table_toc_class.map { |x| "@class = '#{x}'" }
124
+ "//p[#{attr.join(' or ')}]"
125
+ end
126
+
127
+ def make_table_word_toc(docxml)
128
+ (docxml.at(table_toc_xpath) && @toctablestitle) or return ""
112
129
  toc = %{<p class="TOCTitle">#{@toctablestitle}</p>}
113
- docxml.xpath("//p[@class = 'TableTitle']").each do |h|
130
+ docxml.xpath(table_toc_xpath).each do |h|
114
131
  toc += word_toc_entry(1, header_strip(h))
115
132
  end
116
133
  toc.sub(/(<p class="MsoToc1">)/,
117
- %{\\1#{WORD_TOC_TABLE_PREFACE1}}) + WORD_TOC_SUFFIX1
134
+ %{\\1#{word_toc_table_preface1}}) + WORD_TOC_SUFFIX1
135
+ end
136
+
137
+ def figure_toc_xpath
138
+ attr = figure_toc_class.map { |x| "@class = '#{x}'" }
139
+ "//p[#{attr.join(' or ')}]"
118
140
  end
119
141
 
120
- def make_FigureWordToC(docxml)
121
- (docxml.at("//p[@class = 'FigureTitle']") && @tocfigurestitle) or
122
- return ""
142
+ def make_figure_word_toc(docxml)
143
+ (docxml.at(figure_toc_xpath) && @tocfigurestitle) or return ""
123
144
  toc = %{<p class="TOCTitle">#{@tocfigurestitle}</p>}
124
- docxml.xpath("//p[@class = 'FigureTitle']").each do |h|
145
+ docxml.xpath(figure_toc_xpath).each do |h|
125
146
  toc += word_toc_entry(1, header_strip(h))
126
147
  end
127
148
  toc.sub(/(<p class="MsoToc1">)/,
128
- %{\\1#{WORD_TOC_FIGURE_PREFACE1}}) + WORD_TOC_SUFFIX1
149
+ %{\\1#{word_toc_figure_preface1}}) + WORD_TOC_SUFFIX1
150
+ end
151
+
152
+ def reqt_toc_xpath
153
+ attr = reqt_toc_class.map { |x| "@class = '#{x}'" }
154
+ "//p[#{attr.join(' or ')}]"
129
155
  end
130
156
 
131
- def make_RecommendationWordToC(docxml)
132
- (docxml.at("//p[@class = 'RecommendationTitle']") &&
133
- @tocrecommendationstitle) or return ""
157
+ def make_recommendation_word_toc(docxml)
158
+ (docxml.at(reqt_toc_xpath) && @tocrecommendationstitle) or return ""
134
159
  toc = %{<p class="TOCTitle">#{@tocrecommendationstitle}</p>}
135
- docxml.xpath("//p[@class = 'RecommendationTitle' or @class = 'RecommendationTestTitle']").sort_by do |h|
160
+ docxml.xpath(reqt_toc_xpath).sort_by do |h|
136
161
  recommmendation_sort_key(h.text)
137
162
  end.each do |h|
138
163
  toc += word_toc_entry(1, header_strip(h))
139
164
  end
140
165
  toc.sub(/(<p class="MsoToc1">)/,
141
- %{\\1#{WORD_TOC_RECOMMENDATION_PREFACE1}}) + WORD_TOC_SUFFIX1
166
+ %{\\1#{word_toc_reqt_preface1}}) + WORD_TOC_SUFFIX1
142
167
  end
143
168
 
144
169
  def recommmendation_sort_key(header)
@@ -160,7 +185,7 @@ module IsoDoc
160
185
 
161
186
  def authority_cleanup1(docxml, klass)
162
187
  dest = docxml.at("//div[@id = 'boilerplate-#{klass}-destination']")
163
- auth = docxml.at("//div[@id = 'boilerplate-#{klass}' "\
188
+ auth = docxml.at("//div[@id = 'boilerplate-#{klass}' " \
164
189
  "or @class = 'boilerplate-#{klass}']")
165
190
  auth&.xpath(".//h1[not(text())] | .//h2[not(text())]")&.each(&:remove)
166
191
  auth&.xpath(".//h1 | .//h2")&.each do |h|
@@ -218,7 +243,7 @@ module IsoDoc
218
243
  docxml.xpath("//div[@class = '#{sect}']//br[@orientation]").reverse
219
244
  .each_with_index do |br, i|
220
245
  @landscapestyle +=
221
- "\ndiv.#{sect}_#{i} {page:#{sect}"\
246
+ "\ndiv.#{sect}_#{i} {page:#{sect}" \
222
247
  "#{br['orientation'] == 'landscape' ? 'L' : 'P'};}\n"
223
248
  split_at_section_break(docxml, sect, br, i)
224
249
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isodoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.4.1
4
+ version: 2.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-07 00:00:00.000000000 Z
11
+ date: 2022-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciimath
@@ -290,20 +290,6 @@ dependencies:
290
290
  - - "~>"
291
291
  - !ruby/object:Gem::Version
292
292
  version: '13.0'
293
- - !ruby/object:Gem::Dependency
294
- name: rexml
295
- requirement: !ruby/object:Gem::Requirement
296
- requirements:
297
- - - ">="
298
- - !ruby/object:Gem::Version
299
- version: '0'
300
- type: :development
301
- prerelease: false
302
- version_requirements: !ruby/object:Gem::Requirement
303
- requirements:
304
- - - ">="
305
- - !ruby/object:Gem::Version
306
- version: '0'
307
293
  - !ruby/object:Gem::Dependency
308
294
  name: rspec
309
295
  requirement: !ruby/object:Gem::Requirement
@@ -459,6 +445,7 @@ files:
459
445
  - lib/isodoc/pdf_convert.rb
460
446
  - lib/isodoc/presentation_function/bibdata.rb
461
447
  - lib/isodoc/presentation_function/block.rb
448
+ - lib/isodoc/presentation_function/erefs.rb
462
449
  - lib/isodoc/presentation_function/image.rb
463
450
  - lib/isodoc/presentation_function/inline.rb
464
451
  - lib/isodoc/presentation_function/math.rb