metanorma-nist 0.0.1

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