metanorma-iso 1.8.4 → 1.8.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,160 +1,13 @@
1
1
  require "spec_helper"
2
-
3
- RSpec.describe IsoDoc do
4
- it "processes IsoXML tables (Presentation XML)" do
5
- expect(xmlpp(IsoDoc::Iso::PresentationXMLConvert.new({})
6
- .convert("test", <<~"INPUT", true))).to be_equivalent_to xmlpp(<<~"OUTPUT")
7
- <iso-standard xmlns="http://riboseinc.com/isoxml">
8
- <preface>
9
- <foreword>
10
- <table alt="tool tip" id="tableD-1" summary="long desc">
11
- <name>Repeatability and reproducibility of
12
- <em>husked</em>
13
- rice yield</name>
14
- <thead>
15
- <tr>
16
- <td align="left" rowspan="2">Description</td>
17
- <td align="center" colspan="4">Rice sample</td>
18
- </tr>
19
- <tr>
20
- <td align="left">Arborio</td>
21
- <td align="center">Drago
22
- <fn reference="a">
23
- <p id="_0fe65e9a-5531-408e-8295-eeff35f41a55">Parboiled rice.</p></fn>
24
- </td>
25
- <td align="center">Balilla
26
- <fn reference="a">
27
- <p id="_0fe65e9a-5531-408e-8295-eeff35f41a55">Parboiled rice.</p></fn>
28
- </td>
29
- <td align="center">Thaibonnet</td>
30
- </tr>
31
- </thead>
32
- <tbody>
33
- <tr>
34
- <th align="left">Number of laboratories retained after eliminating outliers</th>
35
- <td align="center">13</td>
36
- <td align="center">11</td>
37
- <td align="center">13</td>
38
- <td align="center">13</td>
39
- </tr>
40
- <tr>
41
- <td align="left">Mean value, g/100 g</td>
42
- <td align="center">81,2</td>
43
- <td align="center">82,0</td>
44
- <td align="center">81,8</td>
45
- <td align="center">77,7</td>
46
- </tr>
47
- </tbody>
48
- <tfoot>
49
- <tr>
50
- <td align="left">Reproducibility limit,
51
- <stem type="AsciiMath">R</stem>
52
- (= 2,83
53
- <stem type="AsciiMath">s_R</stem>
54
- )</td>
55
- <td align="center">2,89</td>
56
- <td align="center">0,57</td>
57
- <td align="center">2,26</td>
58
- <td align="center">6,06</td>
59
- </tr>
60
- </tfoot>
61
- <dl>
62
- <dt>Drago</dt>
63
- <dd>A type of rice</dd>
64
- </dl>
65
- <note>
66
- <p>This is a table about rice</p>
67
- </note>
68
- </table>
69
- </foreword>
70
- </preface>
71
- </iso-standard>
72
- INPUT
73
- <?xml version='1.0'?>
74
- <iso-standard xmlns='http://riboseinc.com/isoxml' type="presentation">
75
- <preface>
76
- <foreword>
77
- <table id='tableD-1' alt='tool tip' summary='long desc'>
78
- <name>
79
- Table 1&#xA0;&#x2014; Repeatability and reproducibility of
80
- <em>husked</em>
81
- rice yield
82
- </name>
83
- <thead>
84
- <tr>
85
- <td rowspan='2' align='left'>Description</td>
86
- <td colspan='4' align='center'>Rice sample</td>
87
- </tr>
88
- <tr>
89
- <td align='left'>Arborio</td>
90
- <td align='center'>
91
- Drago
92
- <fn reference='a'>
93
- <p id='_0fe65e9a-5531-408e-8295-eeff35f41a55'>Parboiled rice.</p>
94
- </fn>
95
- </td>
96
- <td align='center'>
97
- Balilla
98
- <fn reference='a'>
99
- <p id='_0fe65e9a-5531-408e-8295-eeff35f41a55'>Parboiled rice.</p>
100
- </fn>
101
- </td>
102
- <td align='center'>Thaibonnet</td>
103
- </tr>
104
- </thead>
105
- <tbody>
106
- <tr>
107
- <th align='left'>Number of laboratories retained after eliminating outliers</th>
108
- <td align='center'>13</td>
109
- <td align='center'>11</td>
110
- <td align='center'>13</td>
111
- <td align='center'>13</td>
112
- </tr>
113
- <tr>
114
- <td align='left'>Mean value, g/100 g</td>
115
- <td align='center'>81,2</td>
116
- <td align='center'>82,0</td>
117
- <td align='center'>81,8</td>
118
- <td align='center'>77,7</td>
119
- </tr>
120
- </tbody>
121
- <tfoot>
122
- <tr>
123
- <td align='left'>
124
- Reproducibility limit,
125
- <stem type='AsciiMath'>R</stem>
126
- (= 2,83
127
- <stem type='AsciiMath'>s_R</stem>
128
- )
129
- </td>
130
- <td align='center'>2,89</td>
131
- <td align='center'>0,57</td>
132
- <td align='center'>2,26</td>
133
- <td align='center'>6,06</td>
134
- </tr>
135
- </tfoot>
136
- <dl>
137
- <dt>Drago</dt>
138
- <dd>A type of rice</dd>
139
- </dl>
140
- <note>
141
- <name>NOTE</name>
142
- <p>This is a table about rice</p>
143
- </note>
144
- </table>
145
- </foreword>
146
- </preface>
147
- </iso-standard>
148
- OUTPUT
149
- end
150
2
 
151
- it "processes IsoXML tables (HTML)" do
152
- IsoDoc::Iso::HtmlConvert.new({}).convert("test", <<~"INPUT", false)
3
+ RSpec.describe IsoDoc do
4
+ it "processes IsoXML tables" do
5
+ input = <<~INPUT
153
6
  <iso-standard xmlns="http://riboseinc.com/isoxml">
154
7
  <preface>
155
8
  <foreword>
156
9
  <table alt="tool tip" id="tableD-1" summary="long desc">
157
- <name>Table 1 — Repeatability and reproducibility of
10
+ <name>Repeatability and reproducibility of
158
11
  <em>husked</em>
159
12
  rice yield</name>
160
13
  <thead>
@@ -193,9 +46,9 @@ RSpec.describe IsoDoc do
193
46
  </tbody>
194
47
  <tfoot>
195
48
  <tr>
196
- <td align="left">Reproducibility limit,
49
+ <td align="left">Reproducibility limit,
197
50
  <stem type="AsciiMath">R</stem>
198
- (= 2,83
51
+ (= 2,83
199
52
  <stem type="AsciiMath">s_R</stem>
200
53
  )</td>
201
54
  <td align="center">2,89</td>
@@ -209,17 +62,114 @@ RSpec.describe IsoDoc do
209
62
  <dd>A type of rice</dd>
210
63
  </dl>
211
64
  <note>
212
- <name>NOTE</name>
213
65
  <p>This is a table about rice</p>
214
66
  </note>
215
67
  </table>
216
68
  </foreword>
217
69
  </preface>
70
+ <annex id="Annex"><title>Annex</title>
71
+ <table id="AnnexTable">
72
+ <name>Another table</name>
73
+ <tbody><td>?</td></tbody>
74
+ </table>
75
+ </annex>
218
76
  </iso-standard>
219
77
  INPUT
220
- expect(File.exist?("test.html")).to be true
221
- html = File.read("test.html").sub(/^.*<main /m, '<main ').sub(%r{</main>.*$}m, "</main>")
222
- expect(xmlpp(html)).to be_equivalent_to xmlpp(<<~"OUTPUT")
78
+ presxml = <<~OUTPUT
79
+ <?xml version='1.0'?>
80
+ <iso-standard xmlns='http://riboseinc.com/isoxml' type="presentation">
81
+ <preface>
82
+ <foreword displayorder='1'>
83
+ <table id='tableD-1' alt='tool tip' summary='long desc'>
84
+ <name>
85
+ Table 1&#xA0;&#x2014; Repeatability and reproducibility of
86
+ <em>husked</em>
87
+ rice yield
88
+ </name>
89
+ <thead>
90
+ <tr>
91
+ <td rowspan='2' align='left'>Description</td>
92
+ <td colspan='4' align='center'>Rice sample</td>
93
+ </tr>
94
+ <tr>
95
+ <td align='left'>Arborio</td>
96
+ <td align='center'>
97
+ Drago
98
+ <fn reference='a'>
99
+ <p id='_0fe65e9a-5531-408e-8295-eeff35f41a55'>Parboiled rice.</p>
100
+ </fn>
101
+ </td>
102
+ <td align='center'>
103
+ Balilla
104
+ <fn reference='a'>
105
+ <p id='_0fe65e9a-5531-408e-8295-eeff35f41a55'>Parboiled rice.</p>
106
+ </fn>
107
+ </td>
108
+ <td align='center'>Thaibonnet</td>
109
+ </tr>
110
+ </thead>
111
+ <tbody>
112
+ <tr>
113
+ <th align='left'>Number of laboratories retained after eliminating outliers</th>
114
+ <td align='center'>13</td>
115
+ <td align='center'>11</td>
116
+ <td align='center'>13</td>
117
+ <td align='center'>13</td>
118
+ </tr>
119
+ <tr>
120
+ <td align='left'>Mean value, g/100 g</td>
121
+ <td align='center'>81,2</td>
122
+ <td align='center'>82,0</td>
123
+ <td align='center'>81,8</td>
124
+ <td align='center'>77,7</td>
125
+ </tr>
126
+ </tbody>
127
+ <tfoot>
128
+ <tr>
129
+ <td align='left'>
130
+ Reproducibility limit,
131
+ <stem type='AsciiMath'>R</stem>
132
+ (= 2,83
133
+ <stem type='AsciiMath'>s_R</stem>
134
+ )
135
+ </td>
136
+ <td align='center'>2,89</td>
137
+ <td align='center'>0,57</td>
138
+ <td align='center'>2,26</td>
139
+ <td align='center'>6,06</td>
140
+ </tr>
141
+ </tfoot>
142
+ <dl>
143
+ <dt>Drago</dt>
144
+ <dd>A type of rice</dd>
145
+ </dl>
146
+ <note>
147
+ <name>NOTE</name>
148
+ <p>This is a table about rice</p>
149
+ </note>
150
+ </table>
151
+ </foreword>
152
+ </preface>
153
+ <annex id='Annex' displayorder='2'>
154
+ <title>
155
+ <strong>Annex A</strong>
156
+ <br/>
157
+ (informative)
158
+ <br/>
159
+ <br/>
160
+ <strong>Annex</strong>
161
+ </title>
162
+ <table id='AnnexTable'>
163
+ <name>Table A.1&#xA0;&#x2014; Another table</name>
164
+ <tbody>
165
+ <td>?</td>
166
+ </tbody>
167
+ </table>
168
+ </annex>
169
+ </iso-standard>
170
+ OUTPUT
171
+
172
+ html = <<~OUTPUT
223
173
  <main class='main-section'>
224
174
  <button onclick='topFunction()' id='myBtn' title='Go to top'>Top</button>
225
175
  <br/>
@@ -313,81 +263,27 @@ RSpec.describe IsoDoc do
313
263
  </table>
314
264
  </div>
315
265
  <p class='zzSTDTitle1'/>
266
+ <br/>
267
+ <div id='Annex' class='Section3'>
268
+ <h1 class='Annex' id='toc1'>
269
+ <b>Annex A</b>
270
+ <br/>
271
+ (informative)
272
+ <br/>
273
+ <br/>
274
+ <b>Annex</b>
275
+ </h1>
276
+ <p class='TableTitle' style='text-align:center;'>Table A.1&#xA0;&#x2014; Another table</p>
277
+ <table id='AnnexTable' class='MsoISOTable' style='border-width:1px;border-spacing:0;'>
278
+ <tbody>
279
+ <tr/>
280
+ </tbody>
281
+ </table>
282
+ </div>
316
283
  </main>
317
284
  OUTPUT
318
- end
319
-
320
- it "processes IsoXML tables (Word)" do
321
- IsoDoc::Iso::WordConvert.new({}).convert("test", <<~"INPUT", false)
322
- <iso-standard xmlns="http://riboseinc.com/isoxml">
323
- <preface>
324
- <foreword>
325
- <table alt="tool tip" id="tableD-1" summary="long desc">
326
- <name>Table 1&#xA0;&#x2014; Repeatability and reproducibility of <em>husked</em> rice yield</name>
327
- <thead>
328
- <tr>
329
- <td align="left" rowspan="2">Description</td>
330
- <td align="center" colspan="4">Rice sample</td>
331
- </tr>
332
- <tr>
333
- <td align="left">Arborio</td>
334
- <td align="center">Drago
335
- <fn reference="a">
336
- <p id="_0fe65e9a-5531-408e-8295-eeff35f41a55">Parboiled rice.</p></fn>
337
- </td>
338
- <td align="center">Balilla
339
- <fn reference="a">
340
- <p id="_0fe65e9a-5531-408e-8295-eeff35f41a55">Parboiled rice.</p></fn>
341
- </td>
342
- <td align="center">Thaibonnet</td>
343
- </tr>
344
- </thead>
345
- <tbody>
346
- <tr>
347
- <th align="left">Number of laboratories retained after eliminating outliers</th>
348
- <td align="center">13</td>
349
- <td align="center">11</td>
350
- <td align="center">13</td>
351
- <td align="center">13</td>
352
- </tr>
353
- <tr>
354
- <td align="left">Mean value, g/100 g</td>
355
- <td align="center">81,2</td>
356
- <td align="center">82,0</td>
357
- <td align="center">81,8</td>
358
- <td align="center">77,7</td>
359
- </tr>
360
- </tbody>
361
- <tfoot>
362
- <tr>
363
- <td align="left">Reproducibility limit,
364
- <stem type="AsciiMath">R</stem>
365
- (= 2,83
366
- <stem type="AsciiMath">s_R</stem>
367
- )</td>
368
- <td align="center">2,89</td>
369
- <td align="center">0,57</td>
370
- <td align="center">2,26</td>
371
- <td align="center">6,06</td>
372
- </tr>
373
- </tfoot>
374
- <dl>
375
- <dt>Drago</dt>
376
- <dd>A type of rice</dd>
377
- </dl>
378
- <note>
379
- <name>NOTE</name>
380
- <p>This is a table about rice</p>
381
- </note>
382
- </table>
383
- </foreword>
384
- </preface>
385
- </iso-standard>
386
- INPUT
387
285
 
388
- expect(File.exist?("test.doc")).to be true
389
- html = File.read("test.doc").sub(/^.+?<table /m, '<table xmlns:m="m" ').sub(%r{</div>\s*<p class="MsoNormal">.*$}m, "")
390
- expect(xmlpp("<div>#{html}")).to be_equivalent_to xmlpp(<<~"OUTPUT")
286
+ doc = <<~OUTPUT
391
287
  <div>
392
288
  <table class="MsoISOTable" style="mso-table-anchor-horizontal:column;mso-table-overlap:never;border-spacing:0;border-width:1px;" summary="long desc" title="tool tip" xmlns:m="m">
393
289
  <a id="tableD-1" name="tableD-1"/>
@@ -423,13 +319,13 @@ RSpec.describe IsoDoc do
423
319
  </tbody>
424
320
  <tfoot>
425
321
  <tr>
426
- <td align="left" style="border-top:solid windowtext 1.5pt;mso-border-top-alt:solid windowtext 1.5pt;border-bottom:0pt;mso-border-bottom-alt:0pt;">Reproducibility limit,
322
+ <td align="left" style="border-top:solid windowtext 1.5pt;mso-border-top-alt:solid windowtext 1.5pt;border-bottom:0pt;mso-border-bottom-alt:0pt;">Reproducibility limit,
427
323
  <span class="stem">
428
324
  <m:oMath>
429
325
  <m:r>
430
326
  <m:t>R</m:t></m:r>
431
327
  </m:oMath>
432
- </span>(= 2,83
328
+ </span>(= 2,83
433
329
  <span class="stem">
434
330
  <m:oMath>
435
331
  <m:sSub>
@@ -483,5 +379,44 @@ RSpec.describe IsoDoc do
483
379
  </table>
484
380
  </div>
485
381
  OUTPUT
382
+ doc2 = <<~OUTPUT
383
+ <div class='Section3'>
384
+ <a name='Annex' id='Annex'/>
385
+ <p class='ANNEX'>
386
+ <br/>
387
+ (informative)
388
+ <br/>
389
+ <br/>
390
+ <b>Annex</b>
391
+ </p>
392
+ <p class='AnnexTableTitle' style='text-align:center;'>Table A.1&#xA0;&#x2014; Another table</p>
393
+ <div align='center' class='table_container'>
394
+ <table class='MsoISOTable' style='mso-table-anchor-horizontal:column;mso-table-overlap:never;border-spacing:0;border-width:1px;'>
395
+ <a name='AnnexTable' id='AnnexTable'/>
396
+ <tbody>
397
+ <tr/>
398
+ </tbody>
399
+ </table>
400
+ </div>
401
+ </div>
402
+ OUTPUT
403
+ expect(xmlpp(IsoDoc::Iso::PresentationXMLConvert.new({})
404
+ .convert("test", input, true))).to be_equivalent_to xmlpp(presxml)
405
+ IsoDoc::Iso::HtmlConvert.new({}).convert("test", presxml, false)
406
+ expect(File.exist?("test.html")).to be true
407
+ out = File.read("test.html")
408
+ .sub(/^.*<main /m, "<main ")
409
+ .sub(%r{</main>.*$}m, "</main>")
410
+ expect(xmlpp(out)).to be_equivalent_to xmlpp(html)
411
+ IsoDoc::Iso::WordConvert.new({}).convert("test", presxml, false)
412
+ expect(File.exist?("test.doc")).to be true
413
+ out = File.read("test.doc")
414
+ .sub(/^.+?<table /m, '<table xmlns:m="m" ')
415
+ .sub(%r{</div>\s*<p class="MsoNormal">.*$}m, "")
416
+ expect(xmlpp("<div>#{out}")).to be_equivalent_to xmlpp(doc)
417
+ out = File.read("test.doc")
418
+ .sub(/^.+?<div class="Section3"/m, '<div class="Section3"')
419
+ .sub(%r{</div>\s*<br[^>]+>\s*<div class="colophon".*$}m, "")
420
+ expect(xmlpp(out)).to be_equivalent_to xmlpp(doc2)
486
421
  end
487
422
  end