metanorma-standoc 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +7 -0
  2. data/.gitattributes +4 -0
  3. data/.gitignore +11 -0
  4. data/.hound.yml +3 -0
  5. data/.oss-guides.rubocop.yml +1077 -0
  6. data/.rubocop.ribose.yml +66 -0
  7. data/.rubocop.tb.yml +650 -0
  8. data/.rubocop.yml +15 -0
  9. data/.travis.yml +21 -0
  10. data/CODE_OF_CONDUCT.md +46 -0
  11. data/Gemfile +7 -0
  12. data/LICENSE +25 -0
  13. data/Makefile +39 -0
  14. data/README.adoc +9 -0
  15. data/Rakefile +6 -0
  16. data/bin/rspec +18 -0
  17. data/docs/customisation.adoc +178 -0
  18. data/docs/guidance.adoc +436 -0
  19. data/docs/htmloutput.adoc +115 -0
  20. data/docs/quickstart.adoc +375 -0
  21. data/lib/asciidoctor/standoc/base.rb +198 -0
  22. data/lib/asciidoctor/standoc/biblio.rng +836 -0
  23. data/lib/asciidoctor/standoc/blocks.rb +190 -0
  24. data/lib/asciidoctor/standoc/cleanup.rb +247 -0
  25. data/lib/asciidoctor/standoc/cleanup_block.rb +193 -0
  26. data/lib/asciidoctor/standoc/cleanup_footnotes.rb +78 -0
  27. data/lib/asciidoctor/standoc/cleanup_ref.rb +125 -0
  28. data/lib/asciidoctor/standoc/converter.rb +55 -0
  29. data/lib/asciidoctor/standoc/front.rb +121 -0
  30. data/lib/asciidoctor/standoc/inline.rb +134 -0
  31. data/lib/asciidoctor/standoc/isodoc.rng +1059 -0
  32. data/lib/asciidoctor/standoc/lists.rb +87 -0
  33. data/lib/asciidoctor/standoc/macros.rb +95 -0
  34. data/lib/asciidoctor/standoc/ref.rb +187 -0
  35. data/lib/asciidoctor/standoc/section.rb +159 -0
  36. data/lib/asciidoctor/standoc/table.rb +61 -0
  37. data/lib/asciidoctor/standoc/utils.rb +121 -0
  38. data/lib/asciidoctor/standoc/validate.rb +65 -0
  39. data/lib/asciidoctor/standoc/validate_section.rb +42 -0
  40. data/lib/asciidoctor/standoc/version.rb +5 -0
  41. data/lib/metanorma-standoc.rb +9 -0
  42. data/lib/metanorma/standoc.rb +7 -0
  43. data/lib/metanorma/standoc/processor.rb +40 -0
  44. data/metanorma-standoc.gemspec +47 -0
  45. data/spec/asciidoctor-standoc/base_spec.rb +271 -0
  46. data/spec/asciidoctor-standoc/blocks_spec.rb +469 -0
  47. data/spec/asciidoctor-standoc/cleanup_spec.rb +760 -0
  48. data/spec/asciidoctor-standoc/inline_spec.rb +162 -0
  49. data/spec/asciidoctor-standoc/isobib_cache_spec.rb +332 -0
  50. data/spec/asciidoctor-standoc/lists_spec.rb +190 -0
  51. data/spec/asciidoctor-standoc/macros_spec.rb +111 -0
  52. data/spec/asciidoctor-standoc/refs_spec.rb +606 -0
  53. data/spec/asciidoctor-standoc/section_spec.rb +310 -0
  54. data/spec/asciidoctor-standoc/table_spec.rb +307 -0
  55. data/spec/asciidoctor-standoc/validate_spec.rb +133 -0
  56. data/spec/assets/header.html +7 -0
  57. data/spec/assets/html.css +2 -0
  58. data/spec/assets/htmlcover.html +4 -0
  59. data/spec/assets/htmlintro.html +5 -0
  60. data/spec/assets/i18n.yaml +2 -0
  61. data/spec/assets/iso.headless.html +33 -0
  62. data/spec/assets/iso.xml +8 -0
  63. data/spec/assets/rice_image1.png +0 -0
  64. data/spec/assets/scripts.html +3 -0
  65. data/spec/assets/std.css +2 -0
  66. data/spec/assets/word.css +2 -0
  67. data/spec/assets/wordcover.html +3 -0
  68. data/spec/assets/wordintro.html +4 -0
  69. data/spec/examples/103_01_02.html +247 -0
  70. data/spec/examples/english.yaml +69 -0
  71. data/spec/examples/iso_123_.xml +45 -0
  72. data/spec/examples/iso_123_all_parts.xml +45 -0
  73. data/spec/examples/iso_123_no_year_note.xml +46 -0
  74. data/spec/examples/iso_124_.xml +41 -0
  75. data/spec/examples/iso_216_.xml +47 -0
  76. data/spec/examples/iso_iec_12382_.xml +48 -0
  77. data/spec/examples/rice.adoc +715 -0
  78. data/spec/examples/rice.preview.html +1877 -0
  79. data/spec/examples/rice.sh +4 -0
  80. data/spec/examples/rice_images/rice_image1.png +0 -0
  81. data/spec/examples/rice_images/rice_image2.png +0 -0
  82. data/spec/examples/rice_images/rice_image3_1.png +0 -0
  83. data/spec/examples/rice_images/rice_image3_2.png +0 -0
  84. data/spec/examples/rice_images/rice_image3_3.png +0 -0
  85. data/spec/metanorma/processor_spec.rb +70 -0
  86. data/spec/spec_helper.rb +198 -0
  87. metadata +370 -0
@@ -0,0 +1,469 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Asciidoctor::Standoc do
4
+ it "processes open blocks" do
5
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
6
+ #{ASCIIDOC_BLANK_HDR}
7
+ --
8
+ x
9
+
10
+ y
11
+
12
+ z
13
+ --
14
+ INPUT
15
+ #{BLANK_HDR}
16
+ <sections><p id="_">x</p>
17
+ <p id="_">y</p>
18
+ <p id="_">z</p></sections>
19
+ </standard-document>
20
+ OUTPUT
21
+ end
22
+
23
+ it "processes stem blocks" do
24
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
25
+ #{ASCIIDOC_BLANK_HDR}
26
+ [stem]
27
+ ++++
28
+ r = 1 %
29
+ r = 1 %
30
+ ++++
31
+
32
+ [stem]
33
+ ++++
34
+ <mml:math><mml:msub xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"> <mml:mrow> <mml:mrow> <mml:mi mathvariant="bold-italic">F</mml:mi> </mml:mrow> </mml:mrow> <mml:mrow> <mml:mrow> <mml:mi mathvariant="bold-italic">&#x0391;</mml:mi> </mml:mrow> </mml:mrow> </mml:msub> </mml:math>
35
+ ++++
36
+ INPUT
37
+ #{BLANK_HDR}
38
+ <sections>
39
+ <formula id="_">
40
+ <stem type="AsciiMath">r = 1 %
41
+ r = 1 %</stem>
42
+ </formula>
43
+
44
+ <formula id="_">
45
+ <stem type="MathML"><math xmlns="http://www.w3.org/1998/Math/MathML"><msub> <mrow> <mrow> <mi mathvariant="bold-italic">F</mi> </mrow> </mrow> <mrow> <mrow> <mi mathvariant="bold-italic">Α</mi> </mrow> </mrow> </msub> </math></stem>
46
+ </stem>
47
+ </formula>
48
+ </sections>
49
+ </standard-document>
50
+ OUTPUT
51
+ end
52
+
53
+ it "ignores review blocks unless document is in draft mode" do
54
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
55
+ #{ASCIIDOC_BLANK_HDR}
56
+ [[foreword]]
57
+ .Foreword
58
+ Foreword
59
+
60
+ [reviewer=ISO,date=20170101,from=foreword,to=foreword]
61
+ ****
62
+ A Foreword shall appear in each document. The generic text is shown here. It does not contain requirements, recommendations or permissions.
63
+
64
+ For further information on the Foreword, see *ISO/IEC Directives, Part 2, 2016, Clause 12.*
65
+ ****
66
+ INPUT
67
+ #{BLANK_HDR}
68
+ <sections><p id="foreword">Foreword</p>
69
+ </sections>
70
+ </standard-document>
71
+ OUTPUT
72
+ end
73
+
74
+ it "processes review blocks if document is in draft mode" do
75
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
76
+ = Document title
77
+ Author
78
+ :docfile: test.adoc
79
+ :nodoc:
80
+ :novalid:
81
+ :draft: 1.2
82
+
83
+ [[foreword]]
84
+ .Foreword
85
+ Foreword
86
+
87
+ [reviewer=ISO,date=20170101,from=foreword,to=foreword]
88
+ ****
89
+ A Foreword shall appear in each document. The generic text is shown here. It does not contain requirements, recommendations or permissions.
90
+
91
+ For further information on the Foreword, see *ISO/IEC Directives, Part 2, 2016, Clause 12.*
92
+ ****
93
+ INPUT
94
+ #{BLANK_HDR}
95
+ <version>
96
+ <draft>1.2</draft>
97
+ </version>
98
+ <sections><p id="foreword">Foreword</p>
99
+ <review reviewer="ISO" id="_" date="20170101T00:00:00Z" from="foreword" to="foreword"><p id="_">A Foreword shall appear in each document. The generic text is shown here. It does not contain requirements, recommendations or permissions.</p>
100
+ <p id="_">For further information on the Foreword, see <strong>ISO/IEC Directives, Part 2, 2016, Clause 12.</strong></p></review></sections>
101
+ </standard-document>
102
+
103
+ OUTPUT
104
+ end
105
+
106
+ it "processes term notes" do
107
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
108
+ #{ASCIIDOC_BLANK_HDR}
109
+ == Terms and Definitions
110
+
111
+ === Term1
112
+
113
+ NOTE: This is a note
114
+ INPUT
115
+ #{BLANK_HDR}
116
+ <sections>
117
+ <terms id="_" obligation="normative">
118
+ <title>Terms and definitions</title>
119
+ <term id="_">
120
+ <preferred>Term1</preferred>
121
+ <termnote id="_">
122
+ <p id="_">This is a note</p>
123
+ </termnote>
124
+ </term>
125
+ </terms>
126
+ </sections>
127
+ </standard-document>
128
+ OUTPUT
129
+ end
130
+
131
+ it "processes notes" do
132
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
133
+ #{ASCIIDOC_BLANK_HDR}
134
+ NOTE: This is a note
135
+ INPUT
136
+ #{BLANK_HDR}
137
+ <sections>
138
+ <note id="_">
139
+ <p id="_">This is a note</p>
140
+ </note>
141
+ </sections>
142
+ </standard-document>
143
+
144
+ OUTPUT
145
+ end
146
+
147
+ it "does nothing in particular with literals" do
148
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
149
+ #{ASCIIDOC_BLANK_HDR}
150
+ ....
151
+ LITERAL
152
+ ....
153
+ INPUT
154
+ #{BLANK_HDR}
155
+ <sections>
156
+ <p id="_">LITERAL</p>
157
+ </sections>
158
+ </standard-document>
159
+
160
+ OUTPUT
161
+ end
162
+
163
+ it "processes simple admonitions with Asciidoc names" do
164
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
165
+ #{ASCIIDOC_BLANK_HDR}
166
+ CAUTION: Only use paddy or parboiled rice for the determination of husked rice yield.
167
+ INPUT
168
+ #{BLANK_HDR}
169
+ <sections>
170
+ <admonition id="_" type="caution">
171
+ <p id="_">Only use paddy or parboiled rice for the determination of husked rice yield.</p>
172
+ </admonition>
173
+ </sections>
174
+ </standard-document>
175
+
176
+ OUTPUT
177
+ end
178
+
179
+
180
+ it "processes complex admonitions with non-Asciidoc names" do
181
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
182
+ #{ASCIIDOC_BLANK_HDR}
183
+ [CAUTION,type=Safety Precautions]
184
+ .Safety Precautions
185
+ ====
186
+ While werewolves are hardy community members, keep in mind the following dietary concerns:
187
+
188
+ . They are allergic to cinnamon.
189
+ . More than two glasses of orange juice in 24 hours makes them howl in harmony with alarms and sirens.
190
+ . Celery makes them sad.
191
+ ====
192
+ INPUT
193
+ #{BLANK_HDR}
194
+ <sections>
195
+ <admonition id="_" type="safety precautions"><p id="_">While werewolves are hardy community members, keep in mind the following dietary concerns:</p>
196
+ <ol id="_" type="arabic">
197
+ <li>
198
+ <p id="_">They are allergic to cinnamon.</p>
199
+ </li>
200
+ <li>
201
+ <p id="_">More than two glasses of orange juice in 24 hours makes them howl in harmony with alarms and sirens.</p>
202
+ </li>
203
+ <li>
204
+ <p id="_">Celery makes them sad.</p>
205
+ </li>
206
+ </ol></admonition>
207
+ </sections>
208
+ </standard-document>
209
+
210
+ OUTPUT
211
+ end
212
+
213
+ it "processes term examples" do
214
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
215
+ #{ASCIIDOC_BLANK_HDR}
216
+ == Terms and Definitions
217
+
218
+ === Term1
219
+
220
+ [example]
221
+ This is an example
222
+ INPUT
223
+ #{BLANK_HDR}
224
+ <sections>
225
+ <terms id="_" obligation="normative">
226
+ <title>Terms and definitions</title>
227
+ <term id="_">
228
+ <preferred>Term1</preferred>
229
+ <termexample id="_">
230
+ <p id="_">This is an example</p>
231
+ </termexample>
232
+ </term>
233
+ </terms>
234
+ </sections>
235
+ </standard-document>
236
+
237
+ OUTPUT
238
+ end
239
+
240
+ it "processes examples" do
241
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
242
+ #{ASCIIDOC_BLANK_HDR}
243
+ [example]
244
+ ====
245
+ This is an example
246
+
247
+ Amen
248
+ ====
249
+ INPUT
250
+ #{BLANK_HDR}
251
+ <sections>
252
+ <example id="_"><p id="_">This is an example</p>
253
+ <p id="_">Amen</p></example>
254
+ </sections>
255
+ </standard-document>
256
+ OUTPUT
257
+ end
258
+
259
+ it "processes preambles" do
260
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
261
+ #{ASCIIDOC_BLANK_HDR}
262
+ This is a preamble
263
+
264
+ == Section 1
265
+ INPUT
266
+ #{BLANK_HDR}
267
+ <preface><foreword obligation="informative">
268
+ <title>Foreword</title>
269
+ <p id="_">This is a preamble</p>
270
+ </foreword></preface><sections>
271
+ <clause id="_" inline-header="false" obligation="normative">
272
+ <title>Section 1</title>
273
+ </clause></sections>
274
+ </standard-document>
275
+ OUTPUT
276
+ end
277
+
278
+ it "processes images" do
279
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
280
+ #{ASCIIDOC_BLANK_HDR}
281
+ .Split-it-right sample divider
282
+ image::spec/examples/rice_images/rice_image1.png[]
283
+
284
+ INPUT
285
+ #{BLANK_HDR}
286
+ <sections>
287
+ <figure id="_">
288
+ <name>Split-it-right sample divider</name>
289
+ <image src="spec/examples/rice_images/rice_image1.png" id="_" imagetype="PNG" height="auto" width="auto"/>
290
+ </figure>
291
+ </sections>
292
+ </standard-document>
293
+ OUTPUT
294
+ end
295
+
296
+ it "accepts width and height attributes on images" do
297
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
298
+ #{ASCIIDOC_BLANK_HDR}
299
+ [height=4,width=3]
300
+ image::spec/examples/rice_images/rice_image1.png[]
301
+
302
+ INPUT
303
+ #{BLANK_HDR}
304
+ <sections>
305
+ <figure id="_">
306
+ <image src="spec/examples/rice_images/rice_image1.png" id="_" imagetype="PNG" height="4" width="3"/>
307
+ </figure>
308
+ </sections>
309
+ </standard-document>
310
+ OUTPUT
311
+ end
312
+
313
+ it "accepts auto for width and height attributes on images" do
314
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
315
+ #{ASCIIDOC_BLANK_HDR}
316
+ [height=4,width=auto]
317
+ image::spec/examples/rice_images/rice_image1.png[]
318
+
319
+ INPUT
320
+ #{BLANK_HDR}
321
+ <sections>
322
+ <figure id="_">
323
+ <image src="spec/examples/rice_images/rice_image1.png" id="_" imagetype="PNG" height="4" width="auto"/>
324
+ </figure>
325
+ </sections>
326
+ </standard-document>
327
+ OUTPUT
328
+ end
329
+
330
+ it "accepts alignment attribute on paragraphs" do
331
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
332
+ #{ASCIIDOC_BLANK_HDR}
333
+ [align=right]
334
+ This para is right-aligned.
335
+ INPUT
336
+ #{BLANK_HDR}
337
+ <sections>
338
+ <p align="right" id="_">This para is right-aligned.</p>
339
+ </sections>
340
+ </standard-document>
341
+ OUTPUT
342
+ end
343
+
344
+ it "processes blockquotes" do
345
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
346
+ #{ASCIIDOC_BLANK_HDR}
347
+ [quote, ISO, "ISO7301,section 1"]
348
+ ____
349
+ Block quotation
350
+ ____
351
+ INPUT
352
+ #{BLANK_HDR}
353
+ <sections>
354
+ <quote id="_">
355
+ <source type="inline" bibitemid="ISO7301" citeas=""><locality type="section"><referenceFrom>1</referenceFrom></locality></source>
356
+ <author>ISO</author>
357
+ <p id="_">Block quotation</p>
358
+ </quote>
359
+ </sections>
360
+ </standard-document>
361
+ OUTPUT
362
+ end
363
+
364
+ it "processes source code" do
365
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
366
+ #{ASCIIDOC_BLANK_HDR}
367
+ [source,ruby]
368
+ --
369
+ puts "Hello, world."
370
+ %w{a b c}.each do |x|
371
+ puts x
372
+ end
373
+ --
374
+ INPUT
375
+ #{BLANK_HDR}
376
+ <sections>
377
+ <sourcecode id="_">puts "Hello, world."
378
+ %w{a b c}.each do |x|
379
+ puts x
380
+ end</sourcecode>
381
+ </sections>
382
+ </standard-document>
383
+ OUTPUT
384
+ end
385
+
386
+ it "processes callouts" do
387
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
388
+ #{ASCIIDOC_BLANK_HDR}
389
+ [source,ruby]
390
+ --
391
+ puts "Hello, world." <1>
392
+ %w{a b c}.each do |x|
393
+ puts x <2>
394
+ end
395
+ --
396
+ <1> This is one callout
397
+ <2> This is another callout
398
+ INPUT
399
+ #{BLANK_HDR}
400
+ <sections><sourcecode id="_">puts "Hello, world." <callout target="_">1</callout>
401
+ %w{a b c}.each do |x|
402
+ puts x <callout target="_">2</callout>
403
+ end<annotation id="_">
404
+ <p id="_">This is one callout</p>
405
+ </annotation><annotation id="_">
406
+ <p id="_">This is another callout</p>
407
+ </annotation></sourcecode>
408
+ </sections>
409
+ </standard-document>
410
+ OUTPUT
411
+ end
412
+
413
+ it "processes unmodified term sources" do
414
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
415
+ #{ASCIIDOC_BLANK_HDR}
416
+ == Terms and Definitions
417
+
418
+ === Term1
419
+
420
+ [.source]
421
+ <<ISO2191,section=1>>
422
+ INPUT
423
+ #{BLANK_HDR}
424
+ <sections>
425
+ <terms id="_" obligation="normative">
426
+ <title>Terms and definitions</title>
427
+ <term id="_">
428
+ <preferred>Term1</preferred>
429
+ <termsource status="identical">
430
+ <origin bibitemid="ISO2191" type="inline" citeas=""><locality type="section"><referenceFrom>1</referenceFrom></locality></origin>
431
+ </termsource>
432
+ </term>
433
+ </terms>
434
+ </sections>
435
+ </standard-document>
436
+ OUTPUT
437
+ end
438
+
439
+ it "processes modified term sources" do
440
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
441
+ #{ASCIIDOC_BLANK_HDR}
442
+ == Terms and Definitions
443
+
444
+ === Term1
445
+
446
+ [.source]
447
+ <<ISO2191,section=1>>, with adjustments
448
+ INPUT
449
+ #{BLANK_HDR}
450
+ <sections>
451
+ <terms id="_" obligation="normative">
452
+ <title>Terms and definitions</title>
453
+ <term id="_">
454
+ <preferred>Term1</preferred>
455
+ <termsource status="modified">
456
+ <origin bibitemid="ISO2191" type="inline" citeas=""><locality type="section"><referenceFrom>1</referenceFrom></locality></origin>
457
+ <modification>
458
+ <p id="_">with adjustments</p>
459
+ </modification>
460
+ </termsource>
461
+ </term>
462
+ </terms>
463
+ </sections>
464
+ </standard-document>
465
+ OUTPUT
466
+ end
467
+
468
+
469
+ end