asciidoctor-iso 0.0.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +2 -0
  3. data/.gitignore +1 -0
  4. data/.hound.yml +3 -0
  5. data/.rubocop.ribose.yml +65 -0
  6. data/.rubocop.tb.yml +640 -0
  7. data/Gemfile +4 -0
  8. data/Gemfile.lock +162 -0
  9. data/Makefile +39 -0
  10. data/README.adoc +396 -59
  11. data/Rakefile +6 -0
  12. data/asciidoctor-iso.gemspec +11 -3
  13. data/lib/asciidoctor/iso/base.rb +122 -51
  14. data/lib/asciidoctor/iso/blocks.rb +119 -108
  15. data/lib/asciidoctor/iso/cleanup.rb +214 -0
  16. data/lib/asciidoctor/iso/cleanup_block.rb +157 -0
  17. data/lib/asciidoctor/iso/converter.rb +5 -3
  18. data/lib/asciidoctor/iso/front.rb +37 -28
  19. data/lib/asciidoctor/iso/html/header.html +184 -0
  20. data/lib/asciidoctor/iso/html/html_iso_intro.html +73 -0
  21. data/lib/asciidoctor/iso/html/html_iso_titlepage.html +31 -0
  22. data/lib/asciidoctor/iso/html/htmlstyle.css +67 -0
  23. data/lib/asciidoctor/iso/html/isodoc.css +679 -0
  24. data/lib/asciidoctor/iso/html/word_iso_intro.html +72 -0
  25. data/lib/asciidoctor/iso/html/word_iso_titlepage.html +58 -0
  26. data/lib/asciidoctor/iso/inline_anchor.rb +20 -26
  27. data/lib/asciidoctor/iso/isostandard.rnc +177 -0
  28. data/lib/asciidoctor/iso/isostandard.rng +1478 -0
  29. data/lib/asciidoctor/iso/isostandard_diff.rnc +295 -0
  30. data/lib/asciidoctor/iso/lists.rb +152 -109
  31. data/lib/asciidoctor/iso/section.rb +164 -0
  32. data/lib/asciidoctor/iso/table.rb +30 -27
  33. data/lib/asciidoctor/iso/utils.rb +61 -183
  34. data/lib/asciidoctor/iso/validate.make.sh +8 -0
  35. data/lib/asciidoctor/iso/validate.rb +195 -24
  36. data/lib/asciidoctor/iso/validate_style.rb +175 -0
  37. data/lib/asciidoctor/iso/version.rb +1 -1
  38. data/spec/examples/rice.adoc +45 -24
  39. data/spec/examples/rice.doc +17708 -0
  40. data/spec/examples/rice.html +1574 -1662
  41. data/spec/examples/rice.preview.html +1811 -0
  42. data/spec/examples/rice.sh +4 -0
  43. data/spec/examples/rice.xml +888 -62
  44. data/spec/examples/rice_images/rice_image1.png +0 -0
  45. data/spec/examples/rice_images/rice_image2.png +0 -0
  46. data/spec/examples/rice_images/rice_image3_1.png +0 -0
  47. data/spec/examples/rice_images/rice_image3_2.png +0 -0
  48. data/spec/examples/rice_images/rice_image3_3.png +0 -0
  49. metadata +135 -12
  50. data/grammar1.gif +0 -0
  51. data/grammar2.gif +0 -0
  52. data/grammar3.gif +0 -0
  53. data/grammar4.gif +0 -0
  54. data/lib/asciidoctor/iso/validate.rnc +0 -444
  55. data/lib/asciidoctor/iso/validate.rng +0 -1001
@@ -0,0 +1,295 @@
1
+ default namespace = "http://riboseinc.com/isoxml"
2
+
3
+ # grammar {
4
+
5
+ start = iso-standard
6
+
7
+ iso-standard =
8
+ element iso-standard {
9
+ title+,
10
+ status,
11
+ creator,
12
+ language,
13
+ script,
14
+ type,
15
+ id,
16
+ version?,
17
+ copyright,
18
+ sections
19
+ }
20
+
21
+ language =
22
+ element language { ( "en" | "fr" ) }
23
+
24
+ script =
25
+ element script { "latn" }
26
+
27
+ # draft into isodoc? To replace version/version?
28
+ version =
29
+ element version {
30
+ edition?,
31
+ revision-date?,
32
+ draft?
33
+ }
34
+
35
+ draft = element draft {text}
36
+
37
+ copyright =
38
+ element copyright {
39
+ from, owner
40
+ }
41
+
42
+ owner =
43
+ element owner {
44
+ owner-affiliation
45
+ }
46
+
47
+ owner-affiliation = element affiliation { "ISO" }
48
+
49
+ id =
50
+ element id {
51
+ documentnumber,
52
+ tc-documentnumber?
53
+ }
54
+
55
+ creator =
56
+ element creator {
57
+ attribute role { text },
58
+ technical-committee,
59
+ subcommittee?,
60
+ workgroup?,
61
+ secretariat?
62
+ }
63
+
64
+ type =
65
+ element type {
66
+ ( "international-standard" | "technical-specification" |
67
+ "technical-report" | "publicly-available-specification" |
68
+ "international-workshop-agreement" | "guide" )
69
+ }
70
+
71
+ status =
72
+ element status {
73
+ stage,
74
+ substage?
75
+ }
76
+
77
+ stage =
78
+ element stage {
79
+ ("00" | "10" | "20" | "30" | "40" | "50" | "60" | "90" | "95" )
80
+ }
81
+
82
+ substage =
83
+ element substage {
84
+ ("00" | "20" | "60" | "90" | "92" | "93" | "98" | "99" )
85
+ }
86
+
87
+ documentnumber =
88
+ element project-number {
89
+ attribute part { xsd:int }?,
90
+ xsd:int
91
+ }
92
+
93
+ tc-documentnumber =
94
+ element tc-document-number {
95
+ xsd:int
96
+ }
97
+
98
+ technical-committee =
99
+ element technical-committee {
100
+ attribute number { xsd:int }?,
101
+ text
102
+ }
103
+
104
+ subcommittee =
105
+ element subcommittee {
106
+ attribute number { xsd:int }?,
107
+ text
108
+ }
109
+
110
+ workgroup =
111
+ element workgroup {
112
+ attribute number { xsd:int }?,
113
+ text
114
+ }
115
+
116
+ secretariat =
117
+ element secretariat { text }
118
+
119
+ title =
120
+ element title {
121
+ attribute language { text },
122
+ title-intro?, title-main, title-part?
123
+ }
124
+
125
+ title-intro =
126
+ element title-intro { text }
127
+
128
+ title-main =
129
+ element title-main { text }
130
+
131
+ title-part =
132
+ element title-part { text }
133
+
134
+ sections =
135
+ element sections {
136
+ content, content?,
137
+ clause, references, terms, clause+,
138
+ annex*, references?
139
+ }
140
+
141
+ references =
142
+ element references {
143
+ attribute id { xsd:ID }?,
144
+ section-title?,
145
+ bibitem*,
146
+ references*
147
+ }
148
+
149
+ terms =
150
+ element terms {
151
+ attribute id { xsd:ID }?,
152
+ section-title?,
153
+ # boilerplate
154
+ paragraph-with-footnote*, ul?,
155
+ (term+ | terms? )
156
+ }
157
+
158
+ term =
159
+ element term {
160
+ attribute id { xsd:ID }?,
161
+ preferred, admitted*, deprecates*,
162
+ termdomain?, definition, termnote*, termexample*, termsource*
163
+ }
164
+
165
+ definition =
166
+ element definition {
167
+ ( paragraph | figure | formula )+
168
+ }
169
+
170
+ origin =
171
+ element origin {
172
+ attribute citeas { text },
173
+ CitationType
174
+ }
175
+
176
+ clause-hanging-paragraph-with-footnote =
177
+ element subsection {
178
+ attribute id { xsd:ID }?,
179
+ attribute inline-header { xsd:boolean } ? ,
180
+ section-title?,
181
+ # allow hanging paragraphs in annexes: they introduce lists
182
+ BasicBlock*,
183
+ clause-hanging-paragraph-with-footnote*
184
+ }
185
+
186
+ annex =
187
+ element annex {
188
+ attribute id { xsd:ID }?,
189
+ attribute inline-header { xsd:boolean }?,
190
+ attribute subtype { "normative" | "informative" }?,
191
+ section-title?,
192
+ # allow hanging paragraps in annexes: they introduce lists
193
+ #( paragraph-with-footnote | table | note | formula | admonition | ol | ul | dl | figure | quote | sourcecode | review | example )*,
194
+ BasicBlock*,
195
+ clause-hanging-paragraph-with-footnote*
196
+ }
197
+
198
+ figure =
199
+ element figure {
200
+ attribute id { xsd:ID },
201
+ tname?,
202
+ ( image | figure+ ),
203
+ fn*,
204
+ dl?,
205
+ note*
206
+ }
207
+
208
+ li =
209
+ element li {
210
+ #( paragraph-with-footnote | table | note | formula | admonition | ol | ul | dl | quote | sourcecode | review | example )+
211
+ BasicBlock+
212
+ # exclude figures?
213
+ }
214
+
215
+ dd =
216
+ element dd {
217
+ #( paragraph-with-footnote | table | note | formula | admonition | ol | ul | dl | quote | sourcecode | review | example )*
218
+ # exclude figures?
219
+ BasicBlock
220
+ }
221
+
222
+ admonition =
223
+ element admonition {
224
+ attribute id { xsd:ID },
225
+ attribute type {
226
+ ( "danger" | "caution" | "warning" | "important" | "safety precautions" )},
227
+ paragraph-with-footnote+
228
+ }
229
+
230
+ xref =
231
+ element xref {
232
+ attribute target { xsd:IDREF },
233
+ text
234
+ }
235
+
236
+ hyperlink =
237
+ element link {
238
+ attribute target {xsd:anyURI},
239
+ text
240
+ }
241
+
242
+ thead =
243
+ element thead { tr+ }
244
+
245
+ td =
246
+ element td {
247
+ attribute colspan { text }?,
248
+ attribute rowspan { text }?,
249
+ attribute align { "left" | "right" | "center" }?,
250
+ (
251
+ (TextElement | fn | review )* |
252
+ paragraph-with-footnote+
253
+ )
254
+ }
255
+
256
+ th =
257
+ element th {
258
+ attribute colspan { text }?,
259
+ attribute rowspan { text }?,
260
+ attribute align { "left" | "right" | "center" }?,
261
+ (
262
+ (TextElement | fn | review )* |
263
+ paragraph-with-footnote+
264
+ )
265
+ }
266
+
267
+ table-note = element note {
268
+ attribute id { xsd:ID }?,
269
+ paragraph
270
+ }
271
+
272
+
273
+ Clause-Section =
274
+ attribute id { xsd:ID }?,
275
+ attribute inline-header { xsd:boolean }?,
276
+ section-title?,
277
+ (
278
+ BasicBlock+ |
279
+ clause-subsection+
280
+ )
281
+
282
+
283
+ BibliographicItem =
284
+ attribute id { xsd:ID },
285
+ attribute type { "article" | "book" | "booklet" | "conference" | "manual" |
286
+ "proceedings" | "presentation" | "thesis" | "techreport" |
287
+ "standard" | "unpublished" }?,
288
+ (bname | formatted), source?, publishdate?, docidentifier*, accesseddate?, creator*,
289
+ publisher*, edition?,
290
+ biblionote*, partof*, creationdate?, language*, script*, abstract?
291
+
292
+
293
+ # }
294
+
295
+
@@ -2,156 +2,199 @@ require "pp"
2
2
  module Asciidoctor
3
3
  module ISO
4
4
  module Lists
5
+ def li(xml_ul, item)
6
+ xml_ul.li do |xml_li|
7
+ style(item, item.text)
8
+ if item.blocks?
9
+ xml_li.p **id_attr(item) do |t|
10
+ t << item.text
11
+ end
12
+ xml_li << item.content
13
+ else
14
+ xml_li.p **id_attr(item) do |p|
15
+ p << item.text
16
+ end
17
+ end
18
+ end
19
+ end
20
+
5
21
  def ulist(node)
6
- return norm_ref(node) if $norm_ref
7
- return biblio_ref(node) if $biblio
22
+ return reference(node, true) if in_norm_ref
23
+ return reference(node, false) if in_biblio
8
24
  noko do |xml|
9
- xml.ul **attr_code(anchor: node.id) do |xml_ul|
25
+ xml.ul **id_attr(node) do |xml_ul|
10
26
  node.items.each do |item|
11
- xml_ul.li **attr_code(anchor: item.id) do |xml_li|
12
- if item.blocks?
13
- xml_li.p { |t| t << item.text }
14
- xml_li << item.content
15
- else
16
- xml_li.p { |p| p << item.text }
17
- end
18
- end
27
+ li(xml_ul, item)
19
28
  end
20
29
  end
21
- end.join
30
+ end.join("\n")
31
+ end
32
+
33
+ def iso_publisher(t)
34
+ t.publisher **{ role: "publisher" } do |p|
35
+ p.affiliation do |aff|
36
+ aff.name "ISO"
37
+ end
38
+ end
22
39
  end
23
40
 
24
41
  def isorefmatches(xml, matched)
25
- ref_attributes = {
26
- anchor: matched[:anchor],
27
- }
28
- xml.iso_ref_title **attr_code(ref_attributes) do |t|
29
- t.isocode matched[:code]
30
- t.isodate matched[:year] if matched[:year]
31
- t.isotitle { |i| i << ref_normalise(matched[:text]) }
42
+ ref_attributes = { id: matched[:anchor], type: "standard" }
43
+ xml.bibitem **attr_code(ref_attributes) do |t|
44
+ t.name { |i| i << ref_normalise(matched[:text]) }
45
+ t.publishDate matched[:year] if matched[:year]
46
+ t.docidentifier matched[:code]
47
+ iso_publisher(t)
32
48
  end
33
49
  end
34
50
 
35
- def isorefmatches2(xml, matched2)
36
- ref_attributes = {
37
- anchor: matched2[:anchor],
38
- }
39
- xml.iso_ref_title **attr_code(ref_attributes) do |t|
40
- t.isocode matched2[:code]
41
- t.isodate "--"
42
- t.date_footnote matched2[:fn]
43
- t.isotitle { |i| i << ref_normalise(matched2[:text]) }
51
+ def isorefmatches2(xml, matched)
52
+ ref_attributes = { id: matched[:anchor], type: "standard" }
53
+ xml.bibitem **attr_code(ref_attributes) do |t|
54
+ t.name { |i| i << ref_normalise(matched[:text]) }
55
+ t.publishDate "--"
56
+ t.docidentifier matched[:code]
57
+ iso_publisher(t)
58
+ t.note { |p| p << "ISO DATE: #{matched[:fn]}" }
59
+ end
60
+ end
61
+
62
+ def isorefmatches3(xml, matched)
63
+ ref_attributes = { id: matched[:anchor], type: "standard" }
64
+ xml.bibitem **attr_code(ref_attributes) do |t|
65
+ t.name { |i| i << ref_normalise(matched[:text]) }
66
+ t.publishDate matched[:year] if matched[:year]
67
+ t.docidentifier "#{matched[:code]}:All Parts"
68
+ iso_publisher(t)
69
+ end
70
+ end
71
+
72
+ def refitem(xml, item, node)
73
+ m = NON_ISO_REF.match item
74
+ if m.nil? then Utils::warning(node, "no anchor on reference", item)
75
+ else
76
+ xml.bibitem **attr_code(id: m[:anchor]) do |t|
77
+ t.formatted { |i| i << ref_normalise_no_format(m[:text]) }
78
+ code = m[:code]
79
+ code = "[#{code}]" if /^\d+$?/.match? code
80
+ t.docidentifier code
81
+ end
44
82
  end
45
83
  end
46
84
 
47
85
  def ref_normalise(ref)
48
- ref.gsub(/&#8201;&#8212;&#8201;/, " -- ").
86
+ ref.
87
+ # gsub(/&#8201;&#8212;&#8201;/, " -- ").
88
+ gsub(/&amp;amp;/, "&amp;").
89
+ gsub(%r{^<em>(.*)</em>}, "\\1")
90
+ end
91
+
92
+ def ref_normalise_no_format(ref)
93
+ ref.
94
+ # gsub(/&#8201;&#8212;&#8201;/, " -- ").
49
95
  gsub(/&amp;amp;/, "&amp;")
50
96
  end
51
97
 
52
- def norm_ref(node)
53
- noko do |xml|
54
- node.items.each do |item|
55
- matched = %r{^<ref\sanchor="(?<anchor>[^"]+)">
56
- \[ISO\s(?<code>[0-9-]+)(:(?<year>[0-9]+))?\]</ref>,?\s
57
- (?<text>.*)$}x.match item.text
58
- matched2 = %r{^<ref\sanchor="(?<anchor>[^"]+)">
59
- \[ISO\s(?<code>[0-9-]+):--\]</ref>,?\s?
60
- <fn>(?<fn>[^\]]+)</fn>,?\s?(?<text>.*)$}x.match item.text
61
- if matched2.nil?
62
- if matched.nil?
63
- warn %(asciidoctor: WARNING (#{current_location(node)}): normative reference not in expected format: #{item.text})
64
- else
65
- isorefmatches(xml, matched)
66
- end
67
- else
68
- isorefmatches2(xml, matched2)
69
- end
70
- end
71
- end.join
98
+ ISO_REF = %r{^<ref\sid="(?<anchor>[^"]+)">
99
+ \[ISO\s(?<code>[0-9-]+)(:(?<year>[0-9]+))?\]</ref>,?\s
100
+ (?<text>.*)$}xm
101
+
102
+ ISO_REF_NO_YEAR = %r{^<ref\sid="(?<anchor>[^"]+)">
103
+ \[ISO\s(?<code>[0-9-]+):--\]</ref>,?\s?
104
+ <fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>,?\s?(?<text>.*)$}xm
105
+
106
+ ISO_REF_ALL_PARTS = %r{^<ref\sid="(?<anchor>[^"]+)">
107
+ \[ISO\s(?<code>[0-9]+)\s\(all\sparts\)\]</ref>(<p>)?,?\s?
108
+ (?<text>.*)(</p>)?$}xm
109
+
110
+ NON_ISO_REF = %r{^<ref\sid="(?<anchor>[^"]+)">
111
+ \[(?<code>[^\]]+)\]</ref>,?\s
112
+ (?<text>.*)$}xm
113
+
114
+ def reference1(node, item, xml, normative)
115
+ matched = ISO_REF.match item
116
+ matched2 = ISO_REF_NO_YEAR.match item
117
+ matched3 = ISO_REF_ALL_PARTS.match item
118
+ if matched3.nil? && matched2.nil? && matched.nil?
119
+ refitem(xml, item, node)
120
+ elsif !matched.nil? then isorefmatches(xml, matched)
121
+ elsif !matched2.nil? then isorefmatches2(xml, matched2)
122
+ elsif !matched3.nil? then isorefmatches3(xml, matched3)
123
+ end
124
+ if matched3.nil? && matched2.nil? && matched.nil? && normative
125
+ Utils::warning(node,
126
+ "non-ISO/IEC reference not expected as normative",
127
+ item)
128
+ end
72
129
  end
73
130
 
74
- def biblio_ref(node)
131
+ def reference(node, normative)
75
132
  noko do |xml|
76
133
  node.items.each do |item|
77
- matched = %r{^<ref\sanchor="(?<anchor>[^"]+)">
78
- \[ISO\s(?<code>[0-9-]+)(:(?<year>[0-9]+))?\]</ref>,?\s
79
- (?<text>.*)$}.match item.text
80
- matched2 = %r{^<ref\sanchor="(?<anchor>[^"]+)">
81
- \[ISO\s(?<code>[0-9-]+):--\]</ref>,?\s?
82
- <fn>(?<fn>[^\]]+)</fn>,?\s?(?<text>.*)$}.match item.text
83
- if matched2.nil?
84
- if matched.nil?
85
- xml.reference do |t|
86
- t.p { |p| p << ref_normalise(item.text) }
87
- end
88
- else
89
- isorefmatches(xml, matched)
90
- end
91
- else
92
- isorefmatches2(xml, matched2)
93
- end
134
+ reference1(node, item.text, xml, normative)
94
135
  end
95
- end.join
136
+ end.join("\n")
137
+ end
138
+
139
+ def olist_style(style)
140
+ return "alphabet" if style == "loweralpha"
141
+ return "roman" if style == "lowerroman"
142
+ return "roman_upper" if style == "upperroman"
143
+ return "alphabet_upper" if style == "upperalpha"
144
+ return style
96
145
  end
97
146
 
98
147
  def olist(node)
99
148
  noko do |xml|
100
- xml.ol **attr_code(anchor: node.id, type: node.style) do |xml_ol|
101
- node.items.each do |item|
102
- xml_ol.li **attr_code(anchor: item.id) do |xml_li|
103
- if item.blocks?
104
- xml_li.p { |t| t << item.text }
105
- xml_li << item.content
106
- else
107
- xml_li.p { |p| p << item.text }
108
- end
109
- end
110
- end
149
+ xml.ol **attr_code(id: Utils::anchor_or_uuid(node),
150
+ type: olist_style(node.style)) do |xml_ol|
151
+ node.items.each { |item| li(xml_ol, item) }
152
+ end
153
+ end.join("\n")
154
+ end
155
+
156
+ def dt(terms, xml_dl)
157
+ terms.each_with_index do |dt, idx|
158
+ style(dt, dt.text)
159
+ xml_dl.dt { |xml_dt| xml_dt << dt.text }
160
+ if idx < terms.size - 1
161
+ xml_dl.dd
111
162
  end
112
- end.join
163
+ end
164
+ end
165
+
166
+ def dd(dd, xml_dl)
167
+ if dd.nil?
168
+ xml_dl.dd
169
+ return
170
+ end
171
+ xml_dl.dd do |xml_dd|
172
+ style(dd, dd.text)
173
+ xml_dd.p { |t| t << dd.text } if dd.text?
174
+ xml_dd << dd.content if dd.blocks?
175
+ end
113
176
  end
114
177
 
115
178
  def dlist(node)
116
179
  noko do |xml|
117
- xml.dl **attr_code(anchor: node.id) do |xml_dl|
180
+ xml.dl **id_attr(node) do |xml_dl|
118
181
  node.items.each do |terms, dd|
119
- terms.each_with_index do |dt, idx|
120
- xml_dl.dt { |xml_dt| xml_dt << dt.text }
121
- if idx < terms.size - 1
122
- xml_dl.dd
123
- end
124
- end
125
-
126
- if dd.nil?
127
- xml_dl.dd
128
- else
129
- xml_dl.dd do |xml_dd|
130
- if dd.blocks?
131
- if dd.text?
132
- xml_dd.p { |t| t << dd.text }
133
- end
134
- xml_dd << dd.content
135
- else
136
- xml_dd.p { |t| t << dd.text }
137
- end
138
- end
139
- end
182
+ dt(terms, xml_dl)
183
+ dd(dd, xml_dl)
140
184
  end
141
185
  end
142
- end.join
186
+ end.join("\n")
143
187
  end
144
188
 
145
189
  def colist(node)
146
190
  noko do |xml|
147
- xml.colist **attr_code(anchor: node.id) do |xml_ul|
148
- node.items.each_with_index do |item, i|
149
- xml_ul.annotation **attr_code(id: i + 1) do |xml_li|
150
- xml_li << item.text
151
- end
191
+ node.items.each_with_index do |item, i|
192
+ xml_ul.annotation **attr_code(id: i + 1) do |xml_li|
193
+ style(item, item.text)
194
+ xml_li.p { |p| p << item.text }
152
195
  end
153
196
  end
154
- end.join
197
+ end.join("\n")
155
198
  end
156
199
  end
157
200
  end