metanorma-iso 1.8.6 → 1.9.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,31 +1,30 @@
1
1
  require "isodoc"
2
- require "mn2sts"
2
+ require "mnconvert"
3
3
 
4
4
  module IsoDoc
5
5
  module Iso
6
-
7
6
  # A {Converter} implementation that generates HTML output, and a document
8
7
  # schema encapsulation of the document for validation
9
8
  #
10
9
  class IsoStsConvert < IsoDoc::XslfoPdfConvert
11
- def initialize(options)
10
+ def initialize(_options)
12
11
  @libdir = File.dirname(__FILE__)
13
12
  @format = :isosts
14
13
  @suffix = "isosts.xml"
15
14
  end
16
15
 
17
- def convert(input_filename, file = nil, debug = false, output_filename = nil)
18
- file = File.read(input_filename, encoding: "utf-8") if file.nil?
19
- docxml, filename, dir = convert_init(file, input_filename, debug)
20
- /\.xml$/.match(input_filename) or
21
- input_filename = Tempfile.open([filename, ".xml"], encoding: "utf-8") do |f|
22
- f.write file
23
- f.path
24
- end
16
+ def convert(input_fname, file = nil, debug = false, output_fname = nil)
17
+ file = File.read(input_fname, encoding: "utf-8") if file.nil?
18
+ _, fname, dir = convert_init(file, input_fname, debug)
19
+ /\.xml$/.match(input_fname) or
20
+ input_fname = Tempfile.open([fname, ".xml"], encoding: "utf-8") do |f|
21
+ f.write file
22
+ f.path
23
+ end
25
24
  FileUtils.rm_rf dir
26
- Mn2sts.convert(input_filename, output_filename || "#{filename}.#{@suffix}", iso: true)
25
+ MnConvert.convert(input_fname, output_fname || "#{fname}.#{@suffix}",
26
+ MnConvert::InputFormat::MN, { output_format: :iso })
27
27
  end
28
28
  end
29
29
  end
30
30
  end
31
-
@@ -112,14 +112,58 @@ module IsoDoc
112
112
  end
113
113
  end
114
114
 
115
+ def concept(docxml)
116
+ docxml.xpath(ns("//terms//concept")).each_with_object({}) do |f, m|
117
+ concept_term(f, m)
118
+ end
119
+ docxml.xpath(ns("//concept")).each do |node|
120
+ concept_render(node, node["ital"] || "false", node["ref"] || "false")
121
+ end
122
+ end
123
+
124
+ def concept_term(node, seen)
125
+ term = node&.at(ns("./refterm"))&.to_xml
126
+ if term && seen[term]
127
+ concept_render(node, node["ital"] || "false", node["ref"] || "false")
128
+ else concept_render(node, node["ital"] || "true", node["ref"] || "true")
129
+ end
130
+ seen[term] = true if term
131
+ seen
132
+ end
133
+
134
+ def concept1_ref(node, ref)
135
+ if r = node.at(ns("./xref | ./eref | ./termref"))
136
+ return r.remove if ref == "false"
137
+
138
+ r.name == "termref" and
139
+ r.replace(@i18n.term_defined_in.sub(/%/, r.to_xml)) or
140
+ r.replace("(#{r.to_xml})")
141
+ end
142
+ end
143
+
115
144
  def concept1(node)
116
- node&.at(ns("./refterm"))&.remove
117
- node&.at(ns("./renderterm"))&.name = "em"
118
- r = node.at(ns("./xref | ./eref | ./termref"))
119
- r.name == "termref" and
120
- r.replace(@i18n.term_defined_in.sub(/%/, r.to_xml)) or
121
- r.replace("(#{r.to_xml})")
122
- node.replace(node.children)
145
+ node.replace(node&.at(ns("./renderterm"))&.children ||
146
+ node&.at(ns("./refterm"))&.children ||
147
+ node.children)
148
+ end
149
+
150
+ # we're assuming terms and clauses in the right place for display,
151
+ # to cope with multiple terms sections
152
+
153
+ def display_order(docxml)
154
+ i = 0
155
+ i = display_order_xpath(docxml, "//preface/*", i)
156
+ i = display_order_at(docxml, "//clause[@type = 'scope']", i)
157
+ i = display_order_at(docxml, @xrefs.klass.norm_ref_xpath, i)
158
+ # i = display_order_at(docxml, "//sections/terms | "\
159
+ # "//sections/clause[descendant::terms]", i)
160
+ # i = display_order_at(docxml, "//sections/definitions", i)
161
+ # i = display_order_xpath(docxml, @xrefs.klass.middle_clause(docxml), i)
162
+ i = display_order_xpath(docxml, "//sections/clause[not(@type = 'scope')] | "\
163
+ "//sections/terms | //sections/definitions", i)
164
+ i = display_order_xpath(docxml, "//annex", i)
165
+ i = display_order_xpath(docxml, @xrefs.klass.bibliography_xpath, i)
166
+ display_order_xpath(docxml, "//indexsect", i)
123
167
  end
124
168
 
125
169
  include Init
@@ -1,9 +1,8 @@
1
1
  require "isodoc"
2
- require "mn2sts"
2
+ require "mnconvert"
3
3
 
4
4
  module IsoDoc
5
5
  module Iso
6
-
7
6
  class StsConvert < IsoDoc::XslfoPdfConvert
8
7
  def initialize(_options) # rubocop:disable Lint/MissingSuper
9
8
  @libdir = File.dirname(__FILE__)
@@ -14,14 +13,14 @@ module IsoDoc
14
13
  def convert(in_fname, file = nil, debug = false, out_fname = nil)
15
14
  file = File.read(in_fname, encoding: "utf-8") if file.nil?
16
15
  _docxml, filename, dir = convert_init(file, in_fname, debug)
17
- unless /\.xml$/.match?(in_fname)
16
+ /\.xml$/.match?(in_fname) or
18
17
  in_fname = Tempfile.open([filename, ".xml"], encoding: "utf-8") do |f|
19
18
  f.write file
20
19
  f.path
21
20
  end
22
- end
23
21
  FileUtils.rm_rf dir
24
- Mn2sts.convert(in_fname, out_fname || "#{filename}.#{@suffix}")
22
+ MnConvert.convert(in_fname, out_fname || "#{filename}.#{@suffix}",
23
+ MnConvert::InputFormat::MN)
25
24
  end
26
25
  end
27
26
  end
@@ -8,7 +8,7 @@ module IsoDoc
8
8
  if @klass.amd(doc)
9
9
  initial_anchor_names_amd(doc)
10
10
  else
11
- super
11
+ initial_anchor_names1(doc)
12
12
  end
13
13
  introduction_names(doc.at(ns("//introduction")))
14
14
  end
@@ -26,6 +26,22 @@ module IsoDoc
26
26
  termexample_anchor_names(doc)
27
27
  end
28
28
 
29
+ def initial_anchor_names1(doc)
30
+ doc.xpath(ns("//preface/*")).each { |c| c.element? and preface_names(c) }
31
+ # potentially overridden in middle_section_asset_names()
32
+ sequential_asset_names(doc.xpath(ns("//preface/*")))
33
+ n = Counter.new
34
+ n = section_names(doc.at(ns("//clause[@type = 'scope']")), n, 1)
35
+ n = section_names(doc.at(ns(@klass.norm_ref_xpath)), n, 1)
36
+ doc.xpath(ns("//sections/clause[not(@type = 'scope')] | "\
37
+ "//sections/terms | //sections/definitions")).each do |c|
38
+ n = section_names(c, n, 1)
39
+ end
40
+ middle_section_asset_names(doc)
41
+ termnote_anchor_names(doc)
42
+ termexample_anchor_names(doc)
43
+ end
44
+
29
45
  # we can reference 0-number clauses in introduction
30
46
  def introduction_names(clause)
31
47
  return if clause.nil?
@@ -31,7 +31,7 @@ module Metanorma
31
31
  "Cambria Math" => nil,
32
32
  "Times New Roman" => nil,
33
33
  "Source Han Sans" => nil,
34
- "Courier" => nil,
34
+ "Source Han Sans Normal" => nil,
35
35
  "Courier New" => nil,
36
36
  }
37
37
  end
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module ISO
3
- VERSION = "1.8.6".freeze
3
+ VERSION = "1.9.2".freeze
4
4
  end
5
5
  end
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
31
31
 
32
32
  spec.add_dependency "isodoc", "~> 1.7.0"
33
33
  spec.add_dependency "metanorma-standoc", "~> 1.10.0"
34
- spec.add_dependency "mn2sts", "~> 1.8.0"
34
+ spec.add_dependency "mnconvert", "~> 1.8.0"
35
35
  spec.add_dependency "ruby-jing"
36
36
  spec.add_dependency "tokenizer", "~> 0.3.0"
37
37
  spec.add_dependency "twitter_cldr"
@@ -48,11 +48,11 @@ RSpec.describe Asciidoctor::ISO do
48
48
  <mi>r</mi>
49
49
  <mo>=</mo>
50
50
  <mn>1</mn>
51
- <mi>%</mi>
51
+ <mo>%</mo>
52
52
  <mi>r</mi>
53
53
  <mo>=</mo>
54
54
  <mn>1</mn>
55
- <mi>%</mi>
55
+ <mo>%</mo>
56
56
  </math>
57
57
  </stem>
58
58
  </formula>
@@ -230,11 +230,11 @@ RSpec.describe Asciidoctor::ISO do
230
230
  <mi>r</mi>
231
231
  <mo>=</mo>
232
232
  <mn>1</mn>
233
- <mi>%</mi>
233
+ <mo>%</mo>
234
234
  <mi>r</mi>
235
235
  <mo>=</mo>
236
236
  <mn>1</mn>
237
- <mi>%</mi>
237
+ <mo>%</mo>
238
238
  </math>
239
239
  </stem>
240
240
  <note id="_">
@@ -2,7 +2,7 @@ require "spec_helper"
2
2
 
3
3
  RSpec.describe Asciidoctor::ISO do
4
4
  it "processes sections" do
5
- expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", *OPTIONS)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
5
+ input = <<~INPUT
6
6
  #{ASCIIDOC_BLANK_HDR}
7
7
  == Foreword
8
8
 
@@ -56,6 +56,7 @@ RSpec.describe Asciidoctor::ISO do
56
56
 
57
57
  === Bibliography Subsection
58
58
  INPUT
59
+ output = <<~OUTPUT
59
60
  #{BLANK_HDR}
60
61
  <preface>
61
62
  <foreword id="_" obligation="informative">
@@ -151,10 +152,12 @@ RSpec.describe Asciidoctor::ISO do
151
152
  </bibliography>
152
153
  </iso-standard>
153
154
  OUTPUT
155
+ expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
156
+ .to be_equivalent_to xmlpp(output)
154
157
  end
155
158
 
156
159
  it "processes section obligations" do
157
- expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", *OPTIONS)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
160
+ input = <<~INPUT
158
161
  #{ASCIIDOC_BLANK_HDR}
159
162
  [obligation=informative]
160
163
  == Clause 1
@@ -167,6 +170,7 @@ RSpec.describe Asciidoctor::ISO do
167
170
  [appendix,obligation=informative]
168
171
  == Annex
169
172
  INPUT
173
+ output = <<~OUTPUT
170
174
  #{BLANK_HDR}
171
175
  <sections>
172
176
  <clause id="_" inline-header="false" obligation="informative">
@@ -184,10 +188,12 @@ RSpec.describe Asciidoctor::ISO do
184
188
  </annex>
185
189
  </iso-standard>
186
190
  OUTPUT
191
+ expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
192
+ .to be_equivalent_to xmlpp(output)
187
193
  end
188
194
 
189
195
  it "processes inline headers" do
190
- expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", *OPTIONS)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
196
+ input = <<~INPUT
191
197
  #{ASCIIDOC_BLANK_HDR}
192
198
  == Clause 1
193
199
 
@@ -200,6 +206,7 @@ RSpec.describe Asciidoctor::ISO do
200
206
  [%inline-header]
201
207
  === Clause Aa
202
208
  INPUT
209
+ output = <<~OUTPUT
203
210
  #{BLANK_HDR}
204
211
  <sections>
205
212
  <clause id="_" inline-header="false" obligation="normative">
@@ -217,16 +224,19 @@ RSpec.describe Asciidoctor::ISO do
217
224
  </annex>
218
225
  </iso-standard>
219
226
  OUTPUT
227
+ expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
228
+ .to be_equivalent_to xmlpp(output)
220
229
  end
221
230
 
222
231
  it "processes blank headers" do
223
- expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", *OPTIONS)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
232
+ input = <<~INPUT
224
233
  #{ASCIIDOC_BLANK_HDR}
225
234
  == Clause 1
226
235
 
227
236
  === {blank}
228
237
 
229
238
  INPUT
239
+ output = <<~OUTPUT
230
240
  #{BLANK_HDR}
231
241
  <sections>
232
242
  <clause id="_" inline-header="false" obligation="normative">
@@ -236,10 +246,12 @@ RSpec.describe Asciidoctor::ISO do
236
246
  </sections>
237
247
  </iso-standard>
238
248
  OUTPUT
249
+ expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
250
+ .to be_equivalent_to xmlpp(output)
239
251
  end
240
252
 
241
253
  it "processes terms & definitions with external source" do
242
- expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", *OPTIONS)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
254
+ input = <<~INPUT
243
255
  #{ASCIIDOC_BLANK_HDR}
244
256
 
245
257
  Foreword
@@ -250,6 +262,7 @@ RSpec.describe Asciidoctor::ISO do
250
262
  === Term1
251
263
 
252
264
  INPUT
265
+ output = <<~OUTPUT
253
266
  #{BLANK_HDR.sub(/<boilerplate>/, '<termdocsource bibitemid="iso1234"/><termdocsource bibitemid="iso5678"/><boilerplate>')}
254
267
  <preface>
255
268
  <foreword id="_" obligation="informative">
@@ -285,10 +298,12 @@ RSpec.describe Asciidoctor::ISO do
285
298
  </sections>
286
299
  </iso-standard>
287
300
  OUTPUT
301
+ expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
302
+ .to be_equivalent_to xmlpp(output)
288
303
  end
289
304
 
290
305
  it "processes empty terms & definitions" do
291
- expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", *OPTIONS)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
306
+ input = <<~INPUT
292
307
  #{ASCIIDOC_BLANK_HDR}
293
308
 
294
309
  Foreword
@@ -297,6 +312,7 @@ RSpec.describe Asciidoctor::ISO do
297
312
 
298
313
 
299
314
  INPUT
315
+ output = <<~OUTPUT
300
316
  #{BLANK_HDR}
301
317
  <preface>
302
318
  <foreword id="_" obligation="informative">
@@ -331,10 +347,12 @@ RSpec.describe Asciidoctor::ISO do
331
347
  </iso-standard>
332
348
 
333
349
  OUTPUT
350
+ expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
351
+ .to be_equivalent_to xmlpp(output)
334
352
  end
335
353
 
336
354
  it "processes empty terms & definitions with external source" do
337
- expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", *OPTIONS)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
355
+ input = <<~INPUT
338
356
  #{ASCIIDOC_BLANK_HDR}
339
357
 
340
358
  Foreword
@@ -343,6 +361,7 @@ RSpec.describe Asciidoctor::ISO do
343
361
  == Terms and Definitions
344
362
 
345
363
  INPUT
364
+ output = <<~OUTPUT
346
365
  #{BLANK_HDR.sub(/<boilerplate>/, '<termdocsource bibitemid="iso1234"/><termdocsource bibitemid="iso5678"/><boilerplate>')}
347
366
  <preface>
348
367
  <foreword id="_" obligation="informative">
@@ -375,5 +394,107 @@ RSpec.describe Asciidoctor::ISO do
375
394
  </sections>
376
395
  </iso-standard>
377
396
  OUTPUT
397
+ expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
398
+ .to be_equivalent_to xmlpp(output)
399
+ end
400
+
401
+ it "ignores multiple terms & definitions in default documents" do
402
+ input = <<~INPUT
403
+ #{ASCIIDOC_BLANK_HDR}
404
+
405
+ == Terms and Definitions
406
+
407
+ == Clause
408
+
409
+ [heading=terms and definitions]
410
+ == More terms
411
+
412
+ INPUT
413
+ output = <<~OUTPUT
414
+ #{BLANK_HDR}
415
+ <sections>
416
+ <terms id='_' obligation='normative'>
417
+ <title>Terms and definitions</title>
418
+ <p id='_'>No terms and definitions are listed in this document.</p>
419
+ <p id='_'>
420
+ ISO and IEC maintain terminological databases for use in standardization
421
+ at the following addresses:
422
+ </p>
423
+ <ul id='_'>
424
+ <li>
425
+ <p id='_'>
426
+ ISO Online browsing platform: available at
427
+ <link target='http://www.iso.org/obp'/>
428
+ </p>
429
+ </li>
430
+ <li>
431
+ <p id='_'>
432
+ IEC Electropedia: available at
433
+ <link target='http://www.electropedia.org'/>
434
+ </p>
435
+ </li>
436
+ </ul>
437
+ </terms>
438
+ <clause id='_' inline-header='false' obligation='normative'>
439
+ <title>Clause</title>
440
+ </clause>
441
+ <clause id='_' inline-header='false' obligation='normative'>
442
+ <title>More terms</title>
443
+ </clause>
444
+ </sections>
445
+ </iso-standard>
446
+ OUTPUT
447
+ expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
448
+ .to be_equivalent_to xmlpp(output)
449
+ end
450
+
451
+ it "permits multiple terms & definitions in vocabulary documents" do
452
+ input = <<~INPUT
453
+ #{ASCIIDOC_BLANK_HDR.sub(/:nodoc:/, ":nodoc:\n:docsubtype: vocabulary")}
454
+
455
+ == Terms and Definitions
456
+
457
+ == Clause
458
+
459
+ [heading=terms and definitions]
460
+ == More terms
461
+
462
+ INPUT
463
+ output = <<~OUTPUT
464
+ #{BLANK_HDR.sub(%r{<doctype>article</doctype>}, "<doctype>article</doctype><subdoctype>vocabulary</subdoctype>")}
465
+ <sections>
466
+ <terms id='_' obligation='normative'>
467
+ <title>Terms and definitions</title>
468
+ <p id='_'>No terms and definitions are listed in this document.</p>
469
+ <p id='_'>
470
+ ISO and IEC maintain terminological databases for use in standardization
471
+ at the following addresses:
472
+ </p>
473
+ <ul id='_'>
474
+ <li>
475
+ <p id='_'>
476
+ ISO Online browsing platform: available at
477
+ <link target='http://www.iso.org/obp'/>
478
+ </p>
479
+ </li>
480
+ <li>
481
+ <p id='_'>
482
+ IEC Electropedia: available at
483
+ <link target='http://www.electropedia.org'/>
484
+ </p>
485
+ </li>
486
+ </ul>
487
+ </terms>
488
+ <clause id='_' inline-header='false' obligation='normative'>
489
+ <title>Clause</title>
490
+ </clause>
491
+ <terms id='_' obligation='normative'>
492
+ <title>More terms</title>
493
+ </terms>
494
+ </sections>
495
+ </iso-standard>
496
+ OUTPUT
497
+ expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
498
+ .to be_equivalent_to xmlpp(output)
378
499
  end
379
500
  end