metanorma-iso 1.10.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +3 -33
  3. data/.github/workflows/ubuntu.yml +1 -1
  4. data/.gitignore +26 -0
  5. data/Gemfile +1 -1
  6. data/Makefile +1 -1
  7. data/lib/asciidoctor/iso/base.rb +2 -69
  8. data/lib/asciidoctor/iso/cleanup.rb +2 -175
  9. data/lib/asciidoctor/iso/converter.rb +2 -17
  10. data/lib/asciidoctor/iso/deprecated.rb +5 -0
  11. data/lib/asciidoctor/iso/front.rb +2 -156
  12. data/lib/asciidoctor/iso/front_id.rb +2 -221
  13. data/lib/asciidoctor/iso/section.rb +2 -48
  14. data/lib/asciidoctor/iso/validate.rb +2 -171
  15. data/lib/asciidoctor/iso/validate_image.rb +2 -96
  16. data/lib/asciidoctor/iso/validate_requirements.rb +2 -110
  17. data/lib/asciidoctor/iso/validate_section.rb +2 -246
  18. data/lib/asciidoctor/iso/validate_style.rb +2 -169
  19. data/lib/asciidoctor/iso/validate_title.rb +2 -104
  20. data/lib/isodoc/iso/base_convert.rb +14 -31
  21. data/lib/isodoc/iso/html/style-human.css +40 -8
  22. data/lib/isodoc/iso/html/style-human.scss +36 -8
  23. data/lib/isodoc/iso/html/style-iso.css +35 -5
  24. data/lib/isodoc/iso/html/style-iso.scss +31 -5
  25. data/lib/isodoc/iso/html/wordstyle.css +10 -8
  26. data/lib/isodoc/iso/html/wordstyle.scss +10 -8
  27. data/lib/isodoc/iso/html_convert.rb +83 -22
  28. data/lib/isodoc/iso/index.rb +53 -45
  29. data/lib/isodoc/iso/iso.amendment.xsl +477 -264
  30. data/lib/isodoc/iso/iso.international-standard.xsl +477 -264
  31. data/lib/isodoc/iso/metadata.rb +27 -22
  32. data/lib/isodoc/iso/presentation_xml_convert.rb +42 -17
  33. data/lib/isodoc/iso/sts_convert.rb +2 -4
  34. data/lib/isodoc/iso/word_convert.rb +0 -2
  35. data/lib/metanorma/iso/base.rb +70 -0
  36. data/lib/{asciidoctor → metanorma}/iso/basicdoc.rng +0 -0
  37. data/lib/{asciidoctor → metanorma}/iso/biblio.rng +0 -0
  38. data/lib/{asciidoctor → metanorma}/iso/boilerplate-fr.xml +0 -0
  39. data/lib/{asciidoctor → metanorma}/iso/boilerplate.xml +0 -0
  40. data/lib/metanorma/iso/cleanup.rb +176 -0
  41. data/lib/metanorma/iso/converter.rb +18 -0
  42. data/lib/metanorma/iso/front.rb +170 -0
  43. data/lib/metanorma/iso/front_id.rb +225 -0
  44. data/lib/{asciidoctor → metanorma}/iso/isodoc.rng +49 -2
  45. data/lib/{asciidoctor → metanorma}/iso/isostandard-amd.rng +0 -0
  46. data/lib/{asciidoctor → metanorma}/iso/isostandard.rnc +0 -0
  47. data/lib/{asciidoctor → metanorma}/iso/isostandard.rng +14 -0
  48. data/lib/{asciidoctor → metanorma}/iso/reqt.rng +0 -0
  49. data/lib/metanorma/iso/section.rb +49 -0
  50. data/lib/metanorma/iso/validate.rb +172 -0
  51. data/lib/metanorma/iso/validate_image.rb +97 -0
  52. data/lib/metanorma/iso/validate_requirements.rb +111 -0
  53. data/lib/metanorma/iso/validate_section.rb +247 -0
  54. data/lib/metanorma/iso/validate_style.rb +170 -0
  55. data/lib/metanorma/iso/validate_title.rb +105 -0
  56. data/lib/metanorma/iso/version.rb +1 -1
  57. data/lib/metanorma-iso.rb +1 -1
  58. data/metanorma-iso.gemspec +2 -2
  59. data/spec/isodoc/amd_spec.rb +261 -250
  60. data/spec/isodoc/inline_spec.rb +238 -212
  61. data/spec/isodoc/iso_spec.rb +3 -1
  62. data/spec/isodoc/postproc_spec.rb +111 -28
  63. data/spec/isodoc/ref_spec.rb +4 -2
  64. data/spec/isodoc/section_spec.rb +1 -1
  65. data/spec/isodoc/terms_spec.rb +17 -24
  66. data/spec/{asciidoctor → metanorma}/amd_spec.rb +1 -1
  67. data/spec/metanorma/base_spec.rb +1185 -0
  68. data/spec/{asciidoctor → metanorma}/blank_spec.rb +1 -1
  69. data/spec/{asciidoctor → metanorma}/blocks_spec.rb +1 -1
  70. data/spec/{asciidoctor → metanorma}/cleanup_spec.rb +1 -1
  71. data/spec/{asciidoctor → metanorma}/inline_spec.rb +1 -1
  72. data/spec/{asciidoctor → metanorma}/lists_spec.rb +1 -1
  73. data/spec/metanorma/processor_spec.rb +1 -1
  74. data/spec/{asciidoctor → metanorma}/refs_spec.rb +1 -1
  75. data/spec/{asciidoctor → metanorma}/section_spec.rb +1 -1
  76. data/spec/{asciidoctor → metanorma}/table_spec.rb +1 -1
  77. data/spec/{asciidoctor → metanorma}/validate_spec.rb +1 -1
  78. data/spec/spec_helper.rb +1 -1
  79. data/spec/vcr_cassettes/docrels.yml +35 -425
  80. metadata +40 -27
  81. data/spec/asciidoctor/base_spec.rb +0 -1333
@@ -140,7 +140,7 @@ span.title {
140
140
 
141
141
  /* TYPOGRAPHY */
142
142
 
143
- h1 {
143
+ h1, .h1 {
144
144
  font-weight: 900;
145
145
  }
146
146
 
@@ -148,18 +148,19 @@ h2,
148
148
  h3,
149
149
  h4,
150
150
  h5,
151
- h6 {
151
+ h6,
152
+ .h2, .h3, .h4, .h5, .h6{
152
153
  font-weight: 700;
153
154
  }
154
155
 
155
- h1 {
156
+ h1, .h1 {
156
157
  font-size: 1.5em;
157
158
  line-height: 2em;
158
159
  margin-top: 2em;
159
160
  margin-bottom: 1em;
160
161
  }
161
162
 
162
- h2 {
163
+ h2, .h2 {
163
164
  font-size: 1.2em;
164
165
  line-height: 1.5em;
165
166
  margin-top: 2em;
@@ -171,7 +172,8 @@ h2,
171
172
  h3,
172
173
  h4,
173
174
  h5,
174
- h6 {
175
+ h6,
176
+ .h1, .h2, .h3, .h4, .h5, .h6 {
175
177
  line-height: 1.2;
176
178
  }
177
179
 
@@ -179,7 +181,7 @@ h6 {
179
181
 
180
182
  {% if doctype == "Amendment" or doctype == "Technical Corrigendum" %}
181
183
 
182
- h1, h2, h3, h4, h5, h6 {
184
+ h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 {
183
185
  font-weight: normal;
184
186
  font-size: initial;
185
187
  font-style: italic;
@@ -190,7 +192,7 @@ h1, h2, h3, h4, h5, h6 {
190
192
 
191
193
  {% endif %}
192
194
 
193
- h2 p {
195
+ h2 p, .h2 p {
194
196
  display: inline;
195
197
  }
196
198
 
@@ -218,7 +220,7 @@ a {
218
220
  text-decoration-color: black;
219
221
  }
220
222
 
221
- h2 p {
223
+ h2 p, .h2 p {
222
224
  display: inline;
223
225
  }
224
226
 
@@ -692,3 +694,29 @@ span.keyword {
692
694
  .admonition p {
693
695
  margin: 0;
694
696
  }
697
+
698
+ /* Collapse TOC */
699
+
700
+ .collapse-group {
701
+ display: flex;
702
+ align-items: center;
703
+ position: relative;
704
+ }
705
+
706
+ .collapse-button {
707
+ position: absolute;
708
+ right: 0;
709
+ display: inline-block;
710
+ height: 20px;
711
+ width: 20px;
712
+ cursor: pointer;
713
+ background-image: url('data:image/svg+xml,<svg focusable="false" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="rgba(0,0,0,.54)" d="M16.59 8.59L12 13.17 7.41 8.59 6 10l6 6 6-6z"></path></svg>');
714
+ }
715
+
716
+ .collapse {
717
+ display: none;
718
+ }
719
+
720
+ .expand {
721
+ transform: rotateZ(-180deg);
722
+ }
@@ -75,6 +75,12 @@ code *, pre *, tt *, kbd *, samp * {
75
75
  font-family: {{monospacefont}} !important;
76
76
  font-variant-ligatures: none; }
77
77
 
78
+ p code, dt code, li code, label code, legend code, caption code, th code, td code,
79
+ p tt, dt tt, li tt, label tt, legend tt, caption tt, th tt, td tt,
80
+ p kbd, dt kbd, li kbd, label kbd, legend kbd, caption kbd, th kbd, td kbd,
81
+ p samp, dt samp, li samp, label samp, legend samp, caption samp, th samp, td samp {
82
+ font-size: {{monospacefontsize}}; }
83
+
78
84
  article, aside, details, figcaption, figure,
79
85
  footer, header, hgroup, menu, nav, section {
80
86
  display: block; }
@@ -86,6 +92,9 @@ table {
86
92
  h1, h2, h3, h4, h5, h6 {
87
93
  font-family: {{headerfont}}; }
88
94
 
95
+ .h1, .h2, .h3, .h4, .h5, .h6 {
96
+ font-family: {{headerfont}}; }
97
+
89
98
  blockquote, q {
90
99
  quotes: none; }
91
100
  blockquote:before, blockquote:after, q:before, q:after {
@@ -315,23 +324,23 @@ span.partlabel {
315
324
  font-size: 0.9em; }
316
325
 
317
326
  /* TYPOGRAPHY */
318
- h1 {
327
+ h1, .h1 {
319
328
  font-size: 1.5em;
320
329
  line-height: 2em;
321
330
  margin-top: 2em;
322
331
  margin-bottom: 1em; }
323
332
 
324
- h2 {
333
+ h2, .h2 {
325
334
  font-size: 1.2em;
326
335
  line-height: 1.5em;
327
336
  margin-top: 2em;
328
337
  margin-bottom: 1em; }
329
338
 
330
- h1, h2, h3, h4, h5, h6 {
339
+ h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 {
331
340
  line-height: 1.2; }
332
341
 
333
342
  {% if doctype == "Amendment" or doctype == "Technical Corrigendum" %}
334
- h1, h2, h3, h4, h5, h6 {
343
+ h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 {
335
344
  font-weight: normal;
336
345
  font-size: initial;
337
346
  font-style: italic; }
@@ -355,7 +364,7 @@ a {
355
364
  color: black;
356
365
  text-decoration-color: black; }
357
366
 
358
- h2 p {
367
+ h2 p, .h2 p {
359
368
  display: inline; }
360
369
 
361
370
  ul > li {
@@ -1004,3 +1013,24 @@ span.keyword {
1004
1013
 
1005
1014
  .Admonition p, .admonition p {
1006
1015
  margin: 0; }
1016
+
1017
+ /* Collapse TOC */
1018
+ .collapse-group {
1019
+ display: flex;
1020
+ align-items: center;
1021
+ position: relative; }
1022
+
1023
+ .collapse-button {
1024
+ position: absolute;
1025
+ right: 0;
1026
+ display: inline-block;
1027
+ height: 20px;
1028
+ width: 20px;
1029
+ cursor: pointer;
1030
+ background-image: url('data:image/svg+xml,<svg focusable="false" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="rgba(0,0,0,.54)" d="M16.59 8.59L12 13.17 7.41 8.59 6 10l6 6 6-6z"></path></svg>'); }
1031
+
1032
+ .collapse {
1033
+ display: none; }
1034
+
1035
+ .expand {
1036
+ transform: rotateZ(-180deg); }
@@ -112,27 +112,27 @@ span.partlabel {
112
112
 
113
113
  /* TYPOGRAPHY */
114
114
 
115
- h1 {
115
+ h1, .h1 {
116
116
  font-size: 1.5em;
117
117
  line-height: 2em;
118
118
  margin-top: 2em;
119
119
  margin-bottom: 1em;
120
120
  }
121
121
 
122
- h2 {
122
+ h2, .h2 {
123
123
  font-size: 1.2em;
124
124
  line-height: 1.5em;
125
125
  margin-top: 2em;
126
126
  margin-bottom: 1em;
127
127
  }
128
128
 
129
- h1, h2, h3, h4, h5, h6 {
129
+ h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 {
130
130
  line-height: 1.2;
131
131
  }
132
132
 
133
133
  {% if doctype == "Amendment" or doctype == "Technical Corrigendum" %}
134
134
 
135
- h1, h2, h3, h4, h5, h6 {
135
+ h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 {
136
136
  font-weight: normal;
137
137
  font-size: initial;
138
138
  font-style: italic;
@@ -164,7 +164,7 @@ a {
164
164
  text-decoration-color: black;
165
165
  }
166
166
 
167
- h2 p {
167
+ h2 p, .h2 p {
168
168
  display: inline;
169
169
  }
170
170
 
@@ -709,3 +709,29 @@ font-weight: 600;
709
709
  .Admonition p, .admonition p {
710
710
  margin: 0;
711
711
  }
712
+
713
+ /* Collapse TOC */
714
+
715
+ .collapse-group {
716
+ display: flex;
717
+ align-items: center;
718
+ position: relative;
719
+ }
720
+
721
+ .collapse-button {
722
+ position: absolute;
723
+ right: 0;
724
+ display: inline-block;
725
+ height: 20px;
726
+ width: 20px;
727
+ cursor: pointer;
728
+ background-image: url('data:image/svg+xml,<svg focusable="false" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="rgba(0,0,0,.54)" d="M16.59 8.59L12 13.17 7.41 8.59 6 10l6 6 6-6z"></path></svg>');
729
+ }
730
+
731
+ .collapse {
732
+ display: none;
733
+ }
734
+
735
+ .expand {
736
+ transform: rotateZ(-180deg);
737
+ }
@@ -289,7 +289,7 @@ p.MsoListParagraphCxSpLast, li.MsoListParagraphCxSpLast, div.MsoListParagraphCxS
289
289
  div.figure, p.figure {
290
290
  text-align: center; }
291
291
 
292
- h1 {
292
+ h1, .h1 {
293
293
  mso-style-priority: 1;
294
294
  mso-style-unhide: no;
295
295
  mso-style-qformat: yes;
@@ -304,8 +304,6 @@ h1 {
304
304
  line-height: 13.5pt;
305
305
  mso-pagination: widow-orphan;
306
306
  page-break-after: avoid;
307
- mso-outline-level: 1;
308
- mso-list: l1 level1 lfo6;
309
307
  mso-hyphenate: none;
310
308
  tab-stops: 20.0pt list 21.6pt left 28.0pt;
311
309
  {% if doctype == "Amendment" or doctype == "Technical Corrigendum" %}
@@ -324,6 +322,10 @@ h1 {
324
322
  mso-fareast-language: JA;
325
323
  mso-bidi-font-weight: normal; }
326
324
 
325
+ h1 {
326
+ mso-outline-level: 1;
327
+ mso-list: l1 level1 lfo6; }
328
+
327
329
  h1.ForewordTitle {
328
330
  font-size: 13.0pt;
329
331
  font-style: normal;
@@ -358,7 +360,7 @@ h1.Annex {
358
360
  mso-fareast-language: JA;
359
361
  mso-bidi-font-weight: normal; }
360
362
 
361
- .h2Annex, h2 {
363
+ .h2Annex, h2, .h2 {
362
364
  mso-style-priority: 2;
363
365
  mso-style-unhide: no;
364
366
  mso-style-qformat: yes;
@@ -395,7 +397,7 @@ h2 {
395
397
  mso-list: l1 level2 lfo6;
396
398
  mso-outline-level: 2; }
397
399
 
398
- .h3Annex, h3 {
400
+ .h3Annex, h3, .h3 {
399
401
  mso-style-priority: 3;
400
402
  mso-style-unhide: no;
401
403
  mso-style-qformat: yes;
@@ -432,7 +434,7 @@ h3 {
432
434
  mso-list: l1 level3 lfo6;
433
435
  mso-outline-level: 3; }
434
436
 
435
- .h4Annex, h4 {
437
+ .h4Annex, h4, .h4 {
436
438
  mso-style-priority: 4;
437
439
  mso-style-unhide: no;
438
440
  mso-style-qformat: yes;
@@ -467,7 +469,7 @@ h4 {
467
469
  mso-list: l1 level4 lfo6;
468
470
  mso-outline-level: 4; }
469
471
 
470
- .h5Annex, h5 {
472
+ .h5Annex, h5, .h5 {
471
473
  mso-style-priority: 5;
472
474
  mso-style-unhide: no;
473
475
  mso-style-qformat: yes;
@@ -502,7 +504,7 @@ h5 {
502
504
  mso-list: l1 level5 lfo6;
503
505
  mso-outline-level: 5; }
504
506
 
505
- h6 {
507
+ h6, .h6 {
506
508
  mso-style-priority: 6;
507
509
  mso-style-unhide: no;
508
510
  mso-style-qformat: yes;
@@ -269,7 +269,7 @@ p.MsoListParagraphCxSpLast, li.MsoListParagraphCxSpLast, div.MsoListParagraphCxS
269
269
  div.figure, p.figure
270
270
  {text-align: center;}
271
271
 
272
- h1
272
+ h1, .h1
273
273
  {mso-style-priority:1;
274
274
  mso-style-unhide:no;
275
275
  mso-style-qformat:yes;
@@ -284,8 +284,6 @@ h1
284
284
  line-height:13.5pt;
285
285
  mso-pagination:widow-orphan;
286
286
  page-break-after:avoid;
287
- mso-outline-level:1;
288
- mso-list:l1 level1 lfo6;
289
287
  mso-hyphenate:none;
290
288
  tab-stops:20.0pt list 21.6pt left 28.0pt;
291
289
  {% if doctype == "Amendment" or doctype == "Technical Corrigendum" %}
@@ -303,6 +301,10 @@ h1
303
301
  mso-ansi-language:EN-GB;
304
302
  mso-fareast-language:JA;
305
303
  mso-bidi-font-weight:normal;}
304
+ h1 {
305
+ mso-outline-level:1;
306
+ mso-list:l1 level1 lfo6;
307
+ }
306
308
  h1.ForewordTitle {
307
309
  font-size:13.0pt;
308
310
  font-style: normal ;
@@ -336,7 +338,7 @@ h1.Annex
336
338
  mso-ansi-language:EN-GB;
337
339
  mso-fareast-language:JA;
338
340
  mso-bidi-font-weight:normal;}
339
- .h2Annex, h2
341
+ .h2Annex, h2, .h2
340
342
  {mso-style-priority:2;
341
343
  mso-style-unhide:no;
342
344
  mso-style-qformat:yes;
@@ -372,7 +374,7 @@ h2
372
374
  { mso-list:l1 level2 lfo6;
373
375
  mso-outline-level:2;
374
376
  }
375
- .h3Annex, h3
377
+ .h3Annex, h3, .h3
376
378
  {mso-style-priority:3;
377
379
  mso-style-unhide:no;
378
380
  mso-style-qformat:yes;
@@ -407,7 +409,7 @@ h2
407
409
  h3 {mso-list:l1 level3 lfo6;
408
410
  mso-outline-level:3;
409
411
  }
410
- .h4Annex, h4
412
+ .h4Annex, h4, .h4
411
413
  {mso-style-priority:4;
412
414
  mso-style-unhide:no;
413
415
  mso-style-qformat:yes;
@@ -440,7 +442,7 @@ h3 {mso-list:l1 level3 lfo6;
440
442
  h4 {mso-list:l1 level4 lfo6;
441
443
  mso-outline-level:4;
442
444
  }
443
- .h5Annex, h5
445
+ .h5Annex, h5, .h5
444
446
  {mso-style-priority:5;
445
447
  mso-style-unhide:no;
446
448
  mso-style-qformat:yes;
@@ -473,7 +475,7 @@ h4 {mso-list:l1 level4 lfo6;
473
475
  h5 {mso-list:l1 level5 lfo6;
474
476
  mso-outline-level:5;
475
477
  }
476
- h6
478
+ h6, .h6
477
479
  {mso-style-priority:6;
478
480
  mso-style-unhide:no;
479
481
  mso-style-qformat:yes;
@@ -10,39 +10,100 @@ module IsoDoc
10
10
  super
11
11
  end
12
12
 
13
- def googlefonts()
14
- <<~HEAD.freeze
15
- <link href="https://fonts.googleapis.com/css?family=Space+Mono:400,400i,700,700i&display=swap" rel="stylesheet">
16
- <link href="https://fonts.googleapis.com/css?family=Lato:400,400i,700,900" rel="stylesheet">
17
- HEAD
18
- end
13
+ def googlefonts
14
+ <<~HEAD.freeze
15
+ <link href="https://fonts.googleapis.com/css?family=Space+Mono:400,400i,700,700i&display=swap" rel="stylesheet">
16
+ <link href="https://fonts.googleapis.com/css?family=Lato:400,400i,700,900" rel="stylesheet">
17
+ HEAD
18
+ end
19
19
 
20
20
  def default_fonts(options)
21
21
  {
22
- bodyfont: (options[:script] == "Hans" ? '"Source Han Sans",serif' :
23
- options[:alt] ? '"Lato",sans-serif' : '"Cambria",serif'),
24
- headerfont: (options[:script] == "Hans" ? '"Source Han Sans",sans-serif' :
25
- options[:alt] ? '"Lato",sans-serif' : '"Cambria",serif'),
26
- monospacefont: (options[:alt] ? '"Space Mono",monospace' :
27
- '"Courier New",monospace'),
28
- normalfontsize: "1.0em",
29
- smallerfontsize: "0.9em",
30
- footnotefontsize: "0.9em",
31
- monospacefontsize: "0.8em",
22
+ bodyfont: (if options[:script] == "Hans"
23
+ '"Source Han Sans",serif'
24
+ else
25
+ options[:alt] ? '"Lato",sans-serif' : '"Cambria",serif'
26
+ end),
27
+ headerfont: (if options[:script] == "Hans"
28
+ '"Source Han Sans",sans-serif'
29
+ else
30
+ options[:alt] ? '"Lato",sans-serif' : '"Cambria",serif'
31
+ end),
32
+ monospacefont: (if options[:alt]
33
+ '"Space Mono",monospace'
34
+ else
35
+ '"Courier New",monospace'
36
+ end),
37
+ normalfontsize: "1.0em",
38
+ smallerfontsize: "0.9em",
39
+ footnotefontsize: "0.9em",
40
+ monospacefontsize: "0.8em",
32
41
  }
33
42
  end
34
43
 
35
44
  def default_file_locations(options)
36
45
  {
37
- htmlstylesheet: (options[:alt] ? html_doc_path("style-human.scss") :
38
- html_doc_path("style-iso.scss")),
39
- htmlcoverpage: html_doc_path("html_iso_titlepage.html"),
40
- htmlintropage: html_doc_path("html_iso_intro.html"),
46
+ htmlstylesheet: (if options[:alt]
47
+ html_doc_path("style-human.scss")
48
+ else
49
+ html_doc_path("style-iso.scss")
50
+ end),
51
+ htmlcoverpage: html_doc_path("html_iso_titlepage.html"),
52
+ htmlintropage: html_doc_path("html_iso_intro.html"),
41
53
  }
42
54
  end
43
55
 
44
- def footnote_reference_format(a)
45
- a.content = a.content + ")"
56
+ def footnote_reference_format(link)
57
+ link.content += ")"
58
+ end
59
+
60
+ def html_toc_entry(level, header)
61
+ content = header.at("./following-sibling::p"\
62
+ "[@class = 'variant-title-toc']") || header
63
+ if level == "h1" &&
64
+ header.parent.at(".//h2#{toc_exclude_class}")
65
+ <<~HDR
66
+ <li class="#{level}"><div class="collapse-group"><a href="##{header['id']}">#{header_strip(content)}</a></li>
67
+ <div class="collapse-button"></div></div>
68
+ HDR
69
+ else
70
+ %(<li class="#{level}"><a href="##{header['id']}">\
71
+ #{header_strip(content)}</a></li>)
72
+ end
73
+ end
74
+
75
+ def html_toc(docxml)
76
+ super
77
+ docxml.xpath("//div[@id = 'toc']/ul[li[@class = 'h2']]").each do |u|
78
+ html_toc1(u)
79
+ end
80
+ docxml
81
+ end
82
+
83
+ def html_toc1(ulist)
84
+ u2 = nil
85
+ ulist.xpath("./li").each do |l|
86
+ if l["class"] != "h2"
87
+ u2 = nil
88
+ elsif u2 then u2.add_child(l.remove)
89
+ else
90
+ u2 = l.replace("<ul class='content collapse'>#{l}</ul>").first
91
+ p = u2.previous_element and p << u2
92
+ end
93
+ end
94
+ end
95
+
96
+ def inject_script(doc)
97
+ scr = <<~HEAD.freeze
98
+ <script>
99
+ $(".collapse-button").click(function () {
100
+ $(this).toggleClass('expand'); // expand: the class to change the collapse button shape
101
+ // collapse: the class to collapse/expand the li elements with the h2 class
102
+ $(this).closest('li').children(".content").toggleClass('collapse');})
103
+ </script>
104
+ HEAD
105
+ a = super.split(%r{</body>})
106
+ "#{a[0]}#{scr}</body>#{a[1]}"
46
107
  end
47
108
 
48
109
  def table_th_center(docxml)
@@ -5,32 +5,36 @@ module IsoDoc
5
5
  %(id="_#{UUIDTools::UUID.random_create}")
6
6
  end
7
7
 
8
- def index(docxml)
9
- unless docxml.at(ns("//index"))
10
- docxml.xpath(ns("//indexsect")).each(&:remove)
11
- return
8
+ def index(xml)
9
+ if xml.at(ns("//index"))
10
+ i = xml.at(ns("//indexsect")) ||
11
+ xml.root.add_child("<indexsect #{add_id}><title>#{@i18n.index}"\
12
+ "</title></indexsect>").first
13
+ index = sort_indexterms(xml.xpath(ns("//index")),
14
+ xml.xpath(ns("//index-xref[@also = 'false']")),
15
+ xml.xpath(ns("//index-xref[@also = 'true']")))
16
+ index1(xml, i, index)
17
+ else xml.xpath(ns("//indexsect")).each(&:remove)
12
18
  end
13
- i = docxml.at(ns("//indexsect")) ||
14
- docxml.root.add_child("<indexsect #{add_id}><title>#{@i18n.index}</title></indexsect>").first
15
- index = sort_indexterms(docxml.xpath(ns("//index")),
16
- docxml.xpath(ns("//index-xref[@also = 'false']")),
17
- docxml.xpath(ns("//index-xref[@also = 'true']")))
18
- index1(docxml, i, index)
19
19
  end
20
20
 
21
- def index1(docxml, i, index)
22
- c = i.add_child("<ul></ul>").first
21
+ def index1(docxml, indexsect, index)
22
+ c = indexsect.add_child("<ul></ul>").first
23
23
  index.keys.sort.each do |k|
24
- # c = i.add_child "<clause #{add_id}><title>#{k}</title><ul></ul></clause>"
25
24
  words = index[k].keys.each_with_object({}) do |w, v|
26
25
  v[sortable(w).downcase] = w
27
26
  end
28
27
  words.keys.localize(@lang.to_sym).sort.to_a.each do |w|
29
- # c.first.at(ns("./ul")).add_child index_entries(words, index[k], w)
30
28
  c.add_child index_entries(words, index[k], w)
31
29
  end
32
30
  end
33
- docxml.xpath(ns("//indexsect//xref")).each { |x| x.children.remove }
31
+ index1_cleanup(docxml)
32
+ end
33
+
34
+ def index1_cleanup(docxml)
35
+ docxml.xpath(ns("//indexsect//xref")).each do |x|
36
+ x.children.remove
37
+ end
34
38
  @xrefs.bookmark_anchor_names(docxml)
35
39
  end
36
40
 
@@ -56,7 +60,7 @@ module IsoDoc
56
60
  end
57
61
  ret += "</ul>"
58
62
  end
59
- ret + "</li>"
63
+ "#{ret}</li>"
60
64
  end
61
65
 
62
66
  def index_entries2(words, index, secondary)
@@ -75,30 +79,29 @@ module IsoDoc
75
79
  end
76
80
  ret += "</ul>"
77
81
  end
78
- ret + "</li>"
82
+ "#{ret}</li>"
79
83
  end
80
84
 
81
85
  def index_entries_head(head, entries, opt)
82
86
  ret = "<li>#{head}"
83
87
  xref = entries&.dig(:xref)&.join(", ")
84
- see_sort = entries&.dig(:see)&.each_with_object({}) do |w, v|
85
- v[sortable(w).downcase] = w
86
- end
87
- see = see_sort&.keys&.localize(@lang.to_sym)&.sort&.to_a&.map do |k|
88
- see_sort[k]
89
- end&.join(", ")
90
- also_sort = entries&.dig(:also)&.each_with_object({}) do |w, v|
91
- v[sortable(w).downcase] = w
92
- end
93
- also = also_sort&.keys&.localize(@lang.to_sym)&.sort&.to_a&.map do |k|
94
- also_sort[k]
95
- end&.join(", ")
88
+ see = index_entries_see(entries, :see)
89
+ also = index_entries_see(entries, :also)
96
90
  ret += "#{opt[:xref_lbl]} #{xref}" if xref
97
91
  ret += "#{opt[:see_lbl]} #{see}" if see
98
92
  ret += "#{opt[:also_lbl]} #{also}" if also
99
93
  ret
100
94
  end
101
95
 
96
+ def index_entries_see(entries, label)
97
+ see_sort = entries&.dig(label)&.each_with_object({}) do |w, v|
98
+ v[sortable(w).downcase] = w
99
+ end
100
+ see_sort&.keys&.localize(@lang.to_sym)&.sort&.to_a&.map do |k|
101
+ see_sort[k]
102
+ end&.join(", ")
103
+ end
104
+
102
105
  def see_lbl
103
106
  @lang == "en" ? @i18n.see : "<em>#{@i18n.see}</em>"
104
107
  end
@@ -119,13 +122,8 @@ module IsoDoc
119
122
 
120
123
  def extract_indexsee(val, terms, label)
121
124
  terms.each_with_object(val) do |t, v|
122
- term = t&.at(ns("./primary"))&.children&.to_xml
123
- term2 = t&.at(ns("./secondary"))&.children&.to_xml
124
- term3 = t&.at(ns("./tertiary"))&.children&.to_xml
125
- v[term] ||= {}
126
- v[term][term2] ||= {}
127
- v[term][term2][term3] ||= {}
128
- v[term][term2][term3][label] ||= []
125
+ term, term2, term3 = extract_indexterms_init(t)
126
+ term_hash_init(v, term, term2, term3, label)
129
127
  v[term][term2][term3][label] << t&.at(ns("./target"))&.children&.to_xml
130
128
  t.remove
131
129
  end
@@ -138,22 +136,32 @@ module IsoDoc
138
136
  end
139
137
  end
140
138
 
141
- # attributes are decoded into UTF-8, elements in extract_indexsee are still in entities
139
+ # attributes are decoded into UTF-8,
140
+ # elements in extract_indexsee are still in entities
142
141
  def extract_indexterms(terms)
143
142
  terms.each_with_object({}) do |t, v|
144
- term = t&.at(ns("./primary"))&.children&.to_xml
145
- term2 = t&.at(ns("./secondary"))&.children&.to_xml
146
- term3 = t&.at(ns("./tertiary"))&.children&.to_xml
143
+ term, term2, term3 = extract_indexterms_init(t)
147
144
  index2bookmark(t)
148
- v[term] ||= {}
149
- v[term][term2] ||= {}
150
- v[term][term2][term3] ||= {}
151
- v[term][term2][term3][:xref] ||= []
145
+ term_hash_init(v, term, term2, term3, :xref)
152
146
  to = t["to"] ? "to='#{t['to']}' " : ""
153
- v[term][term2][term3][:xref] << "<xref target='#{t['id']}' #{to}pagenumber='true'/>"
147
+ v[term][term2][term3][:xref] << "<xref target='#{t['id']}' "\
148
+ "#{to}pagenumber='true'/>"
149
+ end
150
+ end
151
+
152
+ def extract_indexterms_init(term)
153
+ %w(primary secondary tertiary).each_with_object([]) do |x, m|
154
+ m << term&.at(ns("./#{x}"))&.children&.to_xml
154
155
  end
155
156
  end
156
157
 
158
+ def term_hash_init(hash, term, term2, term3, label)
159
+ hash[term] ||= {}
160
+ hash[term][term2] ||= {}
161
+ hash[term][term2][term3] ||= {}
162
+ hash[term][term2][term3][label] ||= []
163
+ end
164
+
157
165
  def index2bookmark(node)
158
166
  node.name = "bookmark"
159
167
  node.children.each(&:remove)