metanorma-rsd 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,197 @@
1
+ require "asciidoctor"
2
+ require "asciidoctor/rsd"
3
+ require "asciidoctor/standoc/converter"
4
+ require "isodoc/rsd/html_convert"
5
+ require "isodoc/rsd/word_convert"
6
+
7
+ module Asciidoctor
8
+ module Rsd
9
+
10
+ # A {Converter} implementation that generates RSD output, and a document
11
+ # schema encapsulation of the document for validation
12
+ #
13
+ class Converter < Standoc::Converter
14
+
15
+ register_for "rsd"
16
+
17
+ def initialize(backend, opts)
18
+ super
19
+ @libdir = File.dirname(__FILE__)
20
+ end
21
+
22
+ def metadata_author(node, xml)
23
+ xml.contributor do |c|
24
+ c.role **{ type: "author" }
25
+ c.organization do |a|
26
+ a.name "Ribose"
27
+ end
28
+ end
29
+ end
30
+
31
+ def metadata_publisher(node, xml)
32
+ xml.contributor do |c|
33
+ c.role **{ type: "publisher" }
34
+ c.organization do |a|
35
+ a.name "Ribose"
36
+ end
37
+ end
38
+ end
39
+
40
+ def metadata_committee(node, xml)
41
+ xml.editorialgroup do |a|
42
+ a.committee node.attr("committee"),
43
+ **attr_code(type: node.attr("committee-type"))
44
+ end
45
+ end
46
+
47
+ def title(node, xml)
48
+ ["en"].each do |lang|
49
+ xml.title **{ language: lang, format: "plain" } do |t|
50
+ t << asciidoc_sub(node.attr("title"))
51
+ end
52
+ end
53
+ end
54
+
55
+ def metadata_status(node, xml)
56
+ xml.status(**{ format: "plain" }) { |s| s << node.attr("status") }
57
+ end
58
+
59
+ def metadata_id(node, xml)
60
+ xml.docidentifier { |i| i << node.attr("docnumber") }
61
+ end
62
+
63
+ def metadata_copyright(node, xml)
64
+ from = node.attr("copyright-year") || Date.today.year
65
+ xml.copyright do |c|
66
+ c.from from
67
+ c.owner do |owner|
68
+ owner.organization do |o|
69
+ o.name "Ribose"
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+ def metadata_security(node, xml)
76
+ security = node.attr("security") || return
77
+ xml.security security
78
+ end
79
+
80
+ def metadata(node, xml)
81
+ super
82
+ metadata_security(node, xml)
83
+ end
84
+
85
+ def title_validate(root)
86
+ nil
87
+ end
88
+
89
+ def makexml(node)
90
+ result = ["<?xml version='1.0' encoding='UTF-8'?>\n<rsd-standard>"]
91
+ @draft = node.attributes.has_key?("draft")
92
+ result << noko { |ixml| front node, ixml }
93
+ result << noko { |ixml| middle node, ixml }
94
+ result << "</rsd-standard>"
95
+ result = textcleanup(result.flatten * "\n")
96
+ ret1 = cleanup(Nokogiri::XML(result))
97
+ validate(ret1)
98
+ ret1.root.add_namespace(nil, RSD_NAMESPACE)
99
+ ret1
100
+ end
101
+
102
+ def doctype(node)
103
+ d = node.attr("doctype")
104
+ unless %w{policy-and-procedures best-practices supporting-document
105
+ report legal directives proposal standard}.include? d
106
+ warn "#{d} is not a legal document type: reverting to 'standard'"
107
+ d = "standard"
108
+ end
109
+ d
110
+ end
111
+
112
+ def pdf_convert(filename)
113
+ url = "#{Dir.pwd}/#{filename}.html"
114
+ pdfjs = File.join(File.dirname(__FILE__), 'pdf.js')
115
+ system "export NODE_PATH=$(npm root --quiet -g);
116
+ node #{pdfjs} file://#{url} #{filename}.pdf"
117
+ end
118
+
119
+ def document(node)
120
+ init(node)
121
+ ret1 = makexml(node)
122
+ ret = ret1.to_xml(indent: 2)
123
+ unless node.attr("nodoc") || !node.attr("docfile")
124
+ filename = node.attr("docfile").gsub(/\.adoc/, ".xml").
125
+ gsub(%r{^.*/}, "")
126
+ File.open(filename, "w") { |f| f.write(ret) }
127
+ html_converter(node).convert filename unless node.attr("nodoc")
128
+ word_converter(node).convert filename unless node.attr("nodoc")
129
+ pdf_convert(filename.sub(/\.xml$/, "")) unless node.attr("nodoc")
130
+ end
131
+ @files_to_delete.each { |f| system "rm #{f}" }
132
+ ret
133
+ end
134
+
135
+ def validate(doc)
136
+ content_validate(doc)
137
+ schema_validate(formattedstr_strip(doc.dup),
138
+ File.join(File.dirname(__FILE__), "rsd.rng"))
139
+ end
140
+
141
+ def rsd_html_path(file)
142
+ File.join(File.dirname(__FILE__), File.join("html", file))
143
+ end
144
+
145
+ def literal(node)
146
+ noko do |xml|
147
+ xml.figure **id_attr(node) do |f|
148
+ figure_title(node, f)
149
+ f.pre node.lines.join("\n")
150
+ end
151
+ end
152
+ end
153
+
154
+ def sections_cleanup(x)
155
+ super
156
+ x.xpath("//*[@inline-header]").each do |h|
157
+ h.delete("inline-header")
158
+ end
159
+ end
160
+
161
+ def style(n, t)
162
+ return
163
+ end
164
+
165
+ def html_converter(node)
166
+ IsoDoc::Rsd::HtmlConvert.new(html_extract_attributes(node))
167
+ end
168
+
169
+ def word_converter(node)
170
+ IsoDoc::Rsd::WordConvert.new(doc_extract_attributes(node))
171
+ end
172
+
173
+ def inline_quoted(node)
174
+ noko do |xml|
175
+ case node.type
176
+ when :emphasis then xml.em node.text
177
+ when :strong then xml.strong node.text
178
+ when :monospaced then xml.tt node.text
179
+ when :double then xml << "\"#{node.text}\""
180
+ when :single then xml << "'#{node.text}'"
181
+ when :superscript then xml.sup node.text
182
+ when :subscript then xml.sub node.text
183
+ when :asciimath then stem_parse(node.text, xml)
184
+ else
185
+ case node.role
186
+ when "strike" then xml.strike node.text
187
+ when "smallcap" then xml.smallcap node.text
188
+ when "keyword" then xml.keyword node.text
189
+ else
190
+ xml << node.text
191
+ end
192
+ end
193
+ end.join
194
+ end
195
+ end
196
+ end
197
+ end
@@ -0,0 +1,1059 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ instantiations of this grammar may replace leaf strings
4
+ with more elaborated types; e.g. title (text) replaced with
5
+ title-main, title-intro, title-part; type replaced with
6
+ enum.
7
+
8
+ some renaming at leaf nodes is permissible
9
+
10
+ obligations can change both from optional to mandatory,
11
+ and from mandatory to optional; optional elements may
12
+ be omitted; freely positioned alternatives may be replaced
13
+ with strict ordering
14
+
15
+ DO NOT introduce a namespace here. We do not want a distinct namespace
16
+ for these elements, and a distinct namespace for any grammar inheriting
17
+ these elements; we just want one namespace for any child grammars
18
+ of this.
19
+ -->
20
+ <grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
21
+ <include href="biblio.rng">
22
+ <define name="status">
23
+ <element name="status">
24
+ <choice>
25
+ <value>proposal</value>
26
+ <value>working_draft</value>
27
+ <value>committee_draft</value>
28
+ <value>draft_standard</value>
29
+ <value>final_draft</value>
30
+ <value>published</value>
31
+ <value>withdrawn</value>
32
+ </choice>
33
+ </element>
34
+ </define>
35
+ </include>
36
+ <start>
37
+ <ref name="standard-document"/>
38
+ </start>
39
+ <define name="standard-document">
40
+ <element name="standard-document">
41
+ <ref name="bibdata"/>
42
+ <optional>
43
+ <ref name="version"/>
44
+ </optional>
45
+ <optional>
46
+ <ref name="preface"/>
47
+ </optional>
48
+ <ref name="sections"/>
49
+ <zeroOrMore>
50
+ <ref name="annex"/>
51
+ </zeroOrMore>
52
+ <zeroOrMore>
53
+ <ref name="references"/>
54
+ </zeroOrMore>
55
+ </element>
56
+ </define>
57
+ <define name="bibdata">
58
+ <element name="bibdata">
59
+ <ref name="BibData"/>
60
+ </element>
61
+ </define>
62
+ <define name="version">
63
+ <element name="version">
64
+ <optional>
65
+ <ref name="vedition"/>
66
+ </optional>
67
+ <optional>
68
+ <ref name="revision-date"/>
69
+ </optional>
70
+ <zeroOrMore>
71
+ <ref name="draft"/>
72
+ </zeroOrMore>
73
+ </element>
74
+ </define>
75
+ <define name="vedition">
76
+ <element name="edition">
77
+ <data type="int"/>
78
+ </element>
79
+ </define>
80
+ <define name="revision-date">
81
+ <element name="revision-date">
82
+ <data type="date"/>
83
+ </element>
84
+ </define>
85
+ <define name="draft">
86
+ <element name="draft">
87
+ <text/>
88
+ </element>
89
+ </define>
90
+ <define name="preface">
91
+ <element name="preface">
92
+ <oneOrMore>
93
+ <ref name="content"/>
94
+ </oneOrMore>
95
+ </element>
96
+ </define>
97
+ <define name="sections">
98
+ <element name="sections">
99
+ <oneOrMore>
100
+ <choice>
101
+ <ref name="content"/>
102
+ <ref name="clause"/>
103
+ <ref name="terms"/>
104
+ <ref name="definitions"/>
105
+ </choice>
106
+ </oneOrMore>
107
+ </element>
108
+ </define>
109
+ <define name="definitions">
110
+ <element name="definitions">
111
+ <optional>
112
+ <attribute name="id">
113
+ <data type="ID"/>
114
+ </attribute>
115
+ </optional>
116
+ <optional>
117
+ <ref name="section-title"/>
118
+ </optional>
119
+ <ref name="dl"/>
120
+ </element>
121
+ </define>
122
+ <define name="section-title">
123
+ <element name="title">
124
+ <zeroOrMore>
125
+ <ref name="TextElement"/>
126
+ </zeroOrMore>
127
+ </element>
128
+ </define>
129
+ <define name="content">
130
+ <element name="content">
131
+ <ref name="Content-Section"/>
132
+ </element>
133
+ </define>
134
+ <define name="content-subsection">
135
+ <element name="clause">
136
+ <ref name="Content-Section"/>
137
+ </element>
138
+ </define>
139
+ <define name="Basic-Section">
140
+ <optional>
141
+ <attribute name="id">
142
+ <data type="ID"/>
143
+ </attribute>
144
+ </optional>
145
+ <optional>
146
+ <ref name="section-title"/>
147
+ </optional>
148
+ <oneOrMore>
149
+ <ref name="BasicBlock"/>
150
+ </oneOrMore>
151
+ <zeroOrMore>
152
+ <ref name="note"/>
153
+ </zeroOrMore>
154
+ </define>
155
+ <define name="Content-Section">
156
+ <optional>
157
+ <attribute name="id">
158
+ <data type="ID"/>
159
+ </attribute>
160
+ </optional>
161
+ <optional>
162
+ <ref name="section-title"/>
163
+ </optional>
164
+ <choice>
165
+ <group>
166
+ <oneOrMore>
167
+ <ref name="BasicBlock"/>
168
+ </oneOrMore>
169
+ <zeroOrMore>
170
+ <ref name="note"/>
171
+ </zeroOrMore>
172
+ </group>
173
+ <oneOrMore>
174
+ <ref name="content-subsection"/>
175
+ </oneOrMore>
176
+ </choice>
177
+ </define>
178
+ <define name="clause">
179
+ <element name="clause">
180
+ <ref name="Clause-Section"/>
181
+ </element>
182
+ </define>
183
+ <define name="Clause-Section">
184
+ <optional>
185
+ <attribute name="id">
186
+ <data type="ID"/>
187
+ </attribute>
188
+ </optional>
189
+ <optional>
190
+ <ref name="section-title"/>
191
+ </optional>
192
+ <choice>
193
+ <group>
194
+ <oneOrMore>
195
+ <ref name="BasicBlock"/>
196
+ </oneOrMore>
197
+ <zeroOrMore>
198
+ <ref name="note"/>
199
+ </zeroOrMore>
200
+ </group>
201
+ <oneOrMore>
202
+ <ref name="clause-subsection"/>
203
+ </oneOrMore>
204
+ </choice>
205
+ </define>
206
+ <define name="clause-subsection">
207
+ <element name="clause">
208
+ <ref name="Clause-Section"/>
209
+ </element>
210
+ </define>
211
+ <define name="annex">
212
+ <element name="annex">
213
+ <optional>
214
+ <attribute name="id">
215
+ <data type="ID"/>
216
+ </attribute>
217
+ </optional>
218
+ <attribute name="obligation">
219
+ <choice>
220
+ <value>normative</value>
221
+ <value>informative</value>
222
+ </choice>
223
+ </attribute>
224
+ <optional>
225
+ <ref name="section-title"/>
226
+ </optional>
227
+ <choice>
228
+ <group>
229
+ <oneOrMore>
230
+ <ref name="BasicBlock"/>
231
+ </oneOrMore>
232
+ <zeroOrMore>
233
+ <ref name="note"/>
234
+ </zeroOrMore>
235
+ </group>
236
+ <oneOrMore>
237
+ <ref name="clause-subsection"/>
238
+ </oneOrMore>
239
+ </choice>
240
+ </element>
241
+ </define>
242
+ <define name="references">
243
+ <element name="references">
244
+ <optional>
245
+ <attribute name="id">
246
+ <data type="ID"/>
247
+ </attribute>
248
+ </optional>
249
+ <optional>
250
+ <ref name="section-title"/>
251
+ </optional>
252
+ <zeroOrMore>
253
+ <ref name="bibitem"/>
254
+ </zeroOrMore>
255
+ </element>
256
+ </define>
257
+ <define name="terms">
258
+ <element name="terms">
259
+ <optional>
260
+ <attribute name="id">
261
+ <data type="ID"/>
262
+ </attribute>
263
+ </optional>
264
+ <oneOrMore>
265
+ <ref name="term"/>
266
+ </oneOrMore>
267
+ </element>
268
+ </define>
269
+ <define name="term">
270
+ <element name="term">
271
+ <optional>
272
+ <attribute name="id">
273
+ <data type="ID"/>
274
+ </attribute>
275
+ </optional>
276
+ <oneOrMore>
277
+ <ref name="preferred"/>
278
+ </oneOrMore>
279
+ <zeroOrMore>
280
+ <ref name="admitted"/>
281
+ </zeroOrMore>
282
+ <zeroOrMore>
283
+ <ref name="deprecates"/>
284
+ </zeroOrMore>
285
+ <optional>
286
+ <ref name="termdomain"/>
287
+ </optional>
288
+ <ref name="definition"/>
289
+ <zeroOrMore>
290
+ <ref name="termnote"/>
291
+ </zeroOrMore>
292
+ <zeroOrMore>
293
+ <ref name="termexample"/>
294
+ </zeroOrMore>
295
+ <zeroOrMore>
296
+ <ref name="termsource"/>
297
+ </zeroOrMore>
298
+ </element>
299
+ </define>
300
+ <define name="preferred">
301
+ <element name="preferred">
302
+ <oneOrMore>
303
+ <ref name="TextElement"/>
304
+ </oneOrMore>
305
+ </element>
306
+ </define>
307
+ <define name="admitted">
308
+ <element name="admitted">
309
+ <oneOrMore>
310
+ <ref name="TextElement"/>
311
+ </oneOrMore>
312
+ </element>
313
+ </define>
314
+ <define name="deprecates">
315
+ <element name="deprecates">
316
+ <oneOrMore>
317
+ <ref name="TextElement"/>
318
+ </oneOrMore>
319
+ </element>
320
+ </define>
321
+ <define name="termdomain">
322
+ <element name="domain">
323
+ <oneOrMore>
324
+ <ref name="TextElement"/>
325
+ </oneOrMore>
326
+ </element>
327
+ </define>
328
+ <define name="definition">
329
+ <element name="definition">
330
+ <ref name="paragraph"/>
331
+ </element>
332
+ </define>
333
+ <define name="termnote">
334
+ <element name="termnote">
335
+ <attribute name="id">
336
+ <data type="ID"/>
337
+ </attribute>
338
+ <ref name="paragraph"/>
339
+ </element>
340
+ </define>
341
+ <define name="termexample">
342
+ <element name="termexample">
343
+ <attribute name="id">
344
+ <data type="ID"/>
345
+ </attribute>
346
+ <ref name="paragraph"/>
347
+ </element>
348
+ </define>
349
+ <define name="termsource">
350
+ <element name="termsource">
351
+ <attribute name="status">
352
+ <choice>
353
+ <value>identical</value>
354
+ <value>modified</value>
355
+ </choice>
356
+ </attribute>
357
+ <ref name="origin"/>
358
+ <optional>
359
+ <ref name="modification"/>
360
+ </optional>
361
+ </element>
362
+ </define>
363
+ <define name="origin">
364
+ <element name="origin">
365
+ <ref name="erefType"/>
366
+ </element>
367
+ </define>
368
+ <define name="modification">
369
+ <element name="modification">
370
+ <ref name="paragraph"/>
371
+ </element>
372
+ </define>
373
+ <define name="BasicBlock">
374
+ <choice>
375
+ <ref name="paragraph-with-footnote"/>
376
+ <ref name="table"/>
377
+ <ref name="formula"/>
378
+ <ref name="admonition"/>
379
+ <ref name="ol"/>
380
+ <ref name="ul"/>
381
+ <ref name="dl"/>
382
+ <ref name="figure"/>
383
+ <ref name="quote"/>
384
+ <ref name="sourcecode"/>
385
+ <ref name="example"/>
386
+ <ref name="review"/>
387
+ </choice>
388
+ </define>
389
+ <define name="paragraph">
390
+ <element name="p">
391
+ <ref name="ParagraphType"/>
392
+ </element>
393
+ </define>
394
+ <define name="Alignments">
395
+ <choice>
396
+ <value>left</value>
397
+ <value>right</value>
398
+ <value>center</value>
399
+ <value>justified</value>
400
+ </choice>
401
+ </define>
402
+ <define name="ParagraphType">
403
+ <attribute name="id">
404
+ <data type="ID"/>
405
+ </attribute>
406
+ <optional>
407
+ <attribute name="align">
408
+ <ref name="Alignments"/>
409
+ </attribute>
410
+ </optional>
411
+ <zeroOrMore>
412
+ <ref name="TextElement"/>
413
+ </zeroOrMore>
414
+ <zeroOrMore>
415
+ <ref name="note"/>
416
+ </zeroOrMore>
417
+ </define>
418
+ <define name="paragraph-with-footnote">
419
+ <element name="p">
420
+ <attribute name="id">
421
+ <data type="ID"/>
422
+ </attribute>
423
+ <optional>
424
+ <attribute name="align">
425
+ <ref name="Alignments"/>
426
+ </attribute>
427
+ </optional>
428
+ <zeroOrMore>
429
+ <choice>
430
+ <ref name="TextElement"/>
431
+ <ref name="fn"/>
432
+ </choice>
433
+ </zeroOrMore>
434
+ <zeroOrMore>
435
+ <ref name="note"/>
436
+ </zeroOrMore>
437
+ </element>
438
+ </define>
439
+ <define name="note">
440
+ <element name="note">
441
+ <attribute name="id">
442
+ <data type="ID"/>
443
+ </attribute>
444
+ <oneOrMore>
445
+ <ref name="paragraph"/>
446
+ </oneOrMore>
447
+ </element>
448
+ </define>
449
+ <define name="review">
450
+ <element name="review">
451
+ <attribute name="id">
452
+ <data type="ID"/>
453
+ </attribute>
454
+ <attribute name="reviewer"/>
455
+ <optional>
456
+ <attribute name="date">
457
+ <data type="dateTime"/>
458
+ </attribute>
459
+ </optional>
460
+ <attribute name="from">
461
+ <data type="IDREF"/>
462
+ </attribute>
463
+ <optional>
464
+ <attribute name="to">
465
+ <data type="IDREF"/>
466
+ </attribute>
467
+ </optional>
468
+ <oneOrMore>
469
+ <ref name="paragraph"/>
470
+ </oneOrMore>
471
+ </element>
472
+ </define>
473
+ <define name="formula">
474
+ <element name="formula">
475
+ <attribute name="id">
476
+ <data type="ID"/>
477
+ </attribute>
478
+ <ref name="stem"/>
479
+ <optional>
480
+ <ref name="dl"/>
481
+ </optional>
482
+ <zeroOrMore>
483
+ <ref name="note"/>
484
+ </zeroOrMore>
485
+ </element>
486
+ </define>
487
+ <define name="quote">
488
+ <element name="quote">
489
+ <attribute name="id">
490
+ <data type="ID"/>
491
+ </attribute>
492
+ <optional>
493
+ <attribute name="alignment">
494
+ <ref name="Alignments"/>
495
+ </attribute>
496
+ </optional>
497
+ <optional>
498
+ <ref name="quote-source"/>
499
+ </optional>
500
+ <optional>
501
+ <ref name="quote-author"/>
502
+ </optional>
503
+ <oneOrMore>
504
+ <ref name="paragraph-with-footnote"/>
505
+ </oneOrMore>
506
+ <zeroOrMore>
507
+ <ref name="note"/>
508
+ </zeroOrMore>
509
+ </element>
510
+ </define>
511
+ <define name="quote-source">
512
+ <element name="source">
513
+ <ref name="erefType"/>
514
+ </element>
515
+ </define>
516
+ <define name="quote-author">
517
+ <element name="author">
518
+ <text/>
519
+ </element>
520
+ </define>
521
+ <define name="sourcecode">
522
+ <element name="sourcecode">
523
+ <attribute name="id">
524
+ <data type="ID"/>
525
+ </attribute>
526
+ <optional>
527
+ <ref name="tname"/>
528
+ </optional>
529
+ <oneOrMore>
530
+ <choice>
531
+ <text/>
532
+ <ref name="callout"/>
533
+ </choice>
534
+ </oneOrMore>
535
+ <zeroOrMore>
536
+ <ref name="annotation"/>
537
+ </zeroOrMore>
538
+ <zeroOrMore>
539
+ <ref name="note"/>
540
+ </zeroOrMore>
541
+ </element>
542
+ </define>
543
+ <define name="table">
544
+ <element name="table">
545
+ <attribute name="id">
546
+ <data type="ID"/>
547
+ </attribute>
548
+ <optional>
549
+ <ref name="tname"/>
550
+ </optional>
551
+ <optional>
552
+ <ref name="thead"/>
553
+ </optional>
554
+ <ref name="tbody"/>
555
+ <optional>
556
+ <ref name="tfoot"/>
557
+ </optional>
558
+ <zeroOrMore>
559
+ <ref name="table-note"/>
560
+ </zeroOrMore>
561
+ <optional>
562
+ <ref name="dl"/>
563
+ </optional>
564
+ </element>
565
+ </define>
566
+ <define name="tname">
567
+ <element name="name">
568
+ <text/>
569
+ </element>
570
+ </define>
571
+ <define name="thead">
572
+ <element name="thead">
573
+ <ref name="tr"/>
574
+ </element>
575
+ </define>
576
+ <define name="tfoot">
577
+ <element name="tfoot">
578
+ <ref name="tr"/>
579
+ </element>
580
+ </define>
581
+ <define name="tbody">
582
+ <element name="tbody">
583
+ <oneOrMore>
584
+ <ref name="tr"/>
585
+ </oneOrMore>
586
+ </element>
587
+ </define>
588
+ <define name="table-note">
589
+ <element name="note">
590
+ <ref name="paragraph"/>
591
+ </element>
592
+ </define>
593
+ <define name="tr">
594
+ <element name="tr">
595
+ <oneOrMore>
596
+ <choice>
597
+ <ref name="td"/>
598
+ <ref name="th"/>
599
+ </choice>
600
+ </oneOrMore>
601
+ </element>
602
+ </define>
603
+ <define name="td">
604
+ <element name="td">
605
+ <optional>
606
+ <attribute name="colspan"/>
607
+ </optional>
608
+ <optional>
609
+ <attribute name="rowspan"/>
610
+ </optional>
611
+ <optional>
612
+ <attribute name="align">
613
+ <choice>
614
+ <value>left</value>
615
+ <value>right</value>
616
+ <value>center</value>
617
+ </choice>
618
+ </attribute>
619
+ </optional>
620
+ <choice>
621
+ <zeroOrMore>
622
+ <ref name="TextElement"/>
623
+ </zeroOrMore>
624
+ <oneOrMore>
625
+ <ref name="paragraph-with-footnote"/>
626
+ </oneOrMore>
627
+ </choice>
628
+ </element>
629
+ </define>
630
+ <define name="th">
631
+ <element name="th">
632
+ <optional>
633
+ <attribute name="colspan"/>
634
+ </optional>
635
+ <optional>
636
+ <attribute name="rowspan"/>
637
+ </optional>
638
+ <optional>
639
+ <attribute name="align">
640
+ <choice>
641
+ <value>left</value>
642
+ <value>right</value>
643
+ <value>center</value>
644
+ </choice>
645
+ </attribute>
646
+ </optional>
647
+ <choice>
648
+ <zeroOrMore>
649
+ <ref name="TextElement"/>
650
+ </zeroOrMore>
651
+ <oneOrMore>
652
+ <ref name="paragraph-with-footnote"/>
653
+ </oneOrMore>
654
+ </choice>
655
+ </element>
656
+ </define>
657
+ <define name="example">
658
+ <element name="example">
659
+ <attribute name="id">
660
+ <data type="ID"/>
661
+ </attribute>
662
+ <oneOrMore>
663
+ <choice>
664
+ <ref name="formula"/>
665
+ <ref name="ul"/>
666
+ <ref name="ol"/>
667
+ <ref name="dl"/>
668
+ <ref name="quote"/>
669
+ <ref name="sourcecode"/>
670
+ <ref name="paragraph-with-footnote"/>
671
+ </choice>
672
+ </oneOrMore>
673
+ <zeroOrMore>
674
+ <ref name="note"/>
675
+ </zeroOrMore>
676
+ </element>
677
+ </define>
678
+ <define name="admonition">
679
+ <element name="admonition">
680
+ <attribute name="type">
681
+ <choice>
682
+ <value>warning</value>
683
+ <value>note</value>
684
+ <value>tip</value>
685
+ <value>important</value>
686
+ <value>caution</value>
687
+ </choice>
688
+ </attribute>
689
+ <attribute name="id">
690
+ <data type="ID"/>
691
+ </attribute>
692
+ <zeroOrMore>
693
+ <ref name="paragraph-with-footnote"/>
694
+ </zeroOrMore>
695
+ <zeroOrMore>
696
+ <ref name="note"/>
697
+ </zeroOrMore>
698
+ </element>
699
+ </define>
700
+ <define name="figure">
701
+ <element name="figure">
702
+ <attribute name="id">
703
+ <data type="ID"/>
704
+ </attribute>
705
+ <optional>
706
+ <ref name="source"/>
707
+ </optional>
708
+ <optional>
709
+ <ref name="tname"/>
710
+ </optional>
711
+ <choice>
712
+ <ref name="image"/>
713
+ <zeroOrMore>
714
+ <ref name="figure"/>
715
+ </zeroOrMore>
716
+ </choice>
717
+ <zeroOrMore>
718
+ <ref name="fn"/>
719
+ </zeroOrMore>
720
+ <optional>
721
+ <ref name="dl"/>
722
+ </optional>
723
+ <zeroOrMore>
724
+ <ref name="note"/>
725
+ </zeroOrMore>
726
+ </element>
727
+ </define>
728
+ <define name="TextElement">
729
+ <choice>
730
+ <text/>
731
+ <ref name="em"/>
732
+ <ref name="eref"/>
733
+ <ref name="strong"/>
734
+ <ref name="stem"/>
735
+ <ref name="sub"/>
736
+ <ref name="sup"/>
737
+ <ref name="tt"/>
738
+ <ref name="strike"/>
739
+ <ref name="smallcap"/>
740
+ <ref name="xref"/>
741
+ <ref name="br"/>
742
+ <ref name="hyperlink"/>
743
+ <ref name="hr"/>
744
+ <ref name="pagebreak"/>
745
+ <ref name="bookmark"/>
746
+ </choice>
747
+ </define>
748
+ <define name="source">
749
+ <element name="source">
750
+ <ref name="TypedUri"/>
751
+ </element>
752
+ </define>
753
+ <define name="em">
754
+ <element name="em">
755
+ <text/>
756
+ </element>
757
+ </define>
758
+ <define name="strong">
759
+ <element name="strong">
760
+ <text/>
761
+ </element>
762
+ </define>
763
+ <define name="tt">
764
+ <element name="tt">
765
+ <text/>
766
+ </element>
767
+ </define>
768
+ <define name="sub">
769
+ <element name="sub">
770
+ <text/>
771
+ </element>
772
+ </define>
773
+ <define name="sup">
774
+ <element name="sup">
775
+ <text/>
776
+ </element>
777
+ </define>
778
+ <define name="strike">
779
+ <element name="strike">
780
+ <text/>
781
+ </element>
782
+ </define>
783
+ <define name="smallcap">
784
+ <element name="smallcap">
785
+ <text/>
786
+ </element>
787
+ </define>
788
+ <define name="br">
789
+ <element name="br">
790
+ <empty/>
791
+ </element>
792
+ </define>
793
+ <define name="hr">
794
+ <element name="hr">
795
+ <empty/>
796
+ </element>
797
+ </define>
798
+ <define name="pagebreak">
799
+ <element name="pagebreak">
800
+ <empty/>
801
+ </element>
802
+ </define>
803
+ <!-- bare ID element, used for referencing arbitrary spans of text -->
804
+ <define name="bookmark">
805
+ <element name="bookmark">
806
+ <attribute name="id">
807
+ <data type="ID"/>
808
+ </attribute>
809
+ <empty/>
810
+ </element>
811
+ </define>
812
+ <define name="ReferenceFormat">
813
+ <choice>
814
+ <value>external</value>
815
+ <value>inline</value>
816
+ <value>footnote</value>
817
+ <value>callout</value>
818
+ </choice>
819
+ </define>
820
+ <define name="eref">
821
+ <element name="eref">
822
+ <ref name="erefType"/>
823
+ </element>
824
+ </define>
825
+ <define name="erefType">
826
+ <optional>
827
+ <attribute name="normative">
828
+ <data type="boolean"/>
829
+ </attribute>
830
+ </optional>
831
+ <attribute name="citeas"/>
832
+ <attribute name="type">
833
+ <ref name="ReferenceFormat"/>
834
+ </attribute>
835
+ <ref name="CitationType"/>
836
+ <text/>
837
+ </define>
838
+ <define name="hyperlink">
839
+ <element name="link">
840
+ <attribute name="target">
841
+ <data type="anyURI"/>
842
+ </attribute>
843
+ <attribute name="type">
844
+ <ref name="ReferenceFormat"/>
845
+ </attribute>
846
+ <text/>
847
+ </element>
848
+ </define>
849
+ <define name="xref">
850
+ <element name="xref">
851
+ <attribute name="target">
852
+ <data type="IDREF"/>
853
+ </attribute>
854
+ <attribute name="type">
855
+ <ref name="ReferenceFormat"/>
856
+ </attribute>
857
+ <text/>
858
+ </element>
859
+ </define>
860
+ <define name="fn">
861
+ <element name="fn">
862
+ <attribute name="reference"/>
863
+ <oneOrMore>
864
+ <ref name="paragraph"/>
865
+ </oneOrMore>
866
+ </element>
867
+ </define>
868
+ <!--
869
+ This is xref with fixed @type="footnote", and @target built in as paragraph+
870
+ @reference replaces ReferenceElement/text
871
+ so <fn reference="2"><p>This is a footnote</p></fn>
872
+ corresponds to
873
+ <eref type="footnote" target="fn2">2</xref> <p id="fn2">This is a footnote</p>
874
+ -->
875
+ <define name="callout">
876
+ <element name="callout">
877
+ <attribute name="target">
878
+ <data type="IDREF"/>
879
+ </attribute>
880
+ <text/>
881
+ </element>
882
+ </define>
883
+ <!--
884
+ This is xref with fixed @type="callout"; the target by convention is in an annotation in the same source code snippet
885
+ so <callout target="xyz">1</callout>
886
+ corresponds to <xref type="callout" target="xyz">1</xref>
887
+ -->
888
+ <define name="image">
889
+ <element name="image">
890
+ <attribute name="id">
891
+ <data type="ID"/>
892
+ </attribute>
893
+ <optional>
894
+ <attribute name="src">
895
+ <data type="anyURI"/>
896
+ </attribute>
897
+ </optional>
898
+ <attribute name="imagetype">
899
+ <choice>
900
+ <value>SVG</value>
901
+ <value>JPEG</value>
902
+ <value>GIF</value>
903
+ <value>PNG</value>
904
+ <value>PDF</value>
905
+ </choice>
906
+ </attribute>
907
+ <optional>
908
+ <attribute name="width">
909
+ <choice>
910
+ <data type="int"/>
911
+ <value>auto</value>
912
+ </choice>
913
+ </attribute>
914
+ </optional>
915
+ <optional>
916
+ <attribute name="height">
917
+ <choice>
918
+ <data type="int"/>
919
+ <value>auto</value>
920
+ </choice>
921
+ </attribute>
922
+ </optional>
923
+ </element>
924
+ </define>
925
+ <define name="stem">
926
+ <element name="stem">
927
+ <attribute name="type">
928
+ <choice>
929
+ <value>MathML</value>
930
+ <value>AsciiMath</value>
931
+ </choice>
932
+ </attribute>
933
+ <text/>
934
+ </element>
935
+ </define>
936
+ <define name="annotation">
937
+ <element name="annotation">
938
+ <attribute name="id">
939
+ <data type="ID"/>
940
+ </attribute>
941
+ <ref name="paragraph"/>
942
+ </element>
943
+ </define>
944
+ <define name="ul">
945
+ <element name="ul">
946
+ <attribute name="id">
947
+ <data type="ID"/>
948
+ </attribute>
949
+ <oneOrMore>
950
+ <ref name="li"/>
951
+ </oneOrMore>
952
+ <zeroOrMore>
953
+ <ref name="note"/>
954
+ </zeroOrMore>
955
+ </element>
956
+ </define>
957
+ <define name="li">
958
+ <element name="li">
959
+ <oneOrMore>
960
+ <ref name="paragraph-with-footnote"/>
961
+ </oneOrMore>
962
+ </element>
963
+ </define>
964
+ <define name="ol">
965
+ <element name="ol">
966
+ <attribute name="id">
967
+ <data type="ID"/>
968
+ </attribute>
969
+ <attribute name="type">
970
+ <choice>
971
+ <value>roman</value>
972
+ <value>alphabet</value>
973
+ <value>arabic</value>
974
+ <value>roman_upper</value>
975
+ <value>alphabet_upper</value>
976
+ </choice>
977
+ </attribute>
978
+ <oneOrMore>
979
+ <ref name="li"/>
980
+ </oneOrMore>
981
+ <zeroOrMore>
982
+ <ref name="note"/>
983
+ </zeroOrMore>
984
+ </element>
985
+ </define>
986
+ <define name="dl">
987
+ <element name="dl">
988
+ <attribute name="id">
989
+ <data type="ID"/>
990
+ </attribute>
991
+ <oneOrMore>
992
+ <ref name="dt"/>
993
+ <ref name="dd"/>
994
+ </oneOrMore>
995
+ <zeroOrMore>
996
+ <ref name="note"/>
997
+ </zeroOrMore>
998
+ </element>
999
+ </define>
1000
+ <define name="dt">
1001
+ <element name="dt">
1002
+ <ref name="TextElement"/>
1003
+ </element>
1004
+ </define>
1005
+ <define name="dd">
1006
+ <element name="dd">
1007
+ <zeroOrMore>
1008
+ <ref name="paragraph-with-footnote"/>
1009
+ </zeroOrMore>
1010
+ </element>
1011
+ </define>
1012
+ <define name="BibData">
1013
+ <optional>
1014
+ <attribute name="type">
1015
+ <ref name="BibItemType"/>
1016
+ </attribute>
1017
+ </optional>
1018
+ <oneOrMore>
1019
+ <ref name="btitle"/>
1020
+ </oneOrMore>
1021
+ <optional>
1022
+ <ref name="formattedref"/>
1023
+ </optional>
1024
+ <zeroOrMore>
1025
+ <ref name="bsource"/>
1026
+ </zeroOrMore>
1027
+ <zeroOrMore>
1028
+ <ref name="docidentifier"/>
1029
+ </zeroOrMore>
1030
+ <zeroOrMore>
1031
+ <ref name="bdate"/>
1032
+ </zeroOrMore>
1033
+ <zeroOrMore>
1034
+ <ref name="contributor"/>
1035
+ </zeroOrMore>
1036
+ <optional>
1037
+ <ref name="edition"/>
1038
+ </optional>
1039
+ <zeroOrMore>
1040
+ <ref name="biblionote"/>
1041
+ </zeroOrMore>
1042
+ <zeroOrMore>
1043
+ <ref name="language"/>
1044
+ </zeroOrMore>
1045
+ <zeroOrMore>
1046
+ <ref name="script"/>
1047
+ </zeroOrMore>
1048
+ <optional>
1049
+ <ref name="abstract"/>
1050
+ </optional>
1051
+ <optional>
1052
+ <ref name="status"/>
1053
+ </optional>
1054
+ <ref name="copyright"/>
1055
+ <zeroOrMore>
1056
+ <ref name="docrelation"/>
1057
+ </zeroOrMore>
1058
+ </define>
1059
+ </grammar>