metanorma-nist 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,19 +9,6 @@
9
9
  <start>
10
10
  <ref name="nist-standard"/>
11
11
  </start>
12
- <define name="btitle">
13
- <element name="title">
14
- <ref name="TypedTitleString"/>
15
- </element>
16
- </define>
17
- <define name="docidentifier">
18
- <element name="docidentifier">
19
- <optional>
20
- <attribute name="type"/>
21
- </optional>
22
- <text/>
23
- </element>
24
- </define>
25
12
  <define name="figure">
26
13
  <element name="figure">
27
14
  <attribute name="id">
@@ -62,9 +49,18 @@
62
49
  </choice>
63
50
  </element>
64
51
  </define>
65
- <define name="BibItemType" combine="choice">
52
+ <define name="DocumentType">
66
53
  <value>standard</value>
67
54
  </define>
55
+ <define name="TitleType">
56
+ <choice>
57
+ <value>alternative</value>
58
+ <value>original</value>
59
+ <value>unofficial</value>
60
+ <value>subtitle</value>
61
+ <value>main</value>
62
+ </choice>
63
+ </define>
68
64
  <!-- DocRelationType |= "obsoletedBy" | "supersedes" | "supersededBy" -->
69
65
  <define name="DocRelationType">
70
66
  <choice>
@@ -107,57 +103,6 @@
107
103
  <value>superseded</value>
108
104
  </choice>
109
105
  </define>
110
- <!-- TitleType |= "document-class" -->
111
- <define name="TitleType">
112
- <choice>
113
- <value>alternative</value>
114
- <value>original</value>
115
- <value>unofficial</value>
116
- <value>subtitle</value>
117
- <value>main</value>
118
- <value>document-class</value>
119
- <value>short-title</value>
120
- <value>short-subtitle</value>
121
- </choice>
122
- </define>
123
- <define name="editorialgroup">
124
- <element name="editorialgroup">
125
- <oneOrMore>
126
- <ref name="committee"/>
127
- </oneOrMore>
128
- </element>
129
- </define>
130
- <define name="stage">
131
- <element name="stage">
132
- <choice>
133
- <value>draft-internal</value>
134
- <value>draft-wip</value>
135
- <value>draft-prelim</value>
136
- <value>draft-public</value>
137
- <value>final</value>
138
- <value>final-review</value>
139
- </choice>
140
- </element>
141
- </define>
142
- <define name="substage">
143
- <element name="substage">
144
- <choice>
145
- <value>active</value>
146
- <value>retired</value>
147
- <value>withdrawn</value>
148
- </choice>
149
- </element>
150
- </define>
151
- <define name="iteration">
152
- <element name="iteration">
153
- <text/>
154
- </element>
155
- </define>
156
- <define name="title-main">
157
- <element name="title-main">
158
- <ref name="FormattedString"/>
159
- </element>
160
- </define>
161
106
  <define name="preface">
162
107
  <element name="preface">
163
108
  <optional>
@@ -218,169 +163,23 @@
218
163
  </choice>
219
164
  </element>
220
165
  </define>
221
- <define name="BibData">
166
+ <define name="BibDataExtensionType">
222
167
  <optional>
223
- <attribute name="type">
224
- <ref name="BibItemType"/>
225
- </attribute>
168
+ <ref name="doctype"/>
226
169
  </optional>
227
170
  <oneOrMore>
228
- <ref name="btitle"/>
171
+ <ref name="bkeyword"/>
229
172
  </oneOrMore>
230
173
  <optional>
231
- <ref name="formattedref"/>
232
- </optional>
233
- <zeroOrMore>
234
- <ref name="bsource"/>
235
- </zeroOrMore>
236
- <zeroOrMore>
237
- <ref name="nistdocidentifier"/>
238
- </zeroOrMore>
239
- <optional>
240
- <ref name="docnumber"/>
241
- </optional>
242
- <zeroOrMore>
243
- <ref name="bdate"/>
244
- </zeroOrMore>
245
- <zeroOrMore>
246
- <ref name="contributor"/>
247
- </zeroOrMore>
248
- <optional>
249
- <ref name="edition"/>
250
- </optional>
251
- <optional>
252
- <ref name="revision"/>
253
- </optional>
254
- <optional>
255
- <ref name="version"/>
174
+ <ref name="commentperiod"/>
256
175
  </optional>
257
- <zeroOrMore>
258
- <ref name="biblionote"/>
259
- </zeroOrMore>
260
- <zeroOrMore>
261
- <ref name="language"/>
262
- </zeroOrMore>
263
- <zeroOrMore>
264
- <ref name="script"/>
265
- </zeroOrMore>
266
- <zeroOrMore>
267
- <ref name="abstract"/>
268
- </zeroOrMore>
269
- <optional>
270
- <ref name="status"/>
271
- </optional>
272
- <ref name="copyright"/>
273
- <zeroOrMore>
274
- <ref name="docrelation"/>
275
- </zeroOrMore>
276
- <optional>
277
- <ref name="nistseries"/>
278
- </optional>
279
- <optional>
280
- <ref name="nistsubseries"/>
281
- </optional>
282
- <optional>
283
- <ref name="editorialgroup"/>
284
- </optional>
285
- <zeroOrMore>
286
- <ref name="ics"/>
287
- </zeroOrMore>
288
- <optional>
289
- <ref name="security"/>
290
- </optional>
291
- <oneOrMore>
292
- <ref name="keyword"/>
293
- </oneOrMore>
294
- <ref name="commentperiod"/>
295
176
  </define>
296
177
  </include>
297
- <define name="committee">
298
- <element name="committee">
299
- <attribute name="type">
300
- <choice>
301
- <value>technical</value>
302
- <value>provisional</value>
303
- </choice>
304
- </attribute>
305
- <text/>
306
- </element>
307
- </define>
308
- <define name="title-sub">
309
- <element name="title-sub">
310
- <ref name="FormattedString"/>
311
- </element>
312
- </define>
313
- <define name="nistdocidentifier">
314
- <element name="docidentifier">
315
- <attribute name="type">
316
- <choice>
317
- <value>nist</value>
318
- <value>nist-long</value>
319
- <value>nist-mr</value>
320
- </choice>
321
- </attribute>
322
- <text/>
323
- </element>
324
- </define>
325
- <define name="security">
326
- <element name="security">
178
+ <define name="bkeyword">
179
+ <element name="keyword">
327
180
  <text/>
328
181
  </element>
329
182
  </define>
330
- <define name="nistseries">
331
- <element name="series">
332
- <attribute name="type">
333
- <value>main</value>
334
- </attribute>
335
- <ref name="nistseriestitle"/>
336
- <optional>
337
- <ref name="abbreviation"/>
338
- </optional>
339
- </element>
340
- </define>
341
- <define name="nistsubseries">
342
- <element name="series">
343
- <attribute name="type">
344
- <value>secondary</value>
345
- </attribute>
346
- <ref name="nistsubseriestitle"/>
347
- </element>
348
- </define>
349
- <define name="nistseriestitle">
350
- <element name="title">
351
- <choice>
352
- <value>NIST Advanced Manufacturing Series</value>
353
- <value>NIST Building Science Series</value>
354
- <value>NIST Federal Information Processing Standards</value>
355
- <value>NIST Grant/Contract Reports</value>
356
- <value>NIST Handbook</value>
357
- <value>ITL Bulletin</value>
358
- <value>Journal of Physical and Chemical Reference Data</value>
359
- <value>NIST Journal of Research</value>
360
- <value>NIST Letter Circular</value>
361
- <value>NIST Monograph</value>
362
- <value>NIST National Construction Safety Team Act Reports</value>
363
- <value>NIST National Standard Reference Data Series</value>
364
- <value>NIST Interagency/Internal Report</value>
365
- <value>NIST Product Standards</value>
366
- <value>NIST Special Publication</value>
367
- <value>NIST Technical Note</value>
368
- <value>NIST Other</value>
369
- <value>CSRC White Paper</value>
370
- <value>CSRC Book</value>
371
- <value>CSRC Use Case</value>
372
- <value>CSRC Building Block</value>
373
- </choice>
374
- </element>
375
- </define>
376
- <define name="nistsubseriestitle">
377
- <element name="title">
378
- <choice>
379
- <value>computer-security</value>
380
- <value>information-security</value>
381
- </choice>
382
- </element>
383
- </define>
384
183
  <define name="commentperiod">
385
184
  <element name="commentperiod">
386
185
  <element name="from">
@@ -408,11 +207,6 @@
408
207
  <ref name="Basic-Section"/>
409
208
  </element>
410
209
  </define>
411
- <define name="revision">
412
- <element name="revision">
413
- <text/>
414
- </element>
415
- </define>
416
210
  <define name="nist-standard">
417
211
  <element name="nist-standard">
418
212
  <ref name="bibdata"/>
@@ -25,6 +25,11 @@
25
25
  <ref name="ObligationType"/>
26
26
  </attribute>
27
27
  </optional>
28
+ <optional>
29
+ <attribute name="unnumbered">
30
+ <data type="boolean"/>
31
+ </attribute>
32
+ </optional>
28
33
  <attribute name="id">
29
34
  <data type="ID"/>
30
35
  </attribute>
@@ -1,24 +1,70 @@
1
1
  module Asciidoctor
2
2
  module NIST
3
3
  class Converter < Standoc::Converter
4
- def title_validate(root)
4
+ def title_validate(root)
5
5
  nil
6
6
  end
7
7
 
8
- def validate(doc)
8
+ def content_validate(doc)
9
+ super
10
+ bibdata_validate(doc.root)
11
+ end
12
+
13
+ def bibdata_validate(doc)
14
+ doctype_validate(doc)
15
+ stage_validate(doc)
16
+ substage_validate(doc)
17
+ iteration_validate(doc)
18
+ series_validate(doc)
19
+ end
20
+
21
+ def doctype_validate(xmldoc)
22
+ doctype = xmldoc&.at("//bibdata/ext/doctype")&.text
23
+ %w(standard).include? doctype or
24
+ warn "Document Attributes: #{doctype} is not a recognised document type"
25
+ end
26
+
27
+ def stage_validate(xmldoc)
28
+ stage = xmldoc&.at("//bibdata/status/stage")&.text
29
+ %w(draft-internal draft-wip draft-prelim draft-public draft-approval
30
+ final final-review).include? stage or
31
+ warn "Document Attributes: #{stage} is not a recognised stage"
32
+ end
33
+
34
+ def substage_validate(xmldoc)
35
+ substage = xmldoc&.at("//bibdata/status/substage")&.text or return
36
+ %w(active retired withdrawn).include? substage or
37
+ warn "Document Attributes: #{substage} is not a recognised substage"
38
+ end
39
+
40
+ def iteration_validate(xmldoc)
41
+ iteration = xmldoc&.at("//bibdata/status/iteration")&.text or return
42
+ %w(final).include? iteration.downcase or /^\d+$/.match(iteration) or
43
+ warn "Document Attributes: #{iteration} is not a recognised iteration"
44
+ end
45
+
46
+ def series_validate(xmldoc)
47
+ series = xmldoc&.at("//bibdata/series/title")&.text or return
48
+ found = false
49
+ SERIES.each { |_, v| found = true if v == series }
50
+ found or
51
+ warn "Document Attributes: #{series} is not a recognised series"
52
+ end
53
+
54
+ def validate(doc)
9
55
  content_validate(doc)
10
56
  schema_validate(formattedstr_strip(doc.dup),
11
57
  File.join(File.dirname(__FILE__), "nist.rng"))
12
58
  end
13
59
 
14
- def introduction_validate(doc)
60
+ def introduction_validate(doc)
15
61
  intro = doc.at("//sections/clause/title")
16
62
  intro&.text == "Introduction" or
17
63
  warn "First section of document body should be Introduction, "\
18
64
  "not #{intro&.text}"
19
65
  end
20
66
 
21
- REF_SECTIONS_TO_VALIDATE = "//references[not(parent::clause)]/title | "\
67
+ REF_SECTIONS_TO_VALIDATE = "//references[not(parent::clause)]/title | "\
22
68
  "//clause[descendant::references][not(parent::clause)]/title".freeze
23
69
 
24
70
  def section_validate(doc)
@@ -35,7 +35,7 @@ module IsoDoc
35
35
  patent = ["Call for Patent Claims", "Patent Disclosure Notice"].include? title&.text
36
36
  out.div **attr_code(id: c["id"]) do |s|
37
37
  page_break(s) if patent
38
- clause_name(get_anchors[c['id']][:label], title&.content, s,
38
+ clause_name(anchor(c['id'], :label), title&.content, s,
39
39
  class: (c.name == "executivesummary") ? "NormalTitle" :
40
40
  "IntroTitle")
41
41
  c.elements.reject { |c1| c1.name == "title" }.each do |c1|
@@ -70,9 +70,10 @@ module IsoDoc
70
70
 
71
71
  def requirement_cleanup(docxml)
72
72
  docxml.xpath("//div[@class = 'recommend' or @class = 'require' "\
73
- "or @class = 'permission'][title]").each do |d|
74
- title = d.at("./title")
73
+ "or @class = 'permission']").each do |d|
74
+ title = d.at("./p[@class = 'AdmonitionTitle']") or next
75
75
  title.name = "b"
76
+ title.delete("class")
76
77
  n = title.next_element
77
78
  n&.children&.first&.add_previous_sibling(" ")
78
79
  n&.children&.first&.add_previous_sibling(title.remove)
@@ -146,39 +147,15 @@ module IsoDoc
146
147
  end
147
148
  end
148
149
 
149
- def recommendation_parse(node, out)
150
- name = node["type"]
151
- out.div **{ class: "recommend" } do |t|
152
- t.title { |b| b << "Recommendation #{get_anchors[node['id']][:label]}:" }
153
- node.children.each do |n|
154
- parse(n, t)
155
- end
156
- end
157
- end
158
-
159
- def requirement_parse(node, out)
160
- name = node["type"]
161
- out.div **{ class: "require" } do |t|
162
- t.title { |b| b << "Requirement #{get_anchors[node['id']][:label]}:" }
163
- node.children.each do |n|
164
- parse(n, t)
165
- end
166
- end
167
- end
168
-
169
- def permission_parse(node, out)
170
- name = node["type"]
171
- out.div **{ class: "permission" } do |t|
172
- t.title { |b| b << "Permission #{get_anchors[node['id']][:label]}:" }
173
- node.children.each do |n|
174
- parse(n, t)
175
- end
176
- end
177
- end
178
-
179
150
  def errata_parse(node, out)
180
151
  out.a **{ name: "errata_XYZZY" }
181
152
  out.table **make_table_attr(node) do |t|
153
+ errata_head(t)
154
+ errata_body(t, node)
155
+ end
156
+ end
157
+
158
+ def errata_head(t)
182
159
  t.thead do |h|
183
160
  h.tr do |tr|
184
161
  %w(Date Type Change Pages).each do |hdr|
@@ -186,6 +163,9 @@ module IsoDoc
186
163
  end
187
164
  end
188
165
  end
166
+ end
167
+
168
+ def errata_body(t, node)
189
169
  t.tbody do |b|
190
170
  node.xpath(ns("./row")).each do |row|
191
171
  b.tr do |tr|
@@ -199,7 +179,6 @@ module IsoDoc
199
179
  end
200
180
  end
201
181
  end
202
- end
203
182
  end
204
183
 
205
184
  MIDDLE_CLAUSE = "//clause[parent::sections] | "\
@@ -291,7 +270,7 @@ module IsoDoc
291
270
 
292
271
  def annex_name(annex, name, div)
293
272
  div.h1 **{ class: "Annex" } do |t|
294
- t << "#{get_anchors[annex['id']][:label]} &mdash; "
273
+ t << "#{anchor(annex['id'], :label)} &mdash; "
295
274
  t.b do |b|
296
275
  if @bibliographycount == 1 && annex.at(ns("./references"))
297
276
  b << "References"
@@ -379,7 +358,7 @@ module IsoDoc
379
358
 
380
359
  def omit_docid_prefix(prefix)
381
360
  return true if prefix.nil? || prefix.empty?
382
- return ["ISO", "IEC", "nist"].include? prefix
361
+ return ["ISO", "IEC", "NIST"].include? prefix
383
362
  end
384
363
 
385
364
  def nist_reference_format(b, r)