isodoc 2.12.9 → 3.0.0

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: 07e9e5bf21e51fd8f43a9a7173a75fef2b5763953c2ea308b3d0860ed1fedb66
4
- data.tar.gz: 8a8195a4271689359e8149bf037d05f440d7ca0a3363242c68616f053c9bd177
3
+ metadata.gz: 80ff8ea483a997f4ff1e6168f6c3f921b9d589ad7f855a475ae4dd82424a0793
4
+ data.tar.gz: cbb2f806aa2b7bd1d8aff9c412732a56a36619121cf27ef5fe57825037a25046
5
5
  SHA512:
6
- metadata.gz: 58941c30a9af219ae12a7154009286107fec41b38615a757a87ba974a23c9cedda4b0fbe7af2b1a674993ef77ba565bab378a1a4a30c19f929c70d7fd66e6f97
7
- data.tar.gz: cfbaae3c97005709624a8bb4f1e6015fd834dd98805223e20ec3b8e3560daaaa702d6e533e8c7a02e452dc0b9dab7c4b0d232ba9c34c849ff59f8a05d9ed5245
6
+ metadata.gz: 11bb2279603ad2b5045238fe562b233af74e5eb53fef0ec612b676cb3e7dff3ae575f7698d0294a1dd7e88ad8f47b31a5ef3bf00828fd16bde24383980841ad4
7
+ data.tar.gz: 13353c87b7fe45e8007f73b1cdfb8f9728c84001dc4d37bdee14fd27894e80e1384a738e013ccd8af750d43938b2aea136766115dbcf5e107a949a7649e46dc3
data/isodoc.gemspec CHANGED
@@ -35,7 +35,7 @@ Gem::Specification.new do |spec|
35
35
  # spec.add_dependency "relaton-cli"
36
36
  # spec.add_dependency "metanorma-utils", "~> 1.5.0" # already in isodoc-i18n
37
37
  spec.add_dependency "mn2pdf", ">= 2.13"
38
- spec.add_dependency "mn-requirements", "~> 0.4.0"
38
+ spec.add_dependency "mn-requirements", "~> 0.5.0"
39
39
 
40
40
  spec.add_dependency "relaton-render", "~> 0.9.0"
41
41
  spec.add_dependency "roman-numerals"
@@ -38,8 +38,9 @@ module IsoDoc
38
38
  def pseudocode_parse(node, out)
39
39
  @in_figure = true
40
40
  name = node.at(ns("./fmt-name"))
41
+ s = node.at(ns("./fmt-figure")) || node
41
42
  out.div **pseudocode_attrs(node) do |div|
42
- node.children.each { |n| parse(n, div) unless n.name == "fmt-name" }
43
+ s.children.each { |n| parse(n, div) unless n.name == "fmt-name" }
43
44
  sourcecode_name_parse(node, div, name)
44
45
  end
45
46
  @in_figure = false
@@ -58,10 +59,12 @@ module IsoDoc
58
59
 
59
60
  def sourcecode_parse(node, out)
60
61
  name = node.at(ns("./fmt-name"))
62
+ n = node.at(ns("./fmt-sourcecode"))
63
+ s = n || node
61
64
  out.p **sourcecode_attrs(node) do |div|
62
- sourcecode_parse1(node, div)
65
+ sourcecode_parse1(s, div)
63
66
  end
64
- annotation_parse(node, out)
67
+ annotation_parse(s, out)
65
68
  sourcecode_name_parse(node, out, name)
66
69
  end
67
70
 
@@ -92,7 +95,7 @@ module IsoDoc
92
95
  def formula_parse1(node, out)
93
96
  out.div **attr_code(class: "formula") do |div|
94
97
  div.p do |_p|
95
- parse(node.at(ns("./stem")), div)
98
+ parse(node.at(ns("./fmt-stem")), div)
96
99
  if lbl = node&.at(ns("./fmt-name"))&.text
97
100
  insert_tab(div, 1)
98
101
  div << lbl
@@ -109,7 +112,7 @@ module IsoDoc
109
112
  out.div **formula_attrs(node) do |div|
110
113
  formula_parse1(node, div)
111
114
  node.children.each do |n|
112
- %w(stem fmt-name).include? n.name and next
115
+ %w(stem fmt-name fmt-stem).include? n.name and next
113
116
  parse(n, div)
114
117
  end
115
118
  end
@@ -148,7 +151,7 @@ module IsoDoc
148
151
  attrs = para_attrs(node)
149
152
  attrs[:class] = "Quote"
150
153
  out.div **attr_code(attrs) do |p|
151
- node.children.each { |n| parse(n, p) }
154
+ node.children.each { |n| parse(n, p) unless n.name == "source" }
152
155
  end
153
156
  end
154
157
 
@@ -82,11 +82,12 @@ module IsoDoc
82
82
  end
83
83
 
84
84
  def stem_parse(node, out)
85
+ ret = node.at(ns("./semx[@element = 'stem']")) || node
85
86
  ooml = case node["type"]
86
- when "AsciiMath" then asciimath_parse(node)
87
- when "MathML" then mathml_parse(node)
88
- when "LaTeX" then latexmath_parse(node)
89
- else HTMLEntities.new.encode(node.text)
87
+ when "AsciiMath" then asciimath_parse(ret)
88
+ when "MathML" then mathml_parse(ret)
89
+ when "LaTeX" then latexmath_parse(ret)
90
+ else HTMLEntities.new.encode(ret.text)
90
91
  end
91
92
  out.span class: "stem" do |span|
92
93
  span.parent.add_child ooml
@@ -188,9 +189,7 @@ module IsoDoc
188
189
  end
189
190
  end
190
191
 
191
- def author_parse(node, out)
192
- children_parse(node, out)
193
- end
192
+ def author_parse(node, out); end
194
193
 
195
194
  def semx_parse(node, out)
196
195
  children_parse(node, out)
@@ -204,12 +203,36 @@ module IsoDoc
204
203
 
205
204
  def name_parse(node, out); end
206
205
  def semx_definition_parse(node, out); end
206
+ def semx_xref_parse(node, out); end
207
+ def semx_eref_parse(node, out); end
208
+ def semx_link_parse(node, out); end
209
+ def semx_origin_parse(node, out); end
210
+ def date_parse(node, out); end
211
+ def semx_stem_parse(node, out); end
207
212
 
208
213
  def floating_title_parse(node, out); end
214
+ def identifier_parse(node, out); end
215
+ def concept_parse(node, out); end
216
+ def erefstack_parse(node, out); end
217
+ def svgmap_parse(node, out); end
218
+ def amend_parse(node, out); end
219
+ def semx_sourcecode_parse(node, out); end
209
220
 
210
221
  def fmt_name_parse(node, out)
211
222
  children_parse(node, out)
212
223
  end
224
+
225
+ def fmt_identifier_parse(node, out)
226
+ children_parse(node, out)
227
+ end
228
+
229
+ def fmt_concept_parse(node, out)
230
+ children_parse(node, out)
231
+ end
232
+
233
+ def fmt_date_parse(node, out)
234
+ children_parse(node, out)
235
+ end
213
236
  end
214
237
  end
215
238
  end
@@ -20,9 +20,10 @@ module IsoDoc
20
20
  end
21
21
 
22
22
  def recommendation_parse1(node, out)
23
+ p = node.at(ns("./fmt-provision")) or return
23
24
  recommendation_name(node.at(ns("./fmt-name")), out)
24
- node.children.each do |n|
25
- parse(n, out) unless n.name == "fmt-name"
25
+ p.children.each do |n|
26
+ parse(n, out)
26
27
  end
27
28
  end
28
29
 
@@ -188,12 +188,17 @@ module IsoDoc
188
188
  when "bookmark" then bookmark_parse(node, out)
189
189
  when "pagebreak" then pagebreak_parse(node, out)
190
190
  when "callout" then callout_parse(node, out)
191
- when "stem" then stem_parse(node, out)
191
+ when "fmt-stem" then stem_parse(node, out)
192
+ when "stem" then semx_stem_parse(node, out)
192
193
  when "clause" then clause_parse(node, out)
193
- when "xref" then xref_parse(node, out)
194
- when "eref" then eref_parse(node, out)
195
- when "origin" then origin_parse(node, out)
196
- when "link" then link_parse(node, out)
194
+ when "xref" then semx_xref_parse(node, out)
195
+ when "fmt-xref" then xref_parse(node, out)
196
+ when "eref" then semx_eref_parse(node, out)
197
+ when "fmt-eref" then eref_parse(node, out)
198
+ when "origin" then semx_origin_parse(node, out)
199
+ when "fmt-origin" then origin_parse(node, out)
200
+ when "link" then semx_link_parse(node, out)
201
+ when "fmt-link" then link_parse(node, out)
197
202
  when "ul" then ul_parse(node, out)
198
203
  when "ol" then ol_parse(node, out)
199
204
  when "li" then li_parse(node, out)
@@ -245,7 +250,6 @@ module IsoDoc
245
250
  when "legal-statement" then legal_parse(node, out)
246
251
  when "feedback-statement" then feedback_parse(node, out)
247
252
  when "passthrough" then passthrough_parse(node, out)
248
- when "amend" then amend_parse(node, out)
249
253
  when "tab" then clausedelimspace(node, out) # in Presentation XML only
250
254
  when "svg" then svg_parse(node, out) # in Presentation XML only
251
255
  when "add" then add_parse(node, out)
@@ -273,6 +277,15 @@ module IsoDoc
273
277
  when "fmt-xref-label" then xref_label_parse(node, out)
274
278
  when "fmt-name" then fmt_name_parse(node, out)
275
279
  when "floating-title" then floating_title_parse(node, out)
280
+ when "fmt-identifier" then fmt_identifier_parse(node, out)
281
+ when "identifier" then identifier_parse(node, out)
282
+ when "fmt-concept" then fmt_concept_parse(node, out)
283
+ when "concept" then concept_parse(node, out)
284
+ when "erefstack" then erefstack_parse(node, out)
285
+ when "svgmap" then svgmap_parse(node, out)
286
+ when "amend" then amend_parse(node, out)
287
+ when "date" then date_parse(node, out)
288
+ when "fmt-date" then fmt_date_parse(node, out)
276
289
  else error_parse(node, out)
277
290
  end
278
291
  end
@@ -76,11 +76,13 @@ module IsoDoc
76
76
  def sourcecode_parse(node, out)
77
77
  name = node.at(ns("./fmt-name"))
78
78
  tag = node.at(ns(".//sourcecode | .//table")) ? "div" : "pre"
79
+ n = node.at(ns("./fmt-sourcecode"))
80
+ s = n || node
79
81
  attr = sourcecode_attrs(node).merge(class: "sourcecode")
80
82
  out.send tag, **attr do |div|
81
- sourcecode_parse1(node, div)
83
+ sourcecode_parse1(s, div)
82
84
  end
83
- annotation_parse(node, out)
85
+ annotation_parse(s, out)
84
86
  sourcecode_name_parse(node, out, name)
85
87
  end
86
88
 
@@ -137,17 +137,18 @@ module IsoDoc
137
137
 
138
138
  def table_fn1(table, fnote, idx); end
139
139
 
140
- # we use this to eliminate the semantic amend blocks from rendering
141
140
  def amend(docxml)
142
141
  docxml.xpath(ns("//amend")).each { |f| amend1(f) }
143
142
  end
144
143
 
145
144
  def amend1(elem)
146
- elem.xpath(ns("./locality | ./localityStack | ./autonumber | " \
145
+ ret = semx_fmt_dup(elem)
146
+ ret.xpath(ns("./locality | ./localityStack | ./autonumber | " \
147
147
  "./classification | ./contributor")).each(&:remove)
148
- elem.xpath(ns("./newcontent")).each { |a| a.name = "quote" }
149
- elem.xpath(ns("./description")).each { |a| a.replace(a.children) }
150
- elem.replace(elem.children)
148
+ ret.xpath(ns("./newcontent")).each { |a| a.name = "quote" }
149
+ ret.xpath(ns("./description")).each { |a| a.replace(a.children) }
150
+ elem.xpath(ns(".//fmt-name | .//fmt-xref-label")).each(&:remove)
151
+ elem.next = ret
151
152
  end
152
153
 
153
154
  def dl(docxml)
@@ -233,11 +234,16 @@ module IsoDoc
233
234
  source = elem.at(ns("./source"))
234
235
  author.nil? && source.nil? and return
235
236
  p = "&#x2014; "
236
- p += author.remove.to_xml if author
237
+ p += to_xml(semx_fmt_dup(author)) if author
237
238
  p += ", " if author && source
238
239
  if source
239
- source.name = "eref"
240
- p += source.remove.to_xml
240
+ s = semx_fmt_dup(source)
241
+ e = Nokogiri::XML::Node.new("eref", elem.document)
242
+ e << s.children
243
+ s << e
244
+ source.attributes.each_key { |k| e[k] = source[k] }
245
+ e["deleteme"] = "true" # duplicate of source, will be duplicated in fmt-eref, need to delete after
246
+ p += to_xml(s)
241
247
  end
242
248
  elem << "<attribution><p>#{l10n p}</p></attribution>"
243
249
  end
@@ -8,7 +8,7 @@ module IsoDoc
8
8
 
9
9
  def concept1(node)
10
10
  node.ancestors("definition, termsource, related").empty? or return
11
- xref = node&.at(ns("./xref/@target"))&.text or
11
+ xref = node&.at(ns("./semx/fmt-xref/@target"))&.text or
12
12
  return concept_render(node, ital: "true", ref: "true", bold: "false",
13
13
  linkref: "true", linkmention: "false")
14
14
  if @definition_ids[xref]
@@ -20,13 +20,25 @@ module IsoDoc
20
20
  end
21
21
 
22
22
  def concept_render(node, defaults)
23
- opts, render, ref = concept_render_init(node, defaults)
24
- node&.at(ns("./refterm"))&.remove
23
+ #require "debug"; binding.b
24
+ opts, render, ref, ret = concept_render_init(node, defaults)
25
+ ret&.at(ns("./refterm"))&.remove
25
26
  ref && opts[:ref] != "false" and render&.next = " "
26
27
  concept1_linkmention(ref, render, opts)
27
- concept1_ref(node, ref, opts)
28
- concept1_style(node, opts)
29
- node.replace(node.children)
28
+ concept1_ref(ret, ref, opts)
29
+ concept1_style(ret, opts)
30
+ concept_dup(node, ret)
31
+ end
32
+
33
+ def concept_dup(node, ret)
34
+ node.xpath(".//xmlns:semx[xmlns:fmt-xref | xmlns:fmt-eref | xmlns:fmt-origin | xmlns:fmt-link]").each(&:remove)
35
+ ret.xpath(ns(".//xref | .//eref | .//origin | .//link")).each(&:remove)
36
+ ret.xpath(ns(".//semx")).each do |s|
37
+ s.children.empty? and s.remove
38
+ end
39
+ f = Nokogiri::XML::Node.new("fmt-concept", node.document)
40
+ f << ret
41
+ node.next = f
30
42
  end
31
43
 
32
44
  def concept1_style(node, opts)
@@ -38,25 +50,37 @@ module IsoDoc
38
50
  end
39
51
 
40
52
  def concept_render_init(node, defaults)
41
- opts = %i(bold ital ref linkref linkmention)
53
+ opts = concept_render_opts(node, defaults)
54
+ ret = semx_fmt_dup(node)
55
+ ret.children.each { |x| x.text? and x.remove }
56
+ [opts, ret.at(ns("./renderterm")),
57
+ ret.at(ns("./semx/fmt-xref | ./semx/fmt-eref | ./termref")), ret]
58
+ end
59
+
60
+ def concept_render_opts(node, defaults)
61
+ %i(bold ital ref linkref linkmention)
42
62
  .each_with_object({}) { |x, m| m[x] = node[x.to_s] || defaults[x] }
43
- [opts, node.at(ns("./renderterm")),
44
- node.at(ns("./xref | ./eref | ./termref"))]
45
63
  end
46
64
 
47
65
  def concept1_linkmention(ref, renderterm, opts)
48
66
  (opts[:linkmention] == "true" && !renderterm.nil? && !ref.nil?) or return
49
67
  ref2 = ref.clone
50
68
  r2 = renderterm.clone
51
- renderterm.replace(ref2).children = r2
69
+ #renderterm.replace(ref2).children = r2
70
+ ref2.children = r2
71
+ if ref.parent.name == "semx"
72
+ renderterm.replace("<semx element='#{ref.parent['element']}' source='#{ref.parent['source']}'>#{to_xml(ref2)}</semx>")
73
+ else
74
+ renderterm.replace(ref2)
75
+ end
52
76
  end
53
77
 
54
78
  def concept1_ref(_node, ref, opts)
55
79
  ref.nil? and return
56
80
  opts[:ref] == "false" and return ref.remove
57
81
  concept1_ref_content(ref)
58
- %w(xref eref).include? ref.name and get_linkend(ref)
59
- opts[:linkref] == "false" && %w(xref eref).include?(ref.name) and
82
+ %w(fmt-xref fmt-eref).include? ref.name and get_linkend(ref)
83
+ opts[:linkref] == "false" && %w(fmt-xref fmt-eref).include?(ref.name) and
60
84
  ref.replace(ref.children)
61
85
  end
62
86
 
@@ -65,7 +89,7 @@ module IsoDoc
65
89
  foll = "]"
66
90
  non_locality_elems(ref).select do |c|
67
91
  !c.text? || /\S/.match(c)
68
- end.empty? and
92
+ end.empty? or
69
93
  (prev, foll = @i18n.term_defined_in.split("%"))
70
94
  ref.previous = prev
71
95
  ref.next = foll
@@ -3,13 +3,14 @@ require "metanorma-utils"
3
3
  module IsoDoc
4
4
  class PresentationXMLConvert < ::IsoDoc::Convert
5
5
  def citeas(xmldoc)
6
- xmldoc.xpath(ns("//eref | //origin | //quote//source | //link"))
6
+ xmldoc.xpath(ns("//fmt-eref | //fmt-origin | //fmt-link"))
7
7
  .each do |e|
8
+ sem_xml_descendant?(e) and next
8
9
  e["bibitemid"] && e["citeas"] or next
9
10
  a = @xrefs.anchor(e["bibitemid"], :xref, false) or next
10
11
  e["citeas"] = citeas_cleanup(a)
11
12
  # link generated in collection postprocessing from eref
12
- e.name == "link" && e.text.empty? and e.children = e["citeas"]
13
+ e.name == "fmt-link" && e.text.empty? and e.children = e["citeas"]
13
14
  end
14
15
  end
15
16
 
@@ -28,11 +29,13 @@ module IsoDoc
28
29
  end
29
30
 
30
31
  def erefstack1(elem)
31
- locs = elem.xpath(ns("./eref")).map do |e|
32
- [e["connective"], to_xml(e)]
32
+ locs = elem.xpath(ns("./semx/fmt-eref")).map do |e|
33
+ [e["connective"], to_xml(e.parent.remove)]
33
34
  end.flatten
34
35
  ret = resolve_eref_connectives(locs)
35
- elem.replace(ret[1])
36
+ elem["id"] ||= "_#{UUIDTools::UUID.random_create}"
37
+ elem.next = "<semx element='erefstack' source='#{elem['id']}'>#{ret[1]}</semx>"
38
+ #elem.replace(ret[1])
36
39
  end
37
40
 
38
41
  def eref_localities(refs, target, node)
@@ -192,8 +195,10 @@ module IsoDoc
192
195
  end
193
196
 
194
197
  def eref2link(docxml)
195
- docxml.xpath(ns("//eref | //origin[not(termref)] | //quote//source"))
198
+ docxml.xpath(ns("//display-text")).each { |f| f.replace(f.children) }
199
+ docxml.xpath(ns("//fmt-eref | //fmt-origin[not(.//termref)]"))
196
200
  .each do |e|
201
+ sem_xml_descendant?(e) and next
197
202
  href = eref_target(e) or next
198
203
  e.xpath(ns("./locality | ./localityStack")).each(&:remove)
199
204
  if href[:type] == :anchor then eref2xref(e)
@@ -203,7 +208,7 @@ module IsoDoc
203
208
  end
204
209
 
205
210
  def eref2xref(node)
206
- node.name = "xref"
211
+ node.name = "fmt-xref"
207
212
  node["target"] = node["bibitemid"]
208
213
  node.delete("bibitemid")
209
214
  node.delete("citeas")
@@ -213,7 +218,7 @@ module IsoDoc
213
218
  def eref2link1(node, href)
214
219
  url = href[:link]
215
220
  att = href[:type] == :attachment ? "attachment='true'" : ""
216
- repl = "<link #{att} target='#{url}'>#{node.children}</link>"
221
+ repl = "<fmt-link #{att} target='#{url}'>#{node.children}</link>"
217
222
  node["type"] == "footnote" and repl = "<sup>#{repl}</sup>"
218
223
  node.replace(repl)
219
224
  end
@@ -20,8 +20,11 @@ module IsoDoc
20
20
  end
21
21
 
22
22
  def svgmap_extract(elem)
23
- if f = elem.at(ns("./figure")) then elem.replace(f)
24
- else elem.remove
23
+ if elem.at(ns("./figure"))# then elem.replace(f)
24
+ n = semx_fmt_dup(elem)
25
+ n.xpath(ns("./target")).each(&:remove)
26
+ elem.next = n
27
+ #else elem.remove
25
28
  end
26
29
  end
27
30
 
@@ -25,8 +25,8 @@ module IsoDoc
25
25
  # <locality type="section"><reference>3.1</reference></locality></origin>
26
26
 
27
27
  def unnest_linkend(node)
28
- node.at(ns("./xref[@nested]")) or return
29
- node.xpath(ns("./xref[@nested]")).each { |x| x.delete("nested") }
28
+ node.at(ns("./fmt-xref[@nested]")) or return
29
+ node.xpath(ns("./fmt-xref[@nested]")).each { |x| x.delete("nested") }
30
30
  node.xpath(ns("./location | ./locationStack")).each(&:remove)
31
31
  node.replace(node.children)
32
32
  end
@@ -39,30 +39,52 @@ module IsoDoc
39
39
  def anchor_id_postprocess(node); end
40
40
 
41
41
  def xref(docxml)
42
- docxml.xpath(ns("//xref")).each { |f| xref1(f) }
43
- docxml.xpath(ns("//xref//xref")).each { |f| f.replace(f.children) }
42
+ #docxml.xpath(ns("//display-text")).each { |f| f.replace(f.children) }
43
+ docxml.xpath(ns("//fmt-xref")).each { |f| xref1(f) }
44
+ docxml.xpath(ns("//fmt-xref//fmt-xref")).each { |f| f.replace(f.children) }
45
+ docxml.xpath(ns("//fmt-xref//xref")).each { |f| f.replace(f.children) }
44
46
  end
45
47
 
46
48
  def eref(docxml)
47
- docxml.xpath(ns("//eref")).each { |f| xref1(f) }
48
- docxml.xpath(ns("//eref//xref")).each { |f| f.replace(f.children) }
49
+ docxml.xpath(ns("//eref[@deleteme]")).each { |f| redundant_eref(f) }
50
+ docxml.xpath(ns("//fmt-eref")).each { |f| xref1(f) }
51
+ docxml.xpath(ns("//fmt-eref//fmt-xref")).each { |f| f.replace(f.children) }
49
52
  docxml.xpath(ns("//erefstack")).each { |f| erefstack1(f) }
50
53
  end
51
54
 
55
+ # redundant eref copied from quote/source
56
+ def redundant_eref(elem)
57
+ if elem.next.name == "semx"
58
+ elem.next.elements.first.delete("deleteme")
59
+ elem.next.replace(elem.next.children)
60
+ end
61
+ elem.remove
62
+ end
63
+
52
64
  def origin(docxml)
53
- docxml.xpath(ns("//origin[not(termref)]")).each { |f| xref1(f) }
65
+ docxml.xpath(ns("//fmt-origin[not(.//termref)]")).each { |f| xref1(f) }
54
66
  end
55
67
 
56
- def quotesource(docxml)
68
+ # KILL
69
+ def quotesourcex(docxml)
57
70
  docxml.xpath(ns("//quote//source")).each { |f| xref1(f) }
58
71
  docxml.xpath(ns("//quote//source//xref")).each do |f|
59
72
  f.replace(f.children)
60
73
  end
61
74
  end
62
75
 
76
+ # do not change to Presentation XML rendering
77
+ def sem_xml_descendant?(node)
78
+ !node.ancestors("preferred, admitted, deprecated, related, " \
79
+ "definition, termsource").empty? and return true
80
+ !node.ancestors("xref, eref, origin, link").empty? and return true
81
+ !node.ancestors("requirement, recommendation, permission").empty? &&
82
+ node.ancestors("fmt-provision").empty? and return true
83
+ false
84
+ end
85
+
63
86
  def xref1(node)
64
- # Semantic XML
65
- node.ancestors("related, definition, termsource").empty? or return
87
+ sem_xml_descendant?(node) and return
66
88
  get_linkend(node)
67
89
  end
68
90
 
@@ -87,11 +109,11 @@ module IsoDoc
87
109
  end
88
110
 
89
111
  def identifier(docxml)
90
- (docxml.xpath(ns("//identifier")) -
91
- docxml.xpath(ns("//bibdata/identifier")) -
92
- docxml.xpath(ns("//bibitema/identifier")))
93
- .each do |n|
94
- n.name = "tt"
112
+ docxml.xpath(ns("//identifier")).each do |n|
113
+ %w(bibdata bibitem requirement recommendation permission)
114
+ .include?(n.parent.name) and next
115
+ s = semx_fmt_dup(n)
116
+ n.next = "<fmt-identifier><tt>#{to_xml(s)}</tt></fmt-identifier>"
95
117
  end
96
118
  end
97
119
 
@@ -104,7 +126,10 @@ module IsoDoc
104
126
 
105
127
  def date1(elem)
106
128
  elem["value"] && elem["format"] or return
107
- elem.replace(@i18n.date(elem["value"], elem["format"].strip))
129
+ val = @i18n.date(elem["value"], elem["format"].strip)
130
+ d = semx_fmt_dup(elem)
131
+ d << val
132
+ elem.next = "<fmt-date>#{to_xml(d)}</fmt-date>"
108
133
  end
109
134
 
110
135
  def inline_format(docxml)
@@ -7,11 +7,13 @@ module IsoDoc
7
7
  MATHML = { "m" => "http://www.w3.org/1998/Math/MathML" }.freeze
8
8
 
9
9
  def mathml(docxml)
10
+ docxml.xpath(ns("//stem")).each { |s| stem_dup(s) }
10
11
  locale = @lang.to_sym
11
12
  @numfmt = Plurimath::NumberFormatter
12
13
  .new(locale, localize_number: @localizenumber,
13
14
  localizer_symbols: twitter_cldr_localiser_symbols)
14
15
  docxml.xpath("//m:math", MATHML).each do |f| # rubocop:disable Style/CombinableLoops
16
+ f.parent&.parent&.name == "fmt-stem" or next
15
17
  mathml1(f, locale)
16
18
  end
17
19
  end
@@ -147,11 +149,11 @@ module IsoDoc
147
149
  def maths_just_numeral(node)
148
150
  mn = node.at(".//m:mn", MATHML).children.text
149
151
  .sub(/\^([0-9+-]+)$/, "<sup>\\1</sup>")
150
- if node.parent.name == "stem"
151
- node.parent.replace(mn)
152
- else
152
+ #if node.parent.parent.name == "stem"
153
+ #node.replace(mn)
154
+ #else
153
155
  node.replace(mn)
154
- end
156
+ #end
155
157
  end
156
158
 
157
159
  def mathml1(node, locale)
@@ -159,6 +161,15 @@ module IsoDoc
159
161
  mathml_number(node, locale)
160
162
  end
161
163
 
164
+ def stem_dup(node)
165
+ sem_xml_descendant?(node) and return
166
+ ret = semx_fmt_dup(node)
167
+ f = Nokogiri::XML::Node.new("fmt-stem", node.document)
168
+ t = node["type"] and f["type"] = t
169
+ f << ret
170
+ node.next = f
171
+ end
172
+
162
173
  # convert any Ascii superscripts to correct(ish) MathML
163
174
  # Not bothering to match times, base of 1.0 x 10^-20, just ^-20
164
175
  def mn_to_msup(node)
@@ -198,11 +209,11 @@ module IsoDoc
198
209
  def mathml_number_to_number(node)
199
210
  (node.elements.size == 1 && node.elements.first.name == "mn") or return
200
211
  repl = node.at("./m:mn", MATHML).children
201
- if node.parent.name == "stem"
202
- node.parent.replace(repl)
203
- else
212
+ #if node.parent.name == "stem"
213
+ #node.parent.replace(repl)
214
+ #else
204
215
  node.replace(repl)
205
- end
216
+ #end
206
217
  end
207
218
  end
208
219
  end
@@ -34,7 +34,7 @@ module IsoDoc
34
34
 
35
35
  def callouts(elem)
36
36
  elem.xpath(ns(".//callout")).each do |c|
37
- @callouts[c["target"]] = c.children.to_xml
37
+ @callouts[c["target"]] = to_xml(c.children)
38
38
  end
39
39
  end
40
40
 
@@ -42,36 +42,66 @@ module IsoDoc
42
42
  sourcehighlighter_css(docxml)
43
43
  @highlighter = sourcehighlighter
44
44
  @callouts = {}
45
- docxml.xpath(ns("//sourcecode")).each do |f|
45
+ (docxml.xpath(ns("//sourcecode")) -
46
+ docxml.xpath(ns("//metanorma-extension//sourcecode")))
47
+ .each do |f|
46
48
  sourcecode1(f)
47
49
  end
48
50
  end
49
51
 
50
52
  def sourcecode1(elem)
51
- source_highlight(elem)
53
+ ret1 = semx_fmt_dup(elem)
54
+ #sourcecode_annot_id(elem)
52
55
  source_label(elem)
56
+ source_highlight(ret1, elem["linenums"] == "true", elem["lang"])
53
57
  callouts(elem)
54
- annotations(elem)
58
+ annotations(elem, ret1)
59
+ fmt_sourcecode(elem, ret1)
55
60
  end
56
61
 
57
- def annotations(elem)
62
+ def fmt_sourcecode(elem, ret1)
63
+ ret = Nokogiri::XML::Node.new("fmt-#{elem.name}", elem.document)
64
+ elem.attributes.each_key { |x| x != "id" and ret[x] = elem[x] }
65
+ ret1.xpath(ns("./name")).each(&:remove)
66
+ ret << ret1.children
67
+ elem << ret
68
+ end
69
+
70
+ # KILL
71
+ def sourcecode_annot_id(elem)
72
+ elem.xpath(ns("./annotation")).each do |a|
73
+ if a["original-id"]
74
+ a["id"] = a["original-id"]
75
+ a.delete("original-id")
76
+ end
77
+ a.xpath(".//*[@original-id]").each do |n|
78
+ n["id"] = n["original-id"]
79
+ n.delete("original-id")
80
+ end
81
+ end
82
+ end
83
+
84
+ def annotations(elem, fmt_elem)
58
85
  elem.at(ns("./annotation")) or return
59
86
  ret = ""
60
87
  elem.xpath(ns("./annotation")).each do |a|
61
- a.remove
88
+ id = a['original-id']
89
+ dd = semx_fmt_dup(a)
90
+ dd["source"] = a["id"]
62
91
  ret += <<~OUT
63
- <dt id='#{a['id']}'><span class='c'>#{@callouts[a['id']]}</span></dt>
64
- <dd>#{a.children.to_xml}</dd>
92
+ <dt id='#{id}'><span class='c'>#{@callouts[id]}</span></dt>
93
+ <dd>#{to_xml dd}</dd>
65
94
  OUT
66
95
  end
67
- elem << "<dl><name>#{@i18n.key}</name>#{ret}</dl>"
96
+ fmt_elem.xpath(ns("./annotation")).each(&:remove)
97
+ fmt_elem << "<dl><name>#{@i18n.key}</name>#{ret}</dl>"
68
98
  end
69
99
 
70
- def source_highlight(elem)
100
+ def source_highlight(elem, linenums, lang)
71
101
  @highlighter or return
72
102
  markup = source_remove_markup(elem)
73
- p = source_lex(elem)
74
- elem.children = if elem["linenums"] == "true"
103
+ p = source_lex(elem, lang)
104
+ elem.children = if linenums
75
105
  r = sourcecode_table_to_elem(elem, p)
76
106
  source_restore_markup_table(r, markup)
77
107
  else
@@ -140,8 +170,8 @@ module IsoDoc
140
170
  r
141
171
  end
142
172
 
143
- def source_lex(elem)
144
- lexer = Rouge::Lexer.find(elem["lang"] || "plaintext") ||
173
+ def source_lex(elem, lang)
174
+ lexer = Rouge::Lexer.find(lang || "plaintext") ||
145
175
  Rouge::Lexer.find("plaintext")
146
176
  l = Rouge::Lexers::Escape.new(start: "{^^{", end: "}^^}", lang: lexer)
147
177
  source = to_xml(elem.children).gsub(/</, "{^^{<").gsub(/>/, ">}^^}")
@@ -1,5 +1,18 @@
1
1
  module IsoDoc
2
2
  class PresentationXMLConvert < ::IsoDoc::Convert
3
+ def fmt_ref(docxml)
4
+ docxml.xpath(ns("//xref | //eref | //origin | //link")).each do |x|
5
+ sem_xml_descendant?(x) and next
6
+ tag = x.name
7
+ y = Nokogiri::XML::Node.new("fmt-#{tag}", x.document)
8
+ x.attributes.each_key { |a| y[a] = x[a] }
9
+ n = semx_fmt_dup(x) # semx/fmt-xref for ease of processing
10
+ n.children.each { |c| y << c }
11
+ n << y
12
+ x.next = n
13
+ end
14
+ end
15
+
3
16
  def prefix_container(container, linkend, node, target)
4
17
  prefix_container?(container, node) or return linkend
5
18
  container_container = @xrefs.anchor(container, :container, false)
@@ -126,7 +139,7 @@ module IsoDoc
126
139
 
127
140
  def loc2xref(entry)
128
141
  if entry[:target]
129
- "<xref nested='true' target='#{entry[:target]}'>#{entry[:label]}</xref>"
142
+ "<fmt-xref nested='true' target='#{entry[:target]}'>#{entry[:label]}</fmt-xref>"
130
143
  else
131
144
  entry[:label]
132
145
  end
@@ -71,7 +71,6 @@ module IsoDoc
71
71
  end
72
72
 
73
73
  def block(docxml)
74
- amend docxml
75
74
  table docxml
76
75
  figure docxml
77
76
  sourcecode docxml
@@ -88,15 +87,18 @@ module IsoDoc
88
87
  requirement docxml
89
88
  recommendation docxml
90
89
  requirement_render docxml
90
+ amend docxml
91
91
  end
92
92
 
93
93
  def inline(docxml)
94
94
  bibitem_lookup(docxml) # feeds citeas
95
- citeas docxml # feeds xref, eref, origin, quotesource
95
+ fmt_ref docxml # feeds citeas, xref, eref, origin, concept
96
+ citeas docxml # feeds xref, eref, origin, concept
96
97
  xref docxml
97
98
  eref docxml # feeds eref2link
98
99
  origin docxml # feeds eref2link
99
- quotesource docxml # feeds eref2link
100
+ #quotesource docxml # feeds eref2link
101
+ concept docxml
100
102
  eref2link docxml
101
103
  mathml docxml
102
104
  ruby docxml
@@ -114,7 +116,7 @@ module IsoDoc
114
116
  termdefinition docxml
115
117
  designation docxml
116
118
  termsource docxml
117
- concept docxml
119
+ #concept docxml
118
120
  related docxml
119
121
  termcleanup docxml
120
122
  end
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "2.12.9".freeze
2
+ VERSION = "3.0.0".freeze
3
3
  end
@@ -134,7 +134,7 @@ module IsoDoc
134
134
  def formula_parse1(node, out)
135
135
  out.div **attr_code(class: "formula") do |div|
136
136
  div.p do |_p|
137
- parse(node.at(ns("./stem")), div)
137
+ parse(node.at(ns("./fmt-stem")), div)
138
138
  insert_tab(div, 1)
139
139
  if lbl = node&.at(ns("./fmt-name"))&.text
140
140
  div << lbl
@@ -124,6 +124,7 @@ module IsoDoc
124
124
 
125
125
  def preface_name_anchors(clause, level, title)
126
126
  xref = semx(clause, title, clause.name)
127
+ clause["id"] ||= "_#{UUIDTools::UUID.random_create}"
127
128
  @anchors[clause["id"]] =
128
129
  { label: nil, level:,
129
130
  xref:, title: nil,
@@ -187,6 +188,7 @@ module IsoDoc
187
188
  xref = labelled_autonum(@labels["clause"], num)
188
189
  label = num
189
190
  c = clause_title(clause) and title = semx(clause, c, "title")
191
+ clause["id"] ||= "_#{UUIDTools::UUID.random_create}"
190
192
  @anchors[clause["id"]] =
191
193
  { label:, xref:, title:, level:, type: "clause",
192
194
  elem: @labels["clause"] }
@@ -207,10 +209,10 @@ module IsoDoc
207
209
  label = num
208
210
  level == 1 && clause.name == "annex" and
209
211
  label = annex_name_lbl(clause, label)
210
- xref = labelled_autonum(@labels["annex"], num)
211
212
  c = clause_title(clause) and title = semx(clause, c, "title")
213
+ clause["id"] ||= "_#{UUIDTools::UUID.random_create}"
212
214
  @anchors[clause["id"]] =
213
- { label:, xref:, title:,
215
+ { label:, xref: labelled_autonum(@labels["annex"], num), title:,
214
216
  elem: @labels["annex"], type: "clause",
215
217
  subtype: "annex", value: num.to_s, level: }
216
218
  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.12.9
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-02-03 00:00:00.000000000 Z
11
+ date: 2025-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.4.0
75
+ version: 0.5.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.4.0
82
+ version: 0.5.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: relaton-render
85
85
  requirement: !ruby/object:Gem::Requirement