metanorma-unece 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.hound.yml +3 -0
  4. data/.rubocop.ribose.yml +66 -0
  5. data/.rubocop.tb.yml +650 -0
  6. data/.rubocop.yml +15 -0
  7. data/.travis.yml +21 -0
  8. data/CODE_OF_CONDUCT.md +74 -0
  9. data/Gemfile +4 -0
  10. data/LICENSE +25 -0
  11. data/README.adoc +202 -0
  12. data/Rakefile +6 -0
  13. data/bin/console +14 -0
  14. data/bin/rspec +17 -0
  15. data/bin/setup +8 -0
  16. data/lib/asciidoctor/unece.rb +7 -0
  17. data/lib/asciidoctor/unece/biblio.rng +880 -0
  18. data/lib/asciidoctor/unece/converter.rb +240 -0
  19. data/lib/asciidoctor/unece/isodoc.rng +1066 -0
  20. data/lib/asciidoctor/unece/isostandard.rng +1054 -0
  21. data/lib/asciidoctor/unece/unece.rng +247 -0
  22. data/lib/isodoc/unece.rb +9 -0
  23. data/lib/isodoc/unece/html/header.html +164 -0
  24. data/lib/isodoc/unece/html/html_unece_intro.html +27 -0
  25. data/lib/isodoc/unece/html/html_unece_titlepage.html +112 -0
  26. data/lib/isodoc/unece/html/htmlstyle.scss +1119 -0
  27. data/lib/isodoc/unece/html/logo.jpg +0 -0
  28. data/lib/isodoc/unece/html/scripts.html +82 -0
  29. data/lib/isodoc/unece/html/unece.scss +660 -0
  30. data/lib/isodoc/unece/html/word_unece_intro.html +24 -0
  31. data/lib/isodoc/unece/html/word_unece_plenary_titlepage.html +129 -0
  32. data/lib/isodoc/unece/html/word_unece_titlepage.html +17 -0
  33. data/lib/isodoc/unece/html/wordstyle.scss +1088 -0
  34. data/lib/isodoc/unece/html_convert.rb +392 -0
  35. data/lib/isodoc/unece/metadata.rb +93 -0
  36. data/lib/isodoc/unece/word_convert.rb +405 -0
  37. data/lib/metanorma-unece.rb +8 -0
  38. data/lib/metanorma/unece.rb +11 -0
  39. data/lib/metanorma/unece/UN_emblem_blue.svg +193 -0
  40. data/lib/metanorma/unece/processor.rb +40 -0
  41. data/lib/metanorma/unece/version.rb +5 -0
  42. data/metanorma-unece.gemspec +47 -0
  43. metadata +353 -0
@@ -0,0 +1,240 @@
1
+ require "asciidoctor"
2
+ require "asciidoctor/standoc/converter"
3
+ require "fileutils"
4
+
5
+ module Asciidoctor
6
+ module Unece
7
+
8
+ # A {Converter} implementation that generates RSD output, and a document
9
+ # schema encapsulation of the document for validation
10
+ #
11
+ class Converter < Standoc::Converter
12
+
13
+ register_for "unece"
14
+
15
+ def metadata_author(node, xml)
16
+ xml.contributor do |c|
17
+ c.role **{ type: "author" }
18
+ c.organization do |a|
19
+ a.name Metanorma::Unece::ORGANIZATION_NAME_SHORT
20
+ end
21
+ end
22
+ end
23
+
24
+ def metadata_publisher(node, xml)
25
+ xml.contributor do |c|
26
+ c.role **{ type: "publisher" }
27
+ c.organization do |a|
28
+ a.name Metanorma::Unece::ORGANIZATION_NAME_SHORT
29
+ end
30
+ end
31
+ end
32
+
33
+ def metadata_committee(node, xml)
34
+ xml.editorialgroup do |a|
35
+ a.committee node.attr("committee"),
36
+ **attr_code(type: node.attr("committee-type"))
37
+ i = 2
38
+ while node.attr("committee_#{i}") do
39
+ a.committee node.attr("committee_#{i}"),
40
+ **attr_code(type: node.attr("committee-type_#{i}"))
41
+ i += 1
42
+ end
43
+ end
44
+ end
45
+
46
+ def title(node, xml)
47
+ ["en"].each do |lang|
48
+ xml.title **{ language: lang, format: "plain" } do |t|
49
+ t << asciidoc_sub(node.attr("title"))
50
+ end
51
+ xml.subtitle **{ language: lang, format: "plain" } do |t|
52
+ t << asciidoc_sub(node.attr("subtitle"))
53
+ end
54
+ end
55
+ end
56
+
57
+ def metadata_status(node, xml)
58
+ xml.status(**{ format: "plain" }) { |s| s << node.attr("status") }
59
+ end
60
+
61
+ def metadata_id(node, xml)
62
+ xml.docidentifier { |i| i << node.attr("docnumber") }
63
+ end
64
+
65
+ def metadata_copyright(node, xml)
66
+ from = node.attr("copyright-year") || Date.today.year
67
+ xml.copyright do |c|
68
+ c.from from
69
+ c.owner do |owner|
70
+ owner.organization do |o|
71
+ o.name Metanorma::Unece::ORGANIZATION_NAME_SHORT
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ def metadata_session(node, xml)
78
+ xml.session do |session|
79
+ session.number node.attr("session") if node.attr("session")
80
+ session.date node.attr("session-date") if node.attr("session-date")
81
+ session.agenda_item node.attr("agenda-item") if node.attr("agenda-item")
82
+ session.collaborator node.attr("collaborator") if node.attr("collaborator")
83
+ session.id node.attr("agenda-id") if node.attr("agenda-id")
84
+ session.distribution node.attr("distribution") if node.attr("distribution")
85
+ end
86
+ end
87
+
88
+ def metadata(node, xml)
89
+ super
90
+ metadata_session(node, xml)
91
+ end
92
+
93
+ def title_validate(root)
94
+ nil
95
+ end
96
+
97
+ def makexml(node)
98
+ result = ["<?xml version='1.0' encoding='UTF-8'?>\n<unece-standard>"]
99
+ @draft = node.attributes.has_key?("draft")
100
+ result << noko { |ixml| front node, ixml }
101
+ result << noko { |ixml| middle node, ixml }
102
+ result << "</unece-standard>"
103
+ result = textcleanup(result.flatten * "\n")
104
+ ret1 = cleanup(Nokogiri::XML(result))
105
+ validate(ret1)
106
+ ret1.root.add_namespace(nil, Metanorma::Unece::DOCUMENT_NAMESPACE)
107
+ ret1
108
+ end
109
+
110
+ def doctype(node)
111
+ d = node.attr("doctype")
112
+ unless %w{plenary recommendation}.include? d
113
+ warn "#{d} is not a legal document type: reverting to 'recommendation'"
114
+ d = "recommendation"
115
+ end
116
+ d
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
+ end
130
+ @files_to_delete.each { |f| FileUtils.rm f }
131
+ ret
132
+ end
133
+
134
+ def validate(doc)
135
+ content_validate(doc)
136
+ schema_validate(formattedstr_strip(doc.dup),
137
+ File.join(File.dirname(__FILE__), "unece.rng"))
138
+ end
139
+
140
+ def literal(node)
141
+ noko do |xml|
142
+ xml.figure **id_attr(node) do |f|
143
+ figure_title(node, f)
144
+ f.pre node.lines.join("\n")
145
+ end
146
+ end
147
+ end
148
+
149
+ def sections_cleanup(x)
150
+ super
151
+ x.xpath("//*[@inline-header]").each do |h|
152
+ h.delete("inline-header")
153
+ end
154
+ end
155
+
156
+ def style(n, t)
157
+ return
158
+ end
159
+
160
+ def html_converter(node)
161
+ IsoDoc::Unece::HtmlConvert.new(html_extract_attributes(node))
162
+ end
163
+
164
+ def word_converter(node)
165
+ IsoDoc::Unece::WordConvert.new(doc_extract_attributes(node))
166
+ end
167
+
168
+ def inline_quoted(node)
169
+ noko do |xml|
170
+ case node.type
171
+ when :emphasis then xml.em node.text
172
+ when :strong then xml.strong node.text
173
+ when :monospaced then xml.tt node.text
174
+ when :double then xml << "\"#{node.text}\""
175
+ when :single then xml << "'#{node.text}'"
176
+ when :superscript then xml.sup node.text
177
+ when :subscript then xml.sub node.text
178
+ when :asciimath then stem_parse(node.text, xml)
179
+ else
180
+ case node.role
181
+ when "strike" then xml.strike node.text
182
+ when "smallcap" then xml.smallcap node.text
183
+ when "keyword" then xml.keyword node.text
184
+ else
185
+ xml << node.text
186
+ end
187
+ end
188
+ end.join
189
+ end
190
+
191
+ def sections_cleanup(xmldoc)
192
+ super
193
+ xmldoc.xpath("//clause/p | //annex/p").each do |p|
194
+ cl = Nokogiri::XML::Node.new("clause", xmldoc)
195
+ cl["id"] = p["id"]
196
+ cl["inline-header"]="true"
197
+ p["id"] = "_" + UUIDTools::UUID.random_create
198
+ p.replace(cl)
199
+ p.parent = cl
200
+ while n = cl.next_element and !%w(p clause).include? n.name
201
+ n.parent = cl
202
+ end
203
+ end
204
+ end
205
+
206
+ def admonition(node)
207
+ return termnote(node) if in_terms?
208
+ return note(node) if node.attr("name") == "note"
209
+ noko do |xml|
210
+ xml.admonition **admonition_attrs(node) do |a|
211
+ unless node.title.nil?
212
+ a.name { |name| name << node.title }
213
+ end
214
+ wrap_in_para(node, a)
215
+ end
216
+ end.join("\n")
217
+ end
218
+
219
+ def clause_parse(attrs, xml, node)
220
+ abstract_parse(attrs, xml, node) && return if node.attr("style") == "abstract"
221
+ super
222
+ end
223
+
224
+ def abstract_parse(attrs, xml, node)
225
+ xml.abstract **attr_code(attrs) do |xml_section|
226
+ xml_section << node.content
227
+ end
228
+ end
229
+
230
+ def make_preface(x, s)
231
+ super
232
+ if x.at("//abstract")
233
+ preface = s.at("//preface") || s.add_previous_sibling("<preface/>").first
234
+ abstract = x.at("//abstract").remove
235
+ preface.prepend_child abstract.remove
236
+ end
237
+ end
238
+ end
239
+ end
240
+ end
@@ -0,0 +1,1066 @@
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
+ <optional>
960
+ <attribute name="id">
961
+ <data type="ID"/>
962
+ </attribute>
963
+ </optional>
964
+ <oneOrMore>
965
+ <ref name="paragraph-with-footnote"/>
966
+ </oneOrMore>
967
+ </element>
968
+ </define>
969
+ <define name="ol">
970
+ <element name="ol">
971
+ <attribute name="id">
972
+ <data type="ID"/>
973
+ </attribute>
974
+ <attribute name="type">
975
+ <choice>
976
+ <value>roman</value>
977
+ <value>alphabet</value>
978
+ <value>arabic</value>
979
+ <value>roman_upper</value>
980
+ <value>alphabet_upper</value>
981
+ </choice>
982
+ </attribute>
983
+ <oneOrMore>
984
+ <ref name="li"/>
985
+ </oneOrMore>
986
+ <zeroOrMore>
987
+ <ref name="note"/>
988
+ </zeroOrMore>
989
+ </element>
990
+ </define>
991
+ <define name="dl">
992
+ <element name="dl">
993
+ <attribute name="id">
994
+ <data type="ID"/>
995
+ </attribute>
996
+ <oneOrMore>
997
+ <ref name="dt"/>
998
+ <ref name="dd"/>
999
+ </oneOrMore>
1000
+ <zeroOrMore>
1001
+ <ref name="note"/>
1002
+ </zeroOrMore>
1003
+ </element>
1004
+ </define>
1005
+ <define name="dt">
1006
+ <element name="dt">
1007
+ <zeroOrMore>
1008
+ <ref name="TextElement"/>
1009
+ </zeroOrMore>
1010
+ </element>
1011
+ </define>
1012
+ <define name="dd">
1013
+ <element name="dd">
1014
+ <zeroOrMore>
1015
+ <ref name="paragraph-with-footnote"/>
1016
+ </zeroOrMore>
1017
+ </element>
1018
+ </define>
1019
+ <define name="BibData">
1020
+ <optional>
1021
+ <attribute name="type">
1022
+ <ref name="BibItemType"/>
1023
+ </attribute>
1024
+ </optional>
1025
+ <oneOrMore>
1026
+ <ref name="btitle"/>
1027
+ </oneOrMore>
1028
+ <optional>
1029
+ <ref name="formattedref"/>
1030
+ </optional>
1031
+ <zeroOrMore>
1032
+ <ref name="bsource"/>
1033
+ </zeroOrMore>
1034
+ <zeroOrMore>
1035
+ <ref name="docidentifier"/>
1036
+ </zeroOrMore>
1037
+ <zeroOrMore>
1038
+ <ref name="bdate"/>
1039
+ </zeroOrMore>
1040
+ <zeroOrMore>
1041
+ <ref name="contributor"/>
1042
+ </zeroOrMore>
1043
+ <optional>
1044
+ <ref name="edition"/>
1045
+ </optional>
1046
+ <zeroOrMore>
1047
+ <ref name="biblionote"/>
1048
+ </zeroOrMore>
1049
+ <zeroOrMore>
1050
+ <ref name="language"/>
1051
+ </zeroOrMore>
1052
+ <zeroOrMore>
1053
+ <ref name="script"/>
1054
+ </zeroOrMore>
1055
+ <optional>
1056
+ <ref name="abstract"/>
1057
+ </optional>
1058
+ <optional>
1059
+ <ref name="status"/>
1060
+ </optional>
1061
+ <ref name="copyright"/>
1062
+ <zeroOrMore>
1063
+ <ref name="docrelation"/>
1064
+ </zeroOrMore>
1065
+ </define>
1066
+ </grammar>