isodoc 2.12.0 → 2.12.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/isodoc.gemspec +2 -2
  3. data/lib/isodoc/convert.rb +0 -21
  4. data/lib/isodoc/function/blocks.rb +19 -48
  5. data/lib/isodoc/function/blocks_example_note.rb +75 -29
  6. data/lib/isodoc/function/cleanup.rb +3 -40
  7. data/lib/isodoc/function/inline.rb +39 -9
  8. data/lib/isodoc/function/lists.rb +5 -5
  9. data/lib/isodoc/function/references.rb +9 -133
  10. data/lib/isodoc/function/reqt.rb +2 -2
  11. data/lib/isodoc/function/section.rb +25 -28
  12. data/lib/isodoc/function/section_titles.rb +16 -13
  13. data/lib/isodoc/function/table.rb +3 -3
  14. data/lib/isodoc/function/terms.rb +21 -20
  15. data/lib/isodoc/function/to_word_html.rb +8 -5
  16. data/lib/isodoc/function/utils.rb +1 -1
  17. data/lib/isodoc/html_function/footnotes.rb +2 -1
  18. data/lib/isodoc/html_function/html.rb +1 -5
  19. data/lib/isodoc/init.rb +31 -0
  20. data/lib/isodoc/metadata.rb +9 -0
  21. data/lib/isodoc/metadata_contributor.rb +1 -1
  22. data/lib/isodoc/metadata_date.rb +1 -1
  23. data/lib/isodoc/presentation_function/autonum.rb +139 -0
  24. data/lib/isodoc/presentation_function/block.rb +95 -36
  25. data/lib/isodoc/presentation_function/docid.rb +78 -0
  26. data/lib/isodoc/presentation_function/erefs.rb +6 -4
  27. data/lib/isodoc/presentation_function/image.rb +52 -13
  28. data/lib/isodoc/presentation_function/inline.rb +6 -6
  29. data/lib/isodoc/presentation_function/math.rb +0 -14
  30. data/lib/isodoc/presentation_function/metadata.rb +0 -62
  31. data/lib/isodoc/presentation_function/refs.rb +44 -14
  32. data/lib/isodoc/presentation_function/reqt.rb +1 -1
  33. data/lib/isodoc/presentation_function/section.rb +46 -121
  34. data/lib/isodoc/presentation_function/sourcecode.rb +7 -4
  35. data/lib/isodoc/presentation_function/terms.rb +27 -2
  36. data/lib/isodoc/presentation_function/title.rb +107 -0
  37. data/lib/isodoc/presentation_function/xrefs.rb +17 -10
  38. data/lib/isodoc/presentation_xml_convert.rb +6 -2
  39. data/lib/isodoc/version.rb +1 -1
  40. data/lib/isodoc/word_function/body.rb +8 -36
  41. data/lib/isodoc/word_function/footnotes.rb +1 -1
  42. data/lib/isodoc/word_function/lists.rb +12 -10
  43. data/lib/isodoc/word_function/postprocess_cover.rb +0 -2
  44. data/lib/isodoc/word_function/postprocess_table.rb +1 -1
  45. data/lib/isodoc/word_function/table.rb +2 -2
  46. data/lib/isodoc/xref/clause_order.rb +2 -2
  47. data/lib/isodoc/xref/xref_anchor.rb +31 -16
  48. data/lib/isodoc/xref/xref_counter_types.rb +3 -2
  49. data/lib/isodoc/xref/xref_gen.rb +57 -33
  50. data/lib/isodoc/xref/xref_gen_seq.rb +145 -56
  51. data/lib/isodoc/xref/xref_sect_gen.rb +64 -47
  52. data/lib/isodoc/xref/xref_util.rb +49 -1
  53. data/lib/isodoc/xref.rb +3 -0
  54. data/lib/isodoc-yaml/i18n-ar.yaml +9 -9
  55. data/lib/isodoc-yaml/i18n-de.yaml +9 -9
  56. data/lib/isodoc-yaml/i18n-en.yaml +9 -9
  57. data/lib/isodoc-yaml/i18n-es.yaml +9 -9
  58. data/lib/isodoc-yaml/i18n-fr.yaml +9 -9
  59. data/lib/isodoc-yaml/i18n-ja.yaml +10 -10
  60. data/lib/isodoc-yaml/i18n-ru.yaml +9 -9
  61. data/lib/isodoc-yaml/i18n-zh-Hans.yaml +9 -9
  62. data/lib/nokogiri/xml/node.rb +1 -0
  63. metadata +9 -6
@@ -11,6 +11,10 @@ module IsoDoc
11
11
  "-"
12
12
  end
13
13
 
14
+ def hierreqtsep
15
+ "-"
16
+ end
17
+
14
18
  def subfigure_increment(idx, counter, elem)
15
19
  if elem.parent.name == "figure" then idx += 1
16
20
  else
@@ -30,7 +34,8 @@ module IsoDoc
30
34
  clause.xpath(ns(self.class::FIGURE_NO_CLASS)).noblank.each do |t|
31
35
  # labelled_ancestor(t, %w(figure)) and next # disable nested figure labelling
32
36
  j = subfigure_increment(j, c, t)
33
- sequential_figure_body(j, c, t, "figure", container:)
37
+ sublabel = subfigure_label(j)
38
+ figure_anchor(t, sublabel, c.print, "figure", container: container)
34
39
  end
35
40
  sequential_figure_class_names(clause, container:)
36
41
  end
@@ -43,24 +48,69 @@ module IsoDoc
43
48
  c[t["class"]] ||= Counter.new
44
49
  # labelled_ancestor(t, %w(figure)) and next
45
50
  j = subfigure_increment(j, c[t["class"]], t)
46
- sequential_figure_body(j, c[t["class"]], t, t["class"],
47
- container:)
51
+ sublabel = subfigure_label(j)
52
+ figure_anchor(t, sublabel, c[t["class"]].print, t["class"],
53
+ container: container)
48
54
  end
49
55
  end
50
56
 
57
+ def hier_separator(markup: false)
58
+ h = hiersep
59
+ h.blank? || !markup or h = delim_wrap(h)
60
+ h
61
+ end
62
+
51
63
  def subfigure_label(subfignum)
52
- subfignum.zero? and return ""
53
- "#{hierfigsep}#{subfignum}"
64
+ subfignum.zero? and return
65
+ subfignum.to_s
66
+ end
67
+
68
+ def subfigure_separator(markup: false)
69
+ h = hierfigsep
70
+ h.blank? || !markup or h = delim_wrap(h)
71
+ h
72
+ end
73
+
74
+ def subreqt_separator(markup: false)
75
+ h = hierreqtsep
76
+ h.blank? || !markup or h = delim_wrap(h)
77
+ h
78
+ end
79
+
80
+ def subfigure_delim
81
+ ""
82
+ end
83
+
84
+ def figure_anchor(elem, sublabel, label, klass, container: false)
85
+ if sublabel
86
+ /<semx/.match?(label) or label = semx(elem.parent, label)
87
+ subfigure_anchor(elem, sublabel, label, klass, container: false)
88
+ else
89
+ @anchors[elem["id"]] = anchor_struct(
90
+ label, elem, @labels[klass] || klass.capitalize, klass,
91
+ { unnumb: elem["unnumbered"], container: }
92
+ )
93
+ end
94
+ end
95
+
96
+ def fig_subfig_label(label, sublabel)
97
+ "#{label}#{subfigure_separator}#{sublabel}"
54
98
  end
55
99
 
56
- def sequential_figure_body(subfig, counter, elem, klass, container: false)
57
- label = counter.print
58
- label &&= label + subfigure_label(subfig)
100
+ def subfigure_anchor(elem, sublabel, label, klass, container: false)
101
+ figlabel = fig_subfig_label(label, sublabel)
59
102
  @anchors[elem["id"]] = anchor_struct(
60
- label, container ? elem : nil,
61
- @labels[klass] || klass.capitalize, klass,
62
- elem["unnumbered"]
103
+ figlabel, elem, @labels[klass] || klass.capitalize, klass,
104
+ { unnumb: elem["unnumbered"] }
63
105
  )
106
+ if elem["unnumbered"] != "true"
107
+ x = "#{subfigure_separator(markup: true)}#{semx(elem, sublabel)}"
108
+ @anchors[elem["id"]][:label] = "#{label}#{x}" # "#{semx(elem.parent, label)}#{x}"
109
+ @anchors[elem["id"]][:xref] = @anchors[elem.parent["id"]][:xref] + x +
110
+ delim_wrap(subfigure_delim)
111
+ x = @anchors[elem.parent["id"]][:container] and
112
+ @anchors[elem["id"]][:container] = x
113
+ end
64
114
  end
65
115
 
66
116
  def sequential_table_names(clause, container: false)
@@ -68,8 +118,8 @@ module IsoDoc
68
118
  clause.xpath(ns(".//table")).noblank.each do |t|
69
119
  # labelled_ancestor(t) and next
70
120
  @anchors[t["id"]] = anchor_struct(
71
- c.increment(t).print, container ? t : nil,
72
- @labels["table"], "table", t["unnumbered"]
121
+ c.increment(t).print, t,
122
+ @labels["table"], "table", { unnumb: t["unnumbered"], container: container }
73
123
  )
74
124
  end
75
125
  end
@@ -80,7 +130,7 @@ module IsoDoc
80
130
  @anchors[t["id"]] = anchor_struct(
81
131
  c.increment(t).print, t,
82
132
  t["inequality"] ? @labels["inequality"] : @labels["formula"],
83
- "formula", t["unnumbered"]
133
+ "formula", { unnumb: t["unnumbered"], container: true }
84
134
  )
85
135
  end
86
136
  end
@@ -95,39 +145,49 @@ module IsoDoc
95
145
  ./permission | ./requirement | ./recommendation
96
146
  XPATH
97
147
 
98
- def sequential_permission_names(clause, container: false)
148
+ def sequential_permission_names(clause, container: true)
99
149
  c = ReqCounter.new
100
150
  clause.xpath(ns(FIRST_LVL_REQ)).noblank.each do |t|
101
151
  m = @reqt_models.model(t["model"])
102
152
  klass, label = reqt2class_label(t, m)
103
153
  id = c.increment(label, t).print
104
- sequential_permission_body(id, t, label, klass, m,
154
+ sequential_permission_body(id, nil, t, label, klass, m,
105
155
  container:)
106
- sequential_permission_children(t, id, container:)
156
+ sequential_permission_children(t, id, klass, container:)
107
157
  end
108
158
  end
109
159
 
110
- def sequential_permission_children(elem, lbl, container: false)
160
+ def sequential_permission_children(elem, lbl, klass, container: false)
111
161
  c = ReqCounter.new
112
162
  elem.xpath(ns(REQ_CHILDREN)).noblank.each do |t|
113
163
  m = @reqt_models.model(t["model"])
114
164
  klass, label = reqt2class_nested_label(t, m)
115
- id = "#{lbl}#{hierfigsep}#{c.increment(label, t).print}"
116
- sequential_permission_body(id, t, label, klass, m,
165
+ ctr = c.increment(label, t).print
166
+ id = "#{lbl}#{subreqt_separator}#{ctr}"
167
+ sequential_permission_body(ctr, lbl, t, label, klass, m,
117
168
  container:)
118
- sequential_permission_children(t, id, container:)
169
+ sequential_permission_children(t, id, klass, container:)
119
170
  end
120
171
  end
121
172
 
122
- def sequential_permission_body(id, elem, label, klass, model,
173
+ def sequential_permission_body(id, parent_id, elem, label, klass, model,
123
174
  container: false)
175
+ lbl = parent_id ? "#{parent_id}#{subreqt_separator}#{id}" : id
124
176
  @anchors[elem["id"]] = model.postprocess_anchor_struct(
125
- elem, anchor_struct(id, elem,
126
- label, klass, elem["unnumbered"])
177
+ elem, anchor_struct(lbl, elem,
178
+ label, klass, { unnumb: elem["unnumbered"], container: })
127
179
  )
180
+ @anchors[elem["id"]][:semx] = semx(elem, lbl)
181
+ if parent_id
182
+ x = "#{subreqt_separator(markup: true)}#{semx(elem, id)}"
183
+ @anchors[elem["id"]][:semx] = @anchors[elem.parent["id"]][:semx] + x
184
+ @anchors[elem["id"]][:label] =
185
+ "<span class='fmt-element-name'>#{label}</span> #{@anchors[elem["id"]][:semx]}"
186
+ @anchors[elem["id"]][:xref] = "<span class='fmt-element-name'>#{label}</span> #{@anchors[elem["id"]][:semx]}"
187
+ end
128
188
  model.permission_parts(elem, id, label, klass).each do |n|
129
189
  @anchors[n[:id]] = anchor_struct(n[:number], n[:elem], n[:label],
130
- n[:klass], false)
190
+ n[:klass], { unnumb: false, container: })
131
191
  end
132
192
  end
133
193
 
@@ -156,44 +216,61 @@ container: false)
156
216
  sequential_permission_names(clause, container:)
157
217
  end
158
218
 
159
- def hierarchical_figure_names(clause, num)
219
+ def nodeSet(clauses)
220
+ case clauses
221
+ when Nokogiri::XML::Node
222
+ [clauses]
223
+ when Nokogiri::XML::NodeSet
224
+ clauses
225
+ end
226
+ end
227
+
228
+ # these can take a NodeSet as argument; semx will point to members of the NodeSet,
229
+ # but numbering will be consecutive
230
+ def hierarchical_figure_names(clauses, num)
160
231
  c = Counter.new
161
232
  j = 0
233
+ nodeSet(clauses).each do |clause|
162
234
  clause.xpath(ns(self.class::FIGURE_NO_CLASS)).noblank.each do |t|
163
235
  # labelled_ancestor(t, %w(figure)) and next
164
236
  j = subfigure_increment(j, c, t)
165
- hierarchical_figure_body(num, j, c, t, "figure")
237
+ sublabel = subfigure_label(j)
238
+ # hierarchical_figure_body(num, j, c, t, "figure")
239
+ #figure_anchor(t, sublabel, "#{num}#{hier_separator}#{c.print}", "figure")
240
+ #require "debug"; binding.b
241
+ figure_anchor(t, sublabel, hiersemx(clause, num, c, t), "figure")
166
242
  end
167
243
  hierarchical_figure_class_names(clause, num)
244
+ end
168
245
  end
169
246
 
170
- def hierarchical_figure_class_names(clause, num)
247
+ def hierarchical_figure_class_names(clauses, num)
171
248
  c = {}
172
249
  j = 0
250
+ nodeSet(clauses).each do |clause|
173
251
  clause.xpath(ns(".//figure[@class][not(@class = 'pseudocode')]"))
174
252
  .noblank.each do |t|
175
253
  # labelled_ancestor(t, %w(figure)) and next
176
254
  c[t["class"]] ||= Counter.new
177
255
  j = subfigure_increment(j, c[t["class"]], t)
178
- hierarchical_figure_body(num, j, c[t["class"]], t, t["class"])
256
+ sublabel = subfigure_label(j)
257
+ # hierarchical_figure_body(num, j, c[t["class"]], t, t["class"])
258
+ #figure_anchor(t, sublabel, "#{num}#{hier_separator}#{c[t['class']].print}", t["class"])
259
+ figure_anchor(t, sublabel, hiersemx(clause, num, c[t["class"]], t), t["class"])
260
+ end
179
261
  end
180
262
  end
181
263
 
182
- def hierarchical_figure_body(num, subfignum, counter, block, klass)
183
- label = "#{num}#{hiersep}#{counter.print}" +
184
- subfigure_label(subfignum)
185
- @anchors[block["id"]] =
186
- anchor_struct(label, nil, @labels[klass] || klass.capitalize,
187
- klass, block["unnumbered"])
188
- end
189
-
190
- def hierarchical_table_names(clause, num)
264
+ def hierarchical_table_names(clauses, num)
191
265
  c = Counter.new
266
+ nodeSet(clauses).each do |clause|
192
267
  clause.xpath(ns(".//table")).noblank.each do |t|
193
268
  # labelled_ancestor(t) and next
194
269
  @anchors[t["id"]] =
195
- anchor_struct("#{num}#{hiersep}#{c.increment(t).print}",
196
- nil, @labels["table"], "table", t["unnumbered"])
270
+ #anchor_struct("#{num}#{hier_separator}#{c.increment(t).print}",
271
+ anchor_struct(hiersemx(clause, num, c.increment(t), t),
272
+ t, @labels["table"], "table", { unnumb: t["unnumbered"], container: false })
273
+ end
197
274
  end
198
275
  end
199
276
 
@@ -204,47 +281,59 @@ container: false)
204
281
  hierarchical_permission_names(clause, num)
205
282
  end
206
283
 
207
- def hierarchical_formula_names(clause, num)
284
+ def hierarchical_formula_names(clauses, num)
208
285
  c = Counter.new
286
+ nodeSet(clauses).each do |clause|
209
287
  clause.xpath(ns(".//formula")).noblank.each do |t|
210
288
  @anchors[t["id"]] = anchor_struct(
211
- "#{num}#{hiersep}#{c.increment(t).print}", nil,
289
+ #"#{num}#{hier_separator}#{c.increment(t).print}", t,
290
+ hiersemx(clause, num, c.increment(t), t), t,
212
291
  t["inequality"] ? @labels["inequality"] : @labels["formula"],
213
- "formula", t["unnumbered"]
292
+ "formula", { unnumb: t["unnumbered"], container: false }
214
293
  )
215
294
  end
295
+ end
216
296
  end
217
297
 
218
- def hierarchical_permission_names(clause, num)
298
+ def hierarchical_permission_names(clauses, num)
219
299
  c = ReqCounter.new
300
+ nodeSet(clauses).each do |clause|
220
301
  clause.xpath(ns(FIRST_LVL_REQ)).noblank.each do |t|
221
302
  m = @reqt_models.model(t["model"])
222
303
  klass, label = reqt2class_label(t, m)
223
- id = "#{num}#{hiersep}#{c.increment(label, t).print}"
224
- hierarchical_permission_body(id, t, label, klass, m)
225
- hierarchical_permission_children(t, id)
304
+ #id = "#{num}#{hier_separator}#{c.increment(label, t).print}"
305
+ id = hiersemx(clause, num, c.increment(label, t), t)
306
+ sequential_permission_body(id, nil, t, label, klass, m, container: false)
307
+ sequential_permission_children(t, id, klass, container: false)
226
308
  end
309
+ end
227
310
  end
228
311
 
312
+ # TODO remove
229
313
  def hierarchical_permission_children(block, lbl)
230
314
  c = ReqCounter.new
231
315
  block.xpath(ns(REQ_CHILDREN)).noblank.each do |t|
232
316
  m = @reqt_models.model(t["model"])
233
317
  klass, label = reqt2class_nested_label(t, m)
234
- id = "#{lbl}#{hierfigsep}#{c.increment(label, t).print}"
235
- hierarchical_permission_body(id, t, label, klass, m)
318
+ id = "#{lbl}#{subreqt_separator}#{c.increment(label, t).print}"
319
+ sequential_permission_body(c.print, lbl, t, label, klass, m)
236
320
  hierarchical_permission_children(t, id)
237
321
  end
238
322
  end
239
323
 
240
- def hierarchical_permission_body(id, block, label, klass, model)
241
- @anchors[block["id"]] = model.postprocess_anchor_struct(
242
- block, anchor_struct(id, nil,
243
- label, klass, block["unnumbered"])
324
+ # TODO remove
325
+ def hierarchical_permission_body(id, parent_id, elem, label, klass, model)
326
+ @anchors[elem["id"]] = model.postprocess_anchor_struct(
327
+ elem, anchor_struct(id, elem,
328
+ label, klass, { unnumb: elem["unnumbered"], container: false })
244
329
  )
245
- model.permission_parts(block, id, label, klass).each do |n|
246
- @anchors[n[:id]] = anchor_struct(n[:number], nil, n[:label],
247
- n[:klass], false)
330
+ x = "#{subreqt_separator(markup: true)}#{semx(elem, id)}"
331
+ @anchors[elem["id"]][:label] = "#{semx(elem.parent, parent_id)}#{x}"
332
+ @anchors[elem["id"]][:xref] = @anchors[elem.parent["id"]][:xref] + x
333
+ model.permission_parts(elem, id, label, klass).each do |n|
334
+ # we don't have an n["id"], so we allow n[:id] in anchor_struct
335
+ @anchors[n[:id]] = anchor_struct(n[:number], n, n[:label],
336
+ n[:klass], { unnumb: false, container: false })
248
337
  end
249
338
  end
250
339
  end
@@ -8,9 +8,6 @@ module IsoDoc
8
8
  annex_anchor_names(xml)
9
9
  back_clauses_anchor_names(xml)
10
10
  end
11
- if @klass.bibrender && (@parse_settings.empty? || @parse_settings[:refs])
12
- references(xml)
13
- end
14
11
  end
15
12
 
16
13
  def annex_anchor_names(xml)
@@ -33,11 +30,7 @@ module IsoDoc
33
30
  end
34
31
  end
35
32
 
36
- def references(docxml)
37
- docxml.xpath(ns("//bibitem[not(ancestor::bibitem)]")).each do |ref|
38
- reference_names(ref)
39
- end
40
- end
33
+ # NOTE: references processing has moved to Presentation XML
41
34
 
42
35
  def initial_anchor_names(xml)
43
36
  if @parse_settings.empty? || @parse_settings[:clauses]
@@ -83,8 +76,9 @@ module IsoDoc
83
76
 
84
77
  def clause_title(clause, use_elem_name: false)
85
78
  ret = clause.at(ns("./title"))&.text
86
- if use_elem_name && !ret
87
- clause.name.capitalize
79
+ if use_elem_name && ret.blank?
80
+ @i18n.labels[clause.name]&.capitalize ||
81
+ clause.name.capitalize
88
82
  else ret
89
83
  end
90
84
  end
@@ -107,11 +101,13 @@ module IsoDoc
107
101
 
108
102
  def unnumbered_names(clause)
109
103
  clause.nil? and return
110
- preface_name_anchors(clause, 1,
111
- clause_title(clause, use_elem_name: true))
104
+ title = clause_title(clause, use_elem_name: true)
105
+ preface_name_anchors(clause, 1, title)
112
106
  clause.xpath(ns(SUBCLAUSES)).each_with_index do |c, i|
113
- preface_names1(c, c.at(ns("./title"))&.text,
114
- "#{clause_title(clause)}, #{i + 1}", 2)
107
+ t = c.at(ns("./title"))
108
+ tt = "#{semx(clause, title, clause.name)}" \
109
+ "<span class='fmt-comma'>,</span> #{semx(c, i + 1)}"
110
+ preface_names1(c, t ? semx(c, t.text, c.name) : nil, tt, 2)
115
111
  end
116
112
  end
117
113
 
@@ -119,15 +115,18 @@ module IsoDoc
119
115
  label = title || parent_title
120
116
  preface_name_anchors(clause, level, title || parent_title)
121
117
  clause.xpath(ns(SUBCLAUSES)).each_with_index do |c, i|
122
- preface_names1(c, c.at(ns("./title"))&.text, "#{label} #{i + 1}",
118
+ t = c.at(ns("./title"))
119
+ preface_names1(c, t ? semx(c, t.text, c.name) : nil,
120
+ "#{label} #{semx(c, i + 1)}",
123
121
  level + 1)
124
122
  end
125
123
  end
126
124
 
127
125
  def preface_name_anchors(clause, level, title)
126
+ xref = semx(clause, title, clause.name)
128
127
  @anchors[clause["id"]] =
129
128
  { label: nil, level:,
130
- xref: title, title: nil,
129
+ xref:, title: nil,
131
130
  type: "clause", elem: @labels["clause"] }
132
131
  end
133
132
 
@@ -142,20 +141,32 @@ module IsoDoc
142
141
  def section_names(clause, num, lvl)
143
142
  unnumbered_section_name?(clause) and return num
144
143
  num.increment(clause)
145
- section_name_anchors(clause, num.print, lvl)
144
+ lbl = semx(clause, num.print)
145
+ section_name_anchors(clause, lbl, lvl)
146
146
  clause.xpath(ns(SUBCLAUSES))
147
- .each_with_object(clause_counter(0, prefix: num.print)) do |c, i|
148
- section_names1(c, i.increment(c).print, lvl + 1)
147
+ .each_with_object(clause_counter(0)) do |c, i|
148
+ section_names1(c, lbl, i.increment(c).print, lvl + 1)
149
149
  end
150
150
  num
151
151
  end
152
152
 
153
- def section_names1(clause, num, level)
153
+ def clause_number_semx(parentnum, clause, num)
154
+ if clause["branch-number"]
155
+ semx(clause, clause["branch-number"])
156
+ elsif parentnum.nil?
157
+ semx(clause, num)
158
+ else
159
+ "#{parentnum}#{delim_wrap(clausesep)}#{semx(clause, num)}"
160
+ end
161
+ end
162
+
163
+ def section_names1(clause, parentnum, num, level)
154
164
  unnumbered_section_name?(clause) and return num
155
- section_name_anchors(clause, num, level)
156
- i = clause_counter(0, prefix: num)
165
+ lbl = clause_number_semx(parentnum, clause, num)
166
+ section_name_anchors(clause, lbl, level)
167
+ i = clause_counter(0)
157
168
  clause.xpath(ns(SUBCLAUSES)).each do |c|
158
- section_names1(c, i.increment(c).print, level + 1)
169
+ section_names1(c, lbl, i.increment(c).print, level + 1)
159
170
  end
160
171
  end
161
172
 
@@ -168,10 +179,16 @@ module IsoDoc
168
179
  false
169
180
  end
170
181
 
182
+ def clausesep
183
+ "."
184
+ end
185
+
171
186
  def section_name_anchors(clause, num, level)
187
+ xref = labelled_autonum(@labels["clause"], num)
188
+ label = num
189
+ c = clause_title(clause) and title = semx(clause, c, "title")
172
190
  @anchors[clause["id"]] =
173
- { label: num, xref: "#{@labels['clause']} #{num}",
174
- title: clause_title(clause), level:, type: "clause",
191
+ { label:, xref:, title:, level:, type: "clause",
175
192
  elem: @labels["clause"] }
176
193
  end
177
194
 
@@ -179,52 +196,52 @@ module IsoDoc
179
196
  obl = "(#{@labels['inform_annex']})"
180
197
  clause["obligation"] == "normative" and
181
198
  obl = "(#{@labels['norm_annex']})"
199
+ obl = "<span class='fmt-obligation'>#{l10n obl}</fmt>"
182
200
  title = Common::case_with_markup(@labels["annex"], "capital",
183
201
  @script)
184
- "<strong>#{title} #{num}</strong><br/>#{obl}"
202
+ s = labelled_autonum(title, num)
203
+ "<strong><span class='fmt-caption-label'>#{s}</span></strong><br/>#{obl}"
185
204
  end
186
205
 
187
206
  def annex_name_anchors(clause, num, level)
188
207
  label = num
189
208
  level == 1 && clause.name == "annex" and
190
- label = annex_name_lbl(clause, num)
209
+ label = annex_name_lbl(clause, label)
210
+ xref = labelled_autonum(@labels["annex"], num)
211
+ c = clause_title(clause) and title = semx(clause, c, "title")
191
212
  @anchors[clause["id"]] =
192
- { label:,
213
+ { label:, xref:, title:,
193
214
  elem: @labels["annex"], type: "clause",
194
- subtype: "annex", value: num.to_s, level:,
195
- title: clause_title(clause),
196
- xref: "#{@labels['annex']} #{num}" }
215
+ subtype: "annex", value: num.to_s, level: }
197
216
  end
198
217
 
199
218
  def annex_names(clause, num)
200
- annex_name_anchors(clause, num, 1)
219
+ label = semx(clause, num)
220
+ annex_name_anchors(clause, label, 1)
201
221
  if @klass.single_term_clause?(clause)
202
222
  annex_names1(clause.at(ns("./references | ./terms | ./definitions")),
203
- num.to_s, 1)
223
+ nil, num.to_s, 1)
204
224
  else
205
225
  clause.xpath(ns(SUBCLAUSES))
206
- .each_with_object(clause_counter(0, prefix: num)) do |c, i|
207
- annex_names1(c, i.increment(c).print, 2)
226
+ .each_with_object(clause_counter(0)) do |c, i|
227
+ annex_names1(c, label, i.increment(c).print, 2)
208
228
  end
209
229
  end
210
- hierarchical_asset_names(clause, num)
230
+ hierarchical_asset_names(clause, label)
211
231
  end
212
232
 
213
- def annex_names1(clause, num, level)
214
- annex_name_anchors(clause, num, level)
215
- i = clause_counter(0, prefix: num)
233
+ def annex_names1(clause, parentnum, num, level)
234
+ lbl = clause_number_semx(parentnum, clause, num)
235
+ annex_name_anchors1(clause, lbl, level)
236
+ i = clause_counter(0)
216
237
  clause.xpath(ns(SUBCLAUSES)).each do |c|
217
- annex_names1(c, i.increment(c).print, level + 1)
238
+ annex_names1(c, lbl, i.increment(c).print, level + 1)
218
239
  end
219
240
  end
220
241
 
221
- def reference_names(ref)
222
- ids = @klass.bibitem_ref_code(ref)
223
- identifiers = @klass.render_identifier(ids)
224
- reference = @klass
225
- .docid_l10n(identifiers[:metanorma] || identifiers[:sdo] ||
226
- identifiers[:ordinal] || identifiers[:doi])
227
- @anchors[ref["id"]] = { xref: reference }
242
+ # subclauses of Annexes
243
+ def annex_name_anchors1(clause, num, level)
244
+ annex_name_anchors(clause, num, level)
228
245
  end
229
246
  end
230
247
  end
@@ -6,9 +6,15 @@ module Enumerable
6
6
  end
7
7
  end
8
8
 
9
+ class Object
10
+ def blank?
11
+ nil? || empty?
12
+ end
13
+ end
14
+
9
15
  module IsoDoc
10
16
  module XrefGen
11
- module Blocks
17
+ module Util
12
18
  def blank?(text)
13
19
  text.nil? || text.empty?
14
20
  end
@@ -37,6 +43,48 @@ module IsoDoc
37
43
 
38
44
  CHILD_SECTIONS = "./clause | ./appendix | ./terms | ./definitions | " \
39
45
  "./references".freeze
46
+
47
+ def child_sections
48
+ CHILD_SECTIONS
49
+ end
50
+
51
+ # if hierarchically marked up node in label already,
52
+ # leave alone, else wrap in semx
53
+ def semx(node, label, element = "autonum")
54
+ label = label.to_s
55
+ id = node["id"] || node[:id]
56
+ /<semx element='[^']+' source='#{id}'/.match?(label) and return label
57
+ l = stripsemx(label)
58
+ %(<semx element='#{element}' source='#{id}'>#{l}</semx>)
59
+ end
60
+
61
+ # assume parent is already semantically annotated with semx
62
+ def hiersemx(parent, parentlabel, counter, element, sep: nil)
63
+ sep ||= hier_separator(markup: true)
64
+ "#{semx(parent, parentlabel)}#{sep}#{semx(element, counter.print)}"
65
+ end
66
+
67
+ def delim_wrap(delim, klass = "fmt-autonum-delim")
68
+ delim.blank? and return ""
69
+ "<span class='#{klass}'>#{delim}</span>"
70
+ end
71
+
72
+ def stripsemx(elem)
73
+ elem.nil? and return elem
74
+ xml = Nokogiri::XML::DocumentFragment.parse(elem)
75
+ xml.traverse do |x|
76
+ x.name == "semx" ||
77
+ (x.name == "span" && /^fmt-/.match?(x["class"])) and
78
+ x.replace(x.children)
79
+ end
80
+ xml.to_xml(indent: 0, encoding: "UTF-8",
81
+ save_with: Nokogiri::XML::Node::SaveOptions::AS_XML)
82
+ end
83
+
84
+ def labelled_autonum(label, autonum)
85
+ label.blank? and return autonum
86
+ l10n("<span class='fmt-element-name'>#{label}</span> #{autonum}")
87
+ end
40
88
  end
41
89
  end
42
90
  end
data/lib/isodoc/xref.rb CHANGED
@@ -4,6 +4,7 @@ require_relative "xref/xref_counter_types"
4
4
  require_relative "xref/xref_gen_seq"
5
5
  require_relative "xref/xref_gen"
6
6
  require_relative "xref/xref_sect_gen"
7
+ require_relative "xref/xref_util"
7
8
  require_relative "class_utils"
8
9
  require_relative "function/utils"
9
10
 
@@ -92,5 +93,7 @@ module IsoDoc
92
93
  def l10n(text, lang = @lang, script = @script, locale = @locale)
93
94
  @i18n.l10n(text, lang, script, locale)
94
95
  end
96
+
97
+ include ::IsoDoc::XrefGen::Util
95
98
  end
96
99
  end
@@ -33,15 +33,15 @@ internal_external_terms_boilerplate: |
33
33
  لأغراض هذه الوثيقة ،تنطبق المصطلحات والتعاريف الواردة في % وما يلي.
34
34
  no_information_available: "[لا توجد معلومات متاحة]"
35
35
  term_defined_in: "(%)"
36
- binary_and: "%1 و %2"
37
- multiple_and: "%1, و %2"
38
- binary_or: "%1 او %2"
39
- multiple_or: "%1, او %2"
40
- chain_and: "%1 و %2"
41
- chain_or: "%1 او %2"
42
- chain_from: "%1 %من 2"
43
- chain_to: "من %1 إلى %2"
44
- nested_xref: "%1, %2"
36
+ binary_and: "%1 <conn>ﻭ</conn> %2"
37
+ multiple_and: "%1<enum-comma>,</enum-comma> <conn>ﻭ</conn> %2"
38
+ binary_or: "%1 <conn>ﺍﻭ</conn> %2"
39
+ multiple_or: "%1<enum-comma>,</enum-comma> <conn>ﺍﻭ</conn> %2"
40
+ chain_and: "%1 <conn>ﻭ</conn> %2"
41
+ chain_or: "%1 <conn>ﺍﻭ</conn> %2"
42
+ chain_from: "%1 <conn>%ﻢﻧ</conn> 2"
43
+ chain_to: "<conn>ﻢﻧ</conn> %1 <conn>ﺈﻟﻯ</conn> %2"
44
+ nested_xref: "%1<comma>,</comma> %2"
45
45
  list_nested_xref: "%1 %2"
46
46
  ordinal_keys: [gender]
47
47
  SpelloutRules: