asciidoctor-iso 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +12 -10
  3. data/asciidoctor-iso.gemspec +1 -1
  4. data/lib/asciidoctor/iso/base.rb +6 -3
  5. data/lib/asciidoctor/iso/blocks.rb +4 -18
  6. data/lib/asciidoctor/iso/cleanup.rb +20 -11
  7. data/lib/asciidoctor/iso/cleanup_block.rb +38 -21
  8. data/lib/asciidoctor/iso/cleanup_ref.rb +17 -4
  9. data/lib/asciidoctor/iso/converter.rb +0 -1
  10. data/lib/asciidoctor/iso/front.rb +23 -14
  11. data/lib/asciidoctor/iso/html/html_iso_intro.html +0 -36
  12. data/lib/asciidoctor/iso/html/isodoc.css +5 -0
  13. data/lib/asciidoctor/iso/inline.rb +14 -2
  14. data/lib/asciidoctor/iso/isodoc.rng +38 -6
  15. data/lib/asciidoctor/iso/isostandard.rng +16 -11
  16. data/lib/asciidoctor/iso/lists.rb +28 -23
  17. data/lib/asciidoctor/iso/section.rb +4 -14
  18. data/lib/asciidoctor/iso/table.rb +0 -3
  19. data/lib/asciidoctor/iso/utils.rb +2 -0
  20. data/lib/asciidoctor/iso/validate.rb +2 -2
  21. data/lib/asciidoctor/iso/validate_section.rb +62 -4
  22. data/lib/asciidoctor/iso/validate_style.rb +24 -15
  23. data/lib/asciidoctor/iso/version.rb +1 -1
  24. data/spec/asciidoctor-iso/base_spec.rb +32 -6
  25. data/spec/asciidoctor-iso/blocks_spec.rb +10 -0
  26. data/spec/asciidoctor-iso/cleanup_spec.rb +26 -18
  27. data/spec/asciidoctor-iso/inline_spec.rb +2 -0
  28. data/spec/asciidoctor-iso/lists_spec.rb +1 -0
  29. data/spec/asciidoctor-iso/refs_spec.rb +44 -11
  30. data/spec/asciidoctor-iso/validate_spec.rb +1 -0
  31. data/spec/examples/rice.doc +2751 -2732
  32. data/spec/examples/rice.html +184 -205
  33. data/spec/examples/rice.xml +244 -212
  34. data/spec/spec_helper.rb +6 -3
  35. metadata +6 -6
@@ -41,7 +41,6 @@ module Asciidoctor
41
41
  outfilesuffix ".xml"
42
42
  end
43
43
 
44
- # alias_method :pass, :content
45
44
  alias_method :embedded, :content
46
45
  alias_method :verse, :quote
47
46
  alias_method :audio, :skip
@@ -34,11 +34,22 @@ module Asciidoctor
34
34
  type: node.attr("#{compname}-type"))
35
35
  end
36
36
 
37
- def metadata_author(_node, xml)
38
- xml.contributor do |c|
39
- c.role **{ type: "author" }
40
- c.organization do |a|
41
- a.name "ISO"
37
+ def organization(org, orgname)
38
+ if ["ISO",
39
+ "International Organization for Standardization"].include? orgname
40
+ org.name "International Organization for Standardization"
41
+ org.abbreviation "ISO"
42
+ else
43
+ org.name orgname
44
+ end
45
+ end
46
+
47
+ def metadata_author(node, xml)
48
+ publishers = node.attr("publisher") || "ISO"
49
+ publishers.split(/,[ ]?/).each do |p|
50
+ xml.contributor do |c|
51
+ c.role **{ type: "author" }
52
+ c.organization { |a| organization(a, p) }
42
53
  end
43
54
  end
44
55
  end
@@ -48,20 +59,18 @@ module Asciidoctor
48
59
  publishers.split(/,[ ]?/).each do |p|
49
60
  xml.contributor do |c|
50
61
  c.role **{ type: "publisher" }
51
- c.organization do |a|
52
- a.name p
53
- end
62
+ c.organization { |a| organization(a, p) }
54
63
  end
55
64
  end
56
65
  end
57
66
 
58
67
  def metadata_copyright(node, xml)
59
- from = node.attr("copyright-year") || Date.today.year
60
- xml.copyright do |c|
61
- c.from from
62
- c.owner do |owner|
63
- owner.organization do |o|
64
- o.name "ISO"
68
+ publishers = node.attr("publisher") || "ISO"
69
+ publishers.split(/,[ ]?/).each do |p|
70
+ xml.copyright do |c|
71
+ c.from (node.attr("copyright-year") || Date.today.year)
72
+ c.owner do |owner|
73
+ owner.organization { |o| organization(o, p) }
65
74
  end
66
75
  end
67
76
  end
@@ -35,39 +35,3 @@ at the address below or ISO’s member body in the country of the requester.
35
35
 
36
36
  <div class="rule"></div>
37
37
 
38
- <script type="text/javascript"
39
- src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
40
- </script>
41
-
42
- <script>
43
- // http://tutorials.jenkov.com/jquery/generating-table-of-contents.html
44
- $(document).ready(function() {
45
- $("#toc-list").empty();
46
-
47
- var prevH2Item = null;
48
- var prevH2List = null;
49
-
50
- var index = 0;
51
- $("h1, h2").each(function() {
52
-
53
- if ($(this).hasClass("toc-contents")) {
54
- return;
55
- }
56
- //insert an anchor to jump to, from the TOC link.
57
- var anchor = "<a name='" + index + "'></a>";
58
- $(this).before(anchor);
59
-
60
- var li = "<li><a href='#" + index + "'>" + $(this).text() + "</a></li>";
61
-
62
- if ($(this).is("h1") ){
63
- prevH2List = $("<ul></ul>");
64
- prevH2Item = $(li);
65
- prevH2Item.append(prevH2List);
66
- prevH2Item.appendTo("#toc-list");
67
- } else {
68
- prevH2List.append(li);
69
- }
70
- index++;
71
- });
72
- });
73
- </script>
@@ -431,6 +431,11 @@ p.Formula, li.Formula, div.Formula
431
431
  mso-fareast-font-family:"Cambria";
432
432
  mso-bidi-font-family:"Cambria";
433
433
  mso-ansi-language:EN-GB;}
434
+ table.dl
435
+ {margin-top:0cm;
436
+ margin-right:0cm;
437
+ margin-bottom:11.0pt;
438
+ margin-left:20.15pt;}
434
439
  .h2Annex
435
440
  {mso-style-priority:2;
436
441
  mso-style-unhide:no;
@@ -1,4 +1,5 @@
1
1
  require "asciidoctor/extensions"
2
+ require "HTMLEntities"
2
3
 
3
4
  module Asciidoctor
4
5
  module ISO
@@ -65,7 +66,6 @@ module Asciidoctor
65
66
  @fn_number += 1
66
67
  xml.fn **{ reference: @fn_number } do |fn|
67
68
  fn.p { |p| p << node.text }
68
- footnote_style(node, node.text)
69
69
  end
70
70
  end.join("\n")
71
71
  end
@@ -85,6 +85,18 @@ module Asciidoctor
85
85
  noko { |xml| xml.hr }.join("\n")
86
86
  end
87
87
 
88
+ def stem_parse(text, xml)
89
+ if /&lt;([^:>&]+:)?math(\s+[^>&]+)?&gt; |
90
+ <([^:>&]+:)?math(\s+[^>&]+)?>/x.match? text
91
+ math = HTMLEntities.new.encode(text, :basic, :hexadecimal).
92
+ gsub(/&amp;gt;/, ">").gsub(/\&amp;lt;/, "<").gsub(/&amp;amp;/, "&").
93
+ gsub(/&gt;/, ">").gsub(/&lt;/, "<").gsub(/&amp;/, "&")
94
+ xml.stem math, **{ type: "MathML" }
95
+ else
96
+ xml.stem text, **{ type: "AsciiMath" }
97
+ end
98
+ end
99
+
88
100
  def inline_quoted(node)
89
101
  noko do |xml|
90
102
  case node.type
@@ -95,7 +107,7 @@ module Asciidoctor
95
107
  when :single then xml << "'#{node.text}'"
96
108
  when :superscript then xml.sup node.text
97
109
  when :subscript then xml.sub node.text
98
- when :asciimath then xml.stem node.text, **{ type: "AsciiMath" }
110
+ when :asciimath then stem_parse(node.text, xml)
99
111
  else
100
112
  case node.role
101
113
  # the following three are legacy, they are now handled by macros
@@ -746,6 +746,11 @@
746
746
  <ref name="bookmark"/>
747
747
  </choice>
748
748
  </define>
749
+ <define name="source">
750
+ <element name="source">
751
+ <data type="anyURI"/>
752
+ </element>
753
+ </define>
749
754
  <define name="em">
750
755
  <element name="em">
751
756
  <text/>
@@ -1168,6 +1173,9 @@
1168
1173
  <define name="organization">
1169
1174
  <element name="organization">
1170
1175
  <ref name="orgname"/>
1176
+ <optional>
1177
+ <ref name="abbreviation"/>
1178
+ </optional>
1171
1179
  <optional>
1172
1180
  <ref name="uri"/>
1173
1181
  </optional>
@@ -1184,6 +1192,11 @@
1184
1192
  <ref name="LocalizedString"/>
1185
1193
  </element>
1186
1194
  </define>
1195
+ <define name="abbreviation">
1196
+ <element name="abbreviation">
1197
+ <ref name="LocalizedString"/>
1198
+ </element>
1199
+ </define>
1187
1200
  <define name="uri">
1188
1201
  <element name="uri">
1189
1202
  <data type="anyURI"/>
@@ -1470,14 +1483,17 @@
1470
1483
  <ref name="FormattedString"/>
1471
1484
  </element>
1472
1485
  </define>
1473
- <define name="source">
1474
- <element name="source">
1475
- <optional>
1476
- <attribute name="type"/>
1477
- </optional>
1478
- <data type="anyURI"/>
1486
+ <define name="link">
1487
+ <element name="link">
1488
+ <ref name="TypedUri"/>
1479
1489
  </element>
1480
1490
  </define>
1491
+ <define name="TypedUri">
1492
+ <optional>
1493
+ <attribute name="type"/>
1494
+ </optional>
1495
+ <data type="anyURI"/>
1496
+ </define>
1481
1497
  <define name="bdate">
1482
1498
  <element name="date">
1483
1499
  <attribute name="type">
@@ -1489,6 +1505,22 @@
1489
1505
  <value>obsoleted</value>
1490
1506
  </choice>
1491
1507
  </attribute>
1508
+ <ref name="bfrom"/>
1509
+ <optional>
1510
+ <ref name="bto"/>
1511
+ </optional>
1512
+ </element>
1513
+ </define>
1514
+ <define name="bfrom">
1515
+ <element name="from">
1516
+ <choice>
1517
+ <data type="gYear"/>
1518
+ <data type="date"/>
1519
+ </choice>
1520
+ </element>
1521
+ </define>
1522
+ <define name="bto">
1523
+ <element name="to">
1492
1524
  <choice>
1493
1525
  <data type="gYear"/>
1494
1526
  <data type="date"/>
@@ -48,6 +48,9 @@
48
48
  <define name="organization">
49
49
  <element name="organization">
50
50
  <ref name="orgname"/>
51
+ <optional>
52
+ <ref name="abbreviation"/>
53
+ </optional>
51
54
  <optional>
52
55
  <ref name="uri"/>
53
56
  </optional>
@@ -125,6 +128,9 @@
125
128
  <optional>
126
129
  <ref name="editorialgroup"/>
127
130
  </optional>
131
+ <optional>
132
+ <ref name="ics"/>
133
+ </optional>
128
134
  </define>
129
135
  <define name="BibData">
130
136
  <optional>
@@ -176,18 +182,12 @@
176
182
  <ref name="docrelation"/>
177
183
  </zeroOrMore>
178
184
  <ref name="editorialgroup"/>
185
+ <optional>
186
+ <ref name="ics"/>
187
+ </optional>
179
188
  </define>
180
- <define name="bdate">
181
- <element name="date">
182
- <attribute name="type">
183
- <choice>
184
- <value>published</value>
185
- <value>accessed</value>
186
- <value>created</value>
187
- <value>activated</value>
188
- <value>obsoleted</value>
189
- </choice>
190
- </attribute>
189
+ <define name="bfrom">
190
+ <element name="from">
191
191
  <choice>
192
192
  <data type="gYear"/>
193
193
  <data type="date"/>
@@ -842,4 +842,9 @@
842
842
  <ref name="erefType"/>
843
843
  </element>
844
844
  </define>
845
+ <define name="ics">
846
+ <element name="ics">
847
+ <text/>
848
+ </element>
849
+ </define>
845
850
  </grammar>
@@ -4,7 +4,6 @@ module Asciidoctor
4
4
  module Lists
5
5
  def li(xml_ul, item)
6
6
  xml_ul.li do |xml_li|
7
- style(item, item.text)
8
7
  if item.blocks?
9
8
  xml_li.p(**id_attr(item)) { |t| t << item.text }
10
9
  xml_li << item.content
@@ -15,8 +14,7 @@ module Asciidoctor
15
14
  end
16
15
 
17
16
  def ulist(node)
18
- return reference(node, true) if in_norm_ref
19
- return reference(node, false) if in_biblio
17
+ return reference(node) if in_norm_ref? || in_biblio?
20
18
  noko do |xml|
21
19
  xml.ul **id_attr(node) do |xml_ul|
22
20
  node.items.each do |item|
@@ -27,10 +25,12 @@ module Asciidoctor
27
25
  end
28
26
 
29
27
  def iso_publisher(t, code)
30
- t.contributor do |c|
31
- c.role **{ type: "publisher" }
32
- c.organization do |aff|
33
- aff.name code.gsub(%r{[/ \t].*$}, "")
28
+ code.sub(/ .*$/, "").split(/\//).each do |abbrev|
29
+ t.contributor do |c|
30
+ c.role **{ type: "publisher" }
31
+ c.organization do |org|
32
+ organization(org, abbrev)
33
+ end
34
34
  end
35
35
  end
36
36
  end
@@ -43,11 +43,20 @@ module Asciidoctor
43
43
  { id: m[:anchor], type: "standard" }
44
44
  end
45
45
 
46
+ def set_date_range(date, text)
47
+ matched = /^(?<from>[0-9]+)(-+(?<to>[0-9]+))?$/.match text
48
+ return unless matched[:from]
49
+ date.from matched[:from]
50
+ date.to matched[:to] if matched[:to]
51
+ end
52
+
46
53
  def isorefmatches(xml, m)
47
54
  xml.bibitem **attr_code(ref_attributes(m)) do |t|
48
55
  t.title(**plaintxt) { |i| i << ref_normalise(m[:text]) }
49
56
  t.docidentifier m[:code]
50
- t.date(m[:year], type: "published") if m[:year]
57
+ m[:year] and t.date **{ type: "published" } do |d|
58
+ set_date_range(d, m[:year])
59
+ end
51
60
  iso_publisher(t, m[:code])
52
61
  end
53
62
  end
@@ -56,7 +65,9 @@ module Asciidoctor
56
65
  xml.bibitem **attr_code(ref_attributes(m)) do |t|
57
66
  t.title(**plaintxt) { |i| i << ref_normalise(m[:text]) }
58
67
  t.docidentifier m[:code]
59
- t.date "--", type: "published"
68
+ t.date **{ type: "published" } do |d|
69
+ d.from "--"
70
+ end
60
71
  iso_publisher(t, m[:code])
61
72
  t.note(**plaintxt) { |p| p << "ISO DATE: #{m[:fn]}" }
62
73
  end
@@ -66,7 +77,9 @@ module Asciidoctor
66
77
  xml.bibitem **attr_code(ref_attributes(m)) do |t|
67
78
  t.title(**plaintxt) { |i| i << ref_normalise(m[:text]) }
68
79
  t.docidentifier "#{m[:code]}:All Parts"
69
- t.date(m[:year], type: "published") if m[:year]
80
+ m[:year] and t.date **{ type: "published" } do |d|
81
+ set_date_range(d, m[:year])
82
+ end
70
83
  iso_publisher(t, m[:code])
71
84
  end
72
85
  end
@@ -99,7 +112,7 @@ module Asciidoctor
99
112
  end
100
113
 
101
114
  ISO_REF = %r{^<ref\sid="(?<anchor>[^"]+)">
102
- \[(?<code>(ISO|IEC)[^0-9]*\s[0-9-]+)(:(?<year>[0-9]+))?\]</ref>,?\s
115
+ \[(?<code>(ISO|IEC)[^0-9]*\s[0-9-]+)(:(?<year>[0-9][0-9-]+))?\]</ref>,?\s
103
116
  (?<text>.*)$}xm
104
117
 
105
118
  ISO_REF_NO_YEAR = %r{^<ref\sid="(?<anchor>[^"]+)">
@@ -107,7 +120,7 @@ module Asciidoctor
107
120
  <fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>,?\s?(?<text>.*)$}xm
108
121
 
109
122
  ISO_REF_ALL_PARTS = %r{^<ref\sid="(?<anchor>[^"]+)">
110
- \[(?<code>(ISO|IEC)[^0-9]*\s[0-9]+)(:(?<year>[0-9]+))?\s
123
+ \[(?<code>(ISO|IEC)[^0-9]*\s[0-9]+)(:(?<year>[0-9][0-9-]+))?\s
111
124
  \(all\sparts\)\]</ref>,?\s
112
125
  (?<text>.*)$}xm
113
126
 
@@ -115,8 +128,6 @@ module Asciidoctor
115
128
  \[(?<code>[^\]]+)\]</ref>,?\s
116
129
  (?<text>.*)$}xm
117
130
 
118
- NORM_ISO_WARN = "non-ISO/IEC reference not expected as normative".freeze
119
-
120
131
  def reference1_matches(item)
121
132
  matched = ISO_REF.match item
122
133
  matched2 = ISO_REF_NO_YEAR.match item
@@ -124,7 +135,7 @@ module Asciidoctor
124
135
  [matched, matched2, matched3]
125
136
  end
126
137
 
127
- def reference1(node, item, xml, normative)
138
+ def reference1(node, item, xml)
128
139
  matched, matched2, matched3 = reference1_matches(item)
129
140
  if matched3.nil? && matched2.nil? && matched.nil?
130
141
  refitem(xml, item, node)
@@ -132,15 +143,12 @@ module Asciidoctor
132
143
  elsif !matched2.nil? then isorefmatches2(xml, matched2)
133
144
  elsif !matched3.nil? then isorefmatches3(xml, matched3)
134
145
  end
135
- if matched3.nil? && matched2.nil? && matched.nil? && normative
136
- Utils::warning(node, NORM_ISO_WARN, item)
137
- end
138
146
  end
139
147
 
140
- def reference(node, normative)
148
+ def reference(node)
141
149
  noko do |xml|
142
150
  node.items.each do |item|
143
- reference1(node, item.text, xml, normative)
151
+ reference1(node, item.text, xml)
144
152
  end
145
153
  end.join("\n")
146
154
  end
@@ -164,7 +172,6 @@ module Asciidoctor
164
172
 
165
173
  def dt(terms, xml_dl)
166
174
  terms.each_with_index do |dt, idx|
167
- style(dt, dt.text)
168
175
  xml_dl.dt { |xml_dt| xml_dt << dt.text }
169
176
  if idx < terms.size - 1
170
177
  xml_dl.dd
@@ -178,7 +185,6 @@ module Asciidoctor
178
185
  return
179
186
  end
180
187
  xml_dl.dd do |xml_dd|
181
- style(dd, dd.text) if dd.text?
182
188
  xml_dd.p { |t| t << dd.text } if dd.text?
183
189
  xml_dd << dd.content if dd.blocks?
184
190
  end
@@ -199,7 +205,6 @@ module Asciidoctor
199
205
  noko do |xml|
200
206
  node.items.each_with_index do |item, i|
201
207
  xml.annotation **attr_code(id: i + 1) do |xml_li|
202
- style(item, item.text)
203
208
  xml_li.p { |p| p << item.text }
204
209
  end
205
210
  end
@@ -8,15 +8,15 @@ module Asciidoctor
8
8
  @term_def = false
9
9
  @norm_ref = false
10
10
 
11
- def in_biblio
11
+ def in_biblio?
12
12
  @biblio
13
13
  end
14
14
 
15
- def in_terms
15
+ def in_terms?
16
16
  @term_def
17
17
  end
18
18
 
19
- def in_norm_ref
19
+ def in_norm_ref?
20
20
  @norm_ref
21
21
  end
22
22
 
@@ -66,14 +66,11 @@ module Asciidoctor
66
66
  end
67
67
  end
68
68
 
69
- SCOPE_WARN = "Scope contains subsections: should be succint".freeze
70
-
71
69
  # Not testing max depth of sections: Asciidoctor already limits
72
70
  # it to 5 levels of nesting
73
71
  def clause_parse(attrs, xml, node)
74
72
  attrs["inline-header".to_sym] = node.option? "inline-header"
75
73
  set_obligation(attrs, node)
76
- style_warning(node, SCOPE_WARN, nil) if @scope
77
74
  sect = node.level == 1 ? "clause" : "subsection"
78
75
  xml.send sect, **attr_code(attrs) do |xml_section|
79
76
  xml_section.title { |n| n << node.title } unless node.title.nil?
@@ -106,8 +103,8 @@ module Asciidoctor
106
103
  end
107
104
  end
108
105
 
106
+ # subclause contains subclauses
109
107
  def term_def_subclause_parse(attrs, xml, node)
110
- # subclause contains subclauses
111
108
  sub = node.find_by(context: :section) { |s| s.level == node.level + 1 }
112
109
  sub.empty? || (return term_def_parse(attrs, xml, node, false))
113
110
  node.title.casecmp("symbols and abbreviated terms").zero? &&
@@ -151,9 +148,6 @@ module Asciidoctor
151
148
  xml_section.title = "Introduction"
152
149
  content = node.content
153
150
  xml_section << content
154
- introduction_style(node,
155
- Utils::flatten_rawtext(content).
156
- join("\n"))
157
151
  end
158
152
  end
159
153
 
@@ -165,15 +159,11 @@ module Asciidoctor
165
159
  end
166
160
 
167
161
  def scope_parse(attrs, xml, node)
168
- @scope = true
169
162
  xml.clause **attr_code(attrs) do |xml_section|
170
163
  xml_section.title { |t| t << "Scope" }
171
164
  content = node.content
172
165
  xml_section << content
173
- c = Utils::flatten_rawtext(content).join("\n")
174
- scope_style(node, c)
175
166
  end
176
- @scope = false
177
167
  end
178
168
  end
179
169
  end