metanorma-csand 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,164 @@
1
+ require "asciidoctor"
2
+ require "asciidoctor/csand/version"
3
+ require "isodoc/csand/csandconvert"
4
+ require "asciidoctor/standoc/converter"
5
+
6
+ module Asciidoctor
7
+ module Csand
8
+ CSAND_NAMESPACE = "https://open.ribose.com/standards/csand"
9
+
10
+ # A {Converter} implementation that generates CSD output, and a document
11
+ # schema encapsulation of the document for validation
12
+ class Converter < Standoc::Converter
13
+
14
+ register_for "csand"
15
+
16
+ def metadata_author(node, xml)
17
+ xml.contributor do |c|
18
+ c.role **{ type: "author" }
19
+ c.organization do |a|
20
+ a.name "Ribose"
21
+ end
22
+ end
23
+ end
24
+
25
+ def metadata_publisher(node, xml)
26
+ xml.contributor do |c|
27
+ c.role **{ type: "publisher" }
28
+ c.organization do |a|
29
+ a.name "Ribose"
30
+ end
31
+ end
32
+ end
33
+
34
+ def metadata_committee(node, xml)
35
+ xml.editorialgroup do |a|
36
+ a.committee node.attr("technical-committee"),
37
+ **attr_code(type: node.attr("technical-committee-type"))
38
+ end
39
+ end
40
+
41
+ def title(node, xml)
42
+ ["en"].each do |lang|
43
+ xml.title **{ language: lang, format: "plain" } do |t|
44
+ t << asciidoc_sub(node.attr("title"))
45
+ end
46
+ end
47
+ end
48
+
49
+ def metadata_status(node, xml)
50
+ xml.status(**{ format: "plain" }) { |s| s << node.attr("status") }
51
+ end
52
+
53
+ def metadata_id(node, xml)
54
+ xml.docidentifier { |i| i << node.attr("docnumber") }
55
+ end
56
+
57
+ def metadata_copyright(node, xml)
58
+ from = node.attr("copyright-year") || Date.today.year
59
+ xml.copyright do |c|
60
+ c.from from
61
+ c.owner do |owner|
62
+ owner.organization do |o|
63
+ o.name "Ribose"
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ def title_validate(root)
70
+ nil
71
+ end
72
+
73
+ def makexml(node)
74
+ result = ["<?xml version='1.0' encoding='UTF-8'?>\n<csand-standard>"]
75
+ @draft = node.attributes.has_key?("draft")
76
+ result << noko { |ixml| front node, ixml }
77
+ result << noko { |ixml| middle node, ixml }
78
+ result << "</csand-standard>"
79
+ result = textcleanup(result.flatten * "\n")
80
+ ret1 = cleanup(Nokogiri::XML(result))
81
+ validate(ret1)
82
+ ret1.root.add_namespace(nil, CSAND_NAMESPACE)
83
+ ret1
84
+ end
85
+
86
+ def doctype(node)
87
+ d = node.attr("doctype")
88
+ unless %w{guidance proposal standard report whitepaper charter policy glossary case-study}.include? d
89
+ warn "#{d} is not a legal document type: reverting to 'standard'"
90
+ d = "standard"
91
+ end
92
+ d
93
+ end
94
+
95
+ def document(node)
96
+ init(node)
97
+ ret1 = makexml(node)
98
+ ret = ret1.to_xml(indent: 2)
99
+ unless node.attr("nodoc") || !node.attr("docfile")
100
+ filename = node.attr("docfile").gsub(/\.adoc/, ".xml").
101
+ gsub(%r{^.*/}, "")
102
+ File.open(filename, "w") { |f| f.write(ret) }
103
+ html_converter(node).convert filename unless node.attr("nodoc")
104
+ end
105
+ @files_to_delete.each { |f| system "rm #{f}" }
106
+ ret
107
+ end
108
+
109
+ def validate(doc)
110
+ content_validate(doc)
111
+ schema_validate(formattedstr_strip(doc.dup),
112
+ File.join(File.dirname(__FILE__), "csand.rng"))
113
+ end
114
+
115
+ def literal(node)
116
+ noko do |xml|
117
+ xml.figure **id_attr(node) do |f|
118
+ figure_title(node, f)
119
+ f.pre node.lines.join("\n")
120
+ end
121
+ end
122
+ end
123
+
124
+ def sections_cleanup(x)
125
+ super
126
+ x.xpath("//*[@inline-header]").each do |h|
127
+ h.delete("inline-header")
128
+ end
129
+ end
130
+
131
+ def style(n, t)
132
+ return
133
+ end
134
+
135
+ def html_converter(node)
136
+ IsoDoc::Csand::HtmlConvert.new(html_extract_attributes(node))
137
+ end
138
+
139
+ def inline_quoted(node)
140
+ noko do |xml|
141
+ case node.type
142
+ when :emphasis then xml.em node.text
143
+ when :strong then xml.strong node.text
144
+ when :monospaced then xml.tt node.text
145
+ when :double then xml << "\"#{node.text}\""
146
+ when :single then xml << "'#{node.text}'"
147
+ when :superscript then xml.sup node.text
148
+ when :subscript then xml.sub node.text
149
+ when :asciimath then stem_parse(node.text, xml)
150
+ else
151
+ case node.role
152
+ when "strike" then xml.strike node.text
153
+ when "smallcap" then xml.smallcap node.text
154
+ when "keyword" then xml.keyword node.text
155
+ else
156
+ xml << node.text
157
+ end
158
+ end
159
+ end.join
160
+ end
161
+
162
+ end
163
+ end
164
+ end
@@ -0,0 +1,154 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
3
+ <!--
4
+ Currently we inherit from a namespaced grammar, isostandard. Until we inherit from isodoc,
5
+ we cannot have a new default namespace: we will end up with a grammar with two different
6
+ namespaces, one for isostandard and one for csand additions. And we do not want that.
7
+ -->
8
+ <include href="isostandard.rng">
9
+ <start>
10
+ <ref name="csand-standard"/>
11
+ </start>
12
+ <define name="language">
13
+ <element name="language">
14
+ <value>en</value>
15
+ </element>
16
+ </define>
17
+ <define name="docidentifier">
18
+ <element name="docidentifier">
19
+ <text/>
20
+ </element>
21
+ </define>
22
+ <define name="btitle">
23
+ <element name="title">
24
+ <ref name="FormattedString"/>
25
+ </element>
26
+ </define>
27
+ <define name="figure">
28
+ <element name="figure">
29
+ <attribute name="id">
30
+ <data type="ID"/>
31
+ </attribute>
32
+ <optional>
33
+ <ref name="source"/>
34
+ </optional>
35
+ <optional>
36
+ <ref name="tname"/>
37
+ </optional>
38
+ <choice>
39
+ <oneOrMore>
40
+ <ref name="figure"/>
41
+ </oneOrMore>
42
+ <group>
43
+ <choice>
44
+ <zeroOrMore>
45
+ <ref name="TextElement"/>
46
+ </zeroOrMore>
47
+ <ref name="pre"/>
48
+ </choice>
49
+ <zeroOrMore>
50
+ <ref name="note"/>
51
+ </zeroOrMore>
52
+ <optional>
53
+ <ref name="dl"/>
54
+ </optional>
55
+ </group>
56
+ </choice>
57
+ </element>
58
+ </define>
59
+ <define name="status">
60
+ <element name="status">
61
+ <choice>
62
+ <value>proposal</value>
63
+ <value>working-draft</value>
64
+ <value>committee-draft</value>
65
+ <value>draft-standard</value>
66
+ <value>final-draft</value>
67
+ <value>published</value>
68
+ <value>withdrawn</value>
69
+ <ref name="LocalizedString"/>
70
+ </choice>
71
+ </element>
72
+ </define>
73
+ <!-- TextElement |= keyword -->
74
+ <define name="TextElement">
75
+ <choice>
76
+ <text/>
77
+ <ref name="em"/>
78
+ <ref name="eref"/>
79
+ <ref name="strong"/>
80
+ <ref name="stem"/>
81
+ <ref name="sub"/>
82
+ <ref name="sup"/>
83
+ <ref name="tt"/>
84
+ <ref name="strike"/>
85
+ <ref name="smallcap"/>
86
+ <ref name="xref"/>
87
+ <ref name="br"/>
88
+ <ref name="hyperlink"/>
89
+ <ref name="hr"/>
90
+ <ref name="pagebreak"/>
91
+ <ref name="bookmark"/>
92
+ <ref name="keyword"/>
93
+ </choice>
94
+ </define>
95
+ <define name="BibItemType" combine="choice">
96
+ <choice>
97
+ <value>guidance</value>
98
+ <value>proposal</value>
99
+ <value>standard</value>
100
+ <value>report</value>
101
+ <value>whitepaper</value>
102
+ <value>charter</value>
103
+ <value>policy</value>
104
+ <value>glossary</value>
105
+ <value>case-study</value>
106
+ </choice>
107
+ </define>
108
+ <define name="editorialgroup">
109
+ <element name="editorialgroup">
110
+ <ref name="committee"/>
111
+ </element>
112
+ </define>
113
+ </include>
114
+ <define name="committee">
115
+ <element name="committee">
116
+ <attribute name="type">
117
+ <choice>
118
+ <value>technical</value>
119
+ <value>provisional</value>
120
+ </choice>
121
+ </attribute>
122
+ <text/>
123
+ </element>
124
+ </define>
125
+ <define name="pre">
126
+ <element name="pre">
127
+ <text/>
128
+ </element>
129
+ </define>
130
+ <define name="keyword">
131
+ <element name="keyword">
132
+ <text/>
133
+ </element>
134
+ </define>
135
+ <define name="csand-standard">
136
+ <element name="csand-standard">
137
+ <ref name="bibdata"/>
138
+ <optional>
139
+ <ref name="version"/>
140
+ </optional>
141
+ <zeroOrMore>
142
+ <ref name="termdocsource"/>
143
+ </zeroOrMore>
144
+ <ref name="preface"/>
145
+ <oneOrMore>
146
+ <ref name="sections"/>
147
+ </oneOrMore>
148
+ <zeroOrMore>
149
+ <ref name="annex"/>
150
+ </zeroOrMore>
151
+ <ref name="bibliography"/>
152
+ </element>
153
+ </define>
154
+ </grammar>
@@ -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>