asciidoctor-iso 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +2 -0
  3. data/.travis.yml +5 -0
  4. data/Gemfile.lock +12 -10
  5. data/README.adoc +113 -16
  6. data/bin/rspec +18 -0
  7. data/lib/asciidoctor/iso/base.rb +30 -28
  8. data/lib/asciidoctor/iso/blocks.rb +33 -33
  9. data/lib/asciidoctor/iso/cleanup.rb +79 -33
  10. data/lib/asciidoctor/iso/cleanup_block.rb +71 -18
  11. data/lib/asciidoctor/iso/cleanup_ref.rb +35 -30
  12. data/lib/asciidoctor/iso/converter.rb +0 -3
  13. data/lib/asciidoctor/iso/front.rb +29 -16
  14. data/lib/asciidoctor/iso/html/isodoc.css +34 -0
  15. data/lib/asciidoctor/iso/html/wordstyle.css +138 -6
  16. data/lib/asciidoctor/iso/inline.rb +10 -22
  17. data/lib/asciidoctor/iso/isodoc.rng +66 -16
  18. data/lib/asciidoctor/iso/isostandard.rng +129 -15
  19. data/lib/asciidoctor/iso/lists.rb +49 -42
  20. data/lib/asciidoctor/iso/macros.rb +12 -8
  21. data/lib/asciidoctor/iso/section.rb +53 -37
  22. data/lib/asciidoctor/iso/table.rb +9 -1
  23. data/lib/asciidoctor/iso/utils.rb +18 -13
  24. data/lib/asciidoctor/iso/validate.rb +100 -24
  25. data/lib/asciidoctor/iso/validate_requirements.rb +106 -0
  26. data/lib/asciidoctor/iso/validate_section.rb +85 -65
  27. data/lib/asciidoctor/iso/validate_style.rb +68 -115
  28. data/lib/asciidoctor/iso/version.rb +1 -1
  29. data/spec/asciidoctor-iso/base_spec.rb +193 -0
  30. data/spec/asciidoctor-iso/blocks_spec.rb +426 -0
  31. data/spec/asciidoctor-iso/cleanup_spec.rb +687 -0
  32. data/spec/asciidoctor-iso/inline_spec.rb +159 -0
  33. data/spec/asciidoctor-iso/lists_spec.rb +189 -0
  34. data/spec/asciidoctor-iso/macros_spec.rb +20 -0
  35. data/spec/asciidoctor-iso/refs_spec.rb +194 -0
  36. data/spec/asciidoctor-iso/section_spec.rb +301 -0
  37. data/spec/asciidoctor-iso/table_spec.rb +307 -0
  38. data/spec/asciidoctor-iso/validate_spec.rb +749 -0
  39. data/spec/examples/english.yaml +69 -0
  40. data/spec/examples/rice.adoc +30 -28
  41. data/spec/examples/rice.doc +3035 -2865
  42. data/spec/examples/rice.html +281 -234
  43. data/spec/examples/rice.preview.html +30 -20
  44. data/spec/examples/rice.xml +250 -282
  45. data/spec/spec_helper.rb +87 -0
  46. metadata +17 -2
@@ -4,28 +4,27 @@ require "uri"
4
4
  module Asciidoctor
5
5
  module ISO
6
6
  module Blocks
7
-
8
7
  def id_attr(node = nil)
9
8
  { id: Utils::anchor_or_uuid(node) }
10
9
  end
11
10
 
11
+ # open block is a container of multiple blocks,
12
+ # treated as a single block.
13
+ # We append each contained block to its parent
12
14
  def open(node)
13
- # open block is a container of multiple blocks,
14
- # treated as a single block.
15
- # We append each contained block to its parent
16
15
  result = []
17
- if node.blocks?
18
- node.blocks.each do |b|
19
- result << send(b.context, b)
20
- end
21
- else
22
- result = paragraph(node)
16
+ node.blocks.each do |b|
17
+ result << send(b.context, b)
23
18
  end
24
19
  result
25
20
  end
26
21
 
22
+ def literal(node)
23
+ open(node)
24
+ end
25
+
26
+ # NOTE: html escaping is performed by Nokogiri
27
27
  def stem(node)
28
- # NOTE: html escaping is performed by Nokogiri
29
28
  stem_content = node.lines.join("\n")
30
29
  noko do |xml|
31
30
  xml.formula **id_attr(node) do |s|
@@ -36,9 +35,9 @@ module Asciidoctor
36
35
  end
37
36
 
38
37
  def sidebar_attrs(node)
39
- date = node.attr("date") || DateTime.now.iso8601.gsub(/\+.*$/, "")
38
+ date = node.attr("date") || Date.today.iso8601.gsub(/\+.*$/, "")
40
39
  date += "T0000" unless /T/.match? date
41
- {
40
+ {
42
41
  reviewer: node.attr("reviewer") || node.attr("source") || "(Unknown)",
43
42
  id: Utils::anchor_or_uuid(node),
44
43
  date: date.gsub(/[:-]/, ""),
@@ -48,9 +47,8 @@ module Asciidoctor
48
47
  end
49
48
 
50
49
  def sidebar(node)
51
- return unless is_draft
52
- content = Utils::flatten_rawtext(node.content).join("\n")
53
- noko do |xml|
50
+ return unless draft?
51
+ noko do |xml|
54
52
  xml.review **attr_code(sidebar_attrs(node)) do |r|
55
53
  wrap_in_para(node, r)
56
54
  end
@@ -78,9 +76,10 @@ module Asciidoctor
78
76
 
79
77
  def admonition_attrs(node)
80
78
  name = node.attr("name")
81
- type = node.attr("type") and
79
+ if type = node.attr("type")
82
80
  ["danger", "safety precautions"].each do |t|
83
- name = t if type.casecmp(t).zero?
81
+ name = t if type.casecmp(t).zero?
82
+ end
84
83
  end
85
84
  { id: Utils::anchor_or_uuid(node), type: name }
86
85
  end
@@ -112,6 +111,8 @@ module Asciidoctor
112
111
  xml.example **id_attr(node) do |ex|
113
112
  content = node.content
114
113
  ex << content
114
+ text = Utils::flatten_rawtext(content).join("\n")
115
+ termexample_style(node, text)
115
116
  end
116
117
  end.join("\n")
117
118
  end
@@ -131,17 +132,25 @@ module Asciidoctor
131
132
  def image_attributes(node)
132
133
  uri = node.image_uri node.attr("target")
133
134
  types = MIME::Types.type_for(uri)
134
- { src: uri,
135
+ { src: uri,
135
136
  id: Utils::anchor_or_uuid,
136
137
  imagetype: types.first.sub_type.upcase,
137
138
  height: node.attr("height"),
138
139
  width: node.attr("width") }
139
140
  end
140
141
 
142
+ def figure_title(node, f)
143
+ if node.title.nil?
144
+ style_warning(node, "Figure should have title", nil)
145
+ else
146
+ f.name { |name| name << node.title }
147
+ end
148
+ end
149
+
141
150
  def image(node)
142
151
  noko do |xml|
143
152
  xml.figure **id_attr(node) do |f|
144
- f.name { |name| name << node.title } unless node.title.nil?
153
+ figure_title(node, f)
145
154
  f.image **attr_code(image_attributes(node))
146
155
  end
147
156
  end
@@ -165,8 +174,8 @@ module Asciidoctor
165
174
 
166
175
  def quote_attribution(node, out)
167
176
  if node.attr("citetitle")
168
- m = /^(?<cite>[^,]+)(,(?<text>.*$))?$/.match node.attr("citetitle")
169
- out.source m[:text],
177
+ m = /^(?<cite>[^,]+)(,(?<text>.*$))?$/m.match node.attr("citetitle")
178
+ out.source m[:text],
170
179
  **attr_code(target: m[:cite], type: "inline")
171
180
  end
172
181
  if node.attr("attribution")
@@ -186,17 +195,8 @@ module Asciidoctor
186
195
  def listing(node)
187
196
  # NOTE: html escaping is performed by Nokogiri
188
197
  noko do |xml|
189
- if node.parent.context != :example
190
- xml.example **id_attr(node) do |e|
191
- e.sourcecode **id_attr(node) do |s|
192
- s << node.content
193
- end
194
- end
195
- else
196
- xml.sourcecode **id_attr(node) do |s|
197
- s << node.content
198
- end
199
- end
198
+ xml.sourcecode(**id_attr(node)) { |s| s << node.content }
199
+ # xml.sourcecode(**id_attr(node)) { |s| s << node.lines.join("\n") }
200
200
  end
201
201
  end
202
202
  end
@@ -15,8 +15,8 @@ module Asciidoctor
15
15
 
16
16
  def cleanup(xmldoc)
17
17
  sections_cleanup(xmldoc)
18
+ obligations_cleanup(xmldoc)
18
19
  termdef_cleanup(xmldoc)
19
- isotitle_cleanup(xmldoc)
20
20
  table_cleanup(xmldoc)
21
21
  formula_cleanup(xmldoc)
22
22
  figure_cleanup(xmldoc)
@@ -25,59 +25,68 @@ module Asciidoctor
25
25
  normref_cleanup(xmldoc)
26
26
  reference_names(xmldoc)
27
27
  xref_cleanup(xmldoc)
28
+ bpart_cleanup(xmldoc)
28
29
  quotesource_cleanup(xmldoc)
29
30
  para_cleanup(xmldoc)
30
31
  callout_cleanup(xmldoc)
31
32
  origin_cleanup(xmldoc)
32
33
  element_name_cleanup(xmldoc)
33
34
  footnote_renumber(xmldoc)
35
+ empty_element_cleanup(xmldoc)
36
+ bookmark_cleanup(xmldoc)
34
37
  xmldoc
35
38
  end
36
39
 
40
+ TEXT_ELEMS =
41
+ %w{status language script version author name callout phone
42
+ email street city state country postcode identifier referenceFrom
43
+ referenceTo docidentifier prefix initial addition surname forename
44
+ title draft secretariat title-main title-intro title-part}.freeze
45
+
46
+ def empty_element_cleanup(xmldoc)
47
+ xmldoc.xpath("//" + TEXT_ELEMS.join(" | //")).each do |x|
48
+ x.remove if x.children.empty?
49
+ end
50
+ end
51
+
37
52
  def element_name_cleanup(xmldoc)
38
53
  xmldoc.traverse { |n| n.name = n.name.gsub(/_/, "-") }
39
54
  end
40
55
 
41
- def callout_cleanup(xmldoc)
56
+ def link_callouts_to_annotations(callouts, annotations)
57
+ callouts.each_with_index do |c, i|
58
+ c["target"] = "_" + UUIDTools::UUID.random_create
59
+ annotations[i]["id"] = c["target"]
60
+ end
61
+ end
62
+
63
+ def align_callouts_to_annotations(xmldoc)
42
64
  xmldoc.xpath("//sourcecode").each do |x|
43
65
  callouts = x.elements.select { |e| e.name == "callout" }
44
66
  annotations = x.elements.select { |e| e.name == "annotation" }
45
67
  if callouts.size == annotations.size
46
- callouts.each_with_index do |c, i|
47
- c["target"] = UUIDTools::UUID.random_create
48
- annotations[i]["id"] = c["id"]
49
- end
68
+ link_callouts_to_annotations(callouts, annotations)
50
69
  else
51
- warn "#{x["id"]}: mismatch of callouts and annotations"
70
+ warn "#{x['id']}: mismatch of callouts and annotations"
52
71
  end
53
72
  end
54
73
  end
55
74
 
56
- LOCALITY_REGEX_STR = <<~REGEXP
57
- ^((?<locality>section|clause|part|paragraph|chapter|page)\\s+
58
- (?<ref>\\S+?)|(?<locality>whole))[,:]?\\s*
59
- (?<text>.*)$
60
- REGEXP
61
- LOCALITY_RE = Regexp.new(LOCALITY_REGEX_STR.gsub(/\s/, ""),
62
- Regexp::IGNORECASE|Regexp::MULTILINE)
63
-
64
- def termdef_warn(text, re, term, msg)
65
- re.match? text and warn "ISO style: #{term}: #{msg}"
75
+ def merge_annotations_into_sourcecode(xmldoc)
76
+ xmldoc.xpath("//sourcecode").each do |x|
77
+ while x&.next_element&.name == "annotation"
78
+ x.next_element.parent = x
79
+ end
80
+ end
66
81
  end
67
82
 
68
- def termdef_style(xmldoc)
69
- xmldoc.xpath("//term").each do |t|
70
- para = t.at("./p") or return
71
- term = t.at("preferred").text
72
- termdef_warn(para.text, /^(the|a)\b/i, term,
73
- "term definition starts with article")
74
- termdef_warn(para.text, /\.$/i, term,
75
- "term definition ends with period")
76
- end
83
+ def callout_cleanup(xmldoc)
84
+ merge_annotations_into_sourcecode(xmldoc)
85
+ align_callouts_to_annotations(xmldoc)
77
86
  end
78
87
 
79
88
  def termdef_stem_cleanup(xmldoc)
80
- xmldoc.xpath("//termdef/p/stem").each do |a|
89
+ xmldoc.xpath("//term/p/stem").each do |a|
81
90
  if a.parent.elements.size == 1
82
91
  # para containing just a stem expression
83
92
  t = Nokogiri::XML::Element.new("admitted", xmldoc)
@@ -97,7 +106,7 @@ module Asciidoctor
97
106
 
98
107
  def termdefinition_cleanup(xmldoc)
99
108
  xmldoc.xpath("//term").each do |d|
100
- first_child = d.at("./p | ./figure | ./formula") or return
109
+ first_child = d.at("./p | ./figure | ./formula") || return
101
110
  t = Nokogiri::XML::Element.new("definition", xmldoc)
102
111
  first_child.replace(t)
103
112
  t << first_child.remove
@@ -114,29 +123,66 @@ module Asciidoctor
114
123
  end
115
124
  end
116
125
 
126
+ def termdef_boilerplate_cleanup(xmldoc)
127
+ xmldoc.xpath("//terms/p | //terms/ul").each do |a|
128
+ a.remove
129
+ end
130
+ end
131
+
117
132
  def termdef_cleanup(xmldoc)
118
133
  termdef_unnest_cleanup(xmldoc)
119
134
  termdef_stem_cleanup(xmldoc)
120
135
  termdomain_cleanup(xmldoc)
121
136
  termdefinition_cleanup(xmldoc)
122
- termdef_style(xmldoc)
137
+ termdef_boilerplate_cleanup(xmldoc)
123
138
  end
124
139
 
125
- ELEMS_ALLOW_NOTES =
126
- %w[p formula quote sourcecode example admonition ul ol dl figure]
140
+ ELEMS_ALLOW_NOTES =
141
+ %w[p formula quote sourcecode example admonition ul ol dl figure].freeze
127
142
 
128
143
  # if a note is at the end of a section, it is left alone
129
- # if a note is followed by a non-note block,
144
+ # if a note is followed by a non-note block,
130
145
  # it is moved inside its preceding block
131
146
  def note_cleanup(xmldoc)
132
147
  q = "//note[following-sibling::*[not(local-name() = 'note')]]"
133
148
  xmldoc.xpath(q).each do |n|
134
149
  next unless n.ancestors("table").empty?
135
- prev = n.previous_element or next
150
+ prev = n.previous_element || next
136
151
  n.parent = prev if ELEMS_ALLOW_NOTES.include? prev.name
137
152
  end
138
153
  end
139
154
 
155
+ def empty_text_before_first_element(x)
156
+ x.children.each do |c|
157
+ if c.text?
158
+ return false if /\S/.match?(c.text)
159
+ end
160
+ return true if c.element?
161
+ end
162
+ true
163
+ end
164
+
165
+ def strip_initial_space(x)
166
+ if x.children[0].text?
167
+ if !/\S/.match?(x.children[0].text)
168
+ x.children[0].remove
169
+ else
170
+ x.children[0].content = x.children[0].text.gsub(/^ /, "")
171
+ end
172
+ end
173
+ end
174
+
175
+ def bookmark_cleanup(xmldoc)
176
+ xmldoc.xpath("//li[descendant::bookmark]").each do |x|
177
+ if x&.elements[0]&.name == "p" &&
178
+ x&.elements[0]&.elements[0]&.name == "bookmark"
179
+ if empty_text_before_first_element(x.elements[0])
180
+ x["id"] = (x.elements[0].elements[0].remove)["id"]
181
+ strip_initial_space(x.elements[0])
182
+ end
183
+ end
184
+ end
185
+ end
140
186
  end
141
187
  end
142
188
  end
@@ -31,11 +31,20 @@ module Asciidoctor
31
31
  end
32
32
  end
33
33
 
34
+ def insert_thead(s)
35
+ thead = s.at("./thead")
36
+ return thead unless thead.nil?
37
+ if tname = s.at("./name")
38
+ thead = tname.add_next_sibling("<thead/>").first
39
+ return thead
40
+ end
41
+ s.children.first.add_previous_sibling("<thead/>").first
42
+ end
43
+
34
44
  def header_rows_cleanup(xmldoc)
35
- q = "//table[@headerrows]"
36
- xmldoc.xpath(q).each do |s|
37
- thead = s.at("./thead")
38
- [1..s["headerrows"].to_i].each do
45
+ xmldoc.xpath("//table[@headerrows]").each do |s|
46
+ thead = insert_thead(s)
47
+ (thead.xpath("./tr").size...s["headerrows"].to_i).each do
39
48
  row = s.at("./tbody/tr")
40
49
  row.parent = thead
41
50
  end
@@ -125,42 +134,86 @@ module Asciidoctor
125
134
  outnum = i
126
135
  seen[fn.text] = outnum
127
136
  end
128
- fn["reference"] = (outnum - 1 + 'a'.ord).chr
137
+ fn["reference"] = (outnum - 1 + "a".ord).chr
129
138
  fn["table"] = true
130
139
  end
131
140
  end
132
141
  end
133
142
 
134
- def other_footnote_renumber(xmldoc)
135
- seen, i = {}, 0
136
- xmldoc.xpath("//fn | //bibitem/note").each do |fn|
137
- unless fn["table"]
138
- if seen[fn.text] then outnum = seen[fn.text]
139
- else
140
- i += 1
141
- outnum = i
142
- seen[fn.text] = outnum
143
- end
144
- fn["reference"] = outnum.to_s
143
+ def other_footnote_renumber1(fn, i, seen, outnum)
144
+ unless fn["table"]
145
+ if seen[fn.text] then outnum = seen[fn.text]
146
+ else
147
+ i += 1
148
+ outnum = i
149
+ seen[fn.text] = outnum
145
150
  end
146
- fn.delete("table")
151
+ fn["reference"] = outnum.to_s
152
+ end
153
+ [i, seen, outnum]
154
+ end
155
+
156
+ PRE_NORMREF_FOOTNOTES = "//foreword//fn | //introduction//fn |"\
157
+ "//clause[title = 'Scope']//fn" .freeze
158
+
159
+ NORMREF_FOOTNOTES =
160
+ "//references[title = 'Normative References']//fn |"\
161
+ "//references[title = 'Normative References']//bibitem/note".freeze
162
+
163
+ POST_NORMREF_FOOTNOTES =
164
+ "//clause[not(title = 'Scope')]//fn | "\
165
+ "//references[title = 'Bibliography']//fn | "\
166
+ "//references[title = 'Bibliography']//bibitem/note".freeze
167
+
168
+ def other_footnote_renumber(xmldoc)
169
+ seen = {}
170
+ i = 0
171
+ outnum = 0
172
+ xmldoc.xpath(PRE_NORMREF_FOOTNOTES).each do |fn|
173
+ i, seen, outnum = other_footnote_renumber1(fn, i, seen, outnum)
174
+ end
175
+ xmldoc.xpath(NORMREF_FOOTNOTES).each do |fn|
176
+ i, seen, outnum = other_footnote_renumber1(fn, i, seen, outnum)
177
+ end
178
+ xmldoc.xpath(POST_NORMREF_FOOTNOTES).each do |fn|
179
+ i, seen, outnum = other_footnote_renumber1(fn, i, seen, outnum)
147
180
  end
148
181
  end
149
182
 
150
183
  def footnote_renumber(xmldoc)
151
184
  table_footnote_renumber(xmldoc)
152
185
  other_footnote_renumber(xmldoc)
186
+ xmldoc.xpath("//fn").each do |fn|
187
+ fn.delete("table")
188
+ end
153
189
  end
154
190
 
155
191
  def sections_cleanup(x)
156
192
  s = x.at("//sections")
157
193
  foreword = x.at("//foreword")
158
- s.previous = foreword.remove
194
+ s.previous = foreword.remove if foreword
159
195
  introduction = x.at("//introduction")
160
196
  s.previous = introduction.remove if introduction
161
197
  x.xpath("//sections/references").reverse_each { |r| s.next = r.remove }
162
198
  x.xpath("//sections/annex").reverse_each { |r| s.next = r.remove }
163
199
  end
200
+
201
+ def obligations_cleanup(x)
202
+ (s = x.at("//foreword")) && s["obligation"] = "informative"
203
+ (s = x.at("//introduction")) && s["obligation"] = "informative"
204
+ (s = x.at("//clause[title = 'Scope']")) && s["obligation"] = "normative"
205
+ (s = x.at("//clause[title = 'Symbols and Abbreviated Terms']")) &&
206
+ s["obligation"] = "normative"
207
+ x.xpath("//references").each { |r| r["obligation"] = "informative" }
208
+ x.xpath("//terms").each { |r| r["obligation"] = "normative" }
209
+ x.xpath("//symbols-abbrevs").each { |r| r["obligation"] = "normative" }
210
+ x.xpath("//annex | //clause").each do |r|
211
+ r["obligation"] = "normative" unless r["obligation"]
212
+ end
213
+ x.xpath("//subsection").each do |r|
214
+ r["obligation"] = r.at("./ancestor::*/@obligation").text
215
+ end
216
+ end
164
217
  end
165
218
  end
166
219
  end
@@ -1,31 +1,41 @@
1
1
  module Asciidoctor
2
2
  module ISO
3
3
  module Cleanup
4
+ # currently references cannot contain commas!
5
+ # extending localities to cover ISO referencing
6
+ LOCALITY_REGEX_STR = <<~REGEXP.freeze
7
+ ^((?<locality>section|clause|part|paragraph|chapter|page|
8
+ table|annex|figure|example|note|formula)\\s+
9
+ (?<ref>[^ \\t\\n,:-]+)(-(?<to>[^ \\t\\n,:-]+))?|
10
+ (?<locality>whole))[,:]?\\s*
11
+ (?<text>.*)$
12
+ REGEXP
13
+ LOCALITY_RE = Regexp.new(LOCALITY_REGEX_STR.gsub(/\s/, ""),
14
+ Regexp::IGNORECASE | Regexp::MULTILINE)
4
15
 
5
16
  def extract_localities(x)
6
17
  text = x.children.first.remove.text
7
- m = LOCALITY_RE.match text
8
- while !m.nil?
9
- ref = m[:ref] ? "<reference>#{m[:ref]}</reference>" : ""
10
- locality = m[:locality].downcase
11
- x.add_child("<locality type='#{locality}'>#{ref}</locality>")
18
+ while (m = LOCALITY_RE.match text)
19
+ ref = m[:ref] ? "<referenceFrom>#{m[:ref]}</referenceFrom>" : ""
20
+ refto = m[:to] ? "<referenceTo>#{m[:to]}</referenceTo>" : ""
21
+ x.add_child("<locality type='#{m[:locality].downcase}'>"\
22
+ "#{ref}#{refto}</locality>")
12
23
  text = m[:text]
13
- m = LOCALITY_RE.match text
14
24
  end
15
25
  x.add_child(text)
16
26
  end
17
27
 
18
28
  def xref_to_eref(x)
19
29
  x["bibitemid"] = x["target"]
20
- x["citeas"] = @anchors&.dig(x["target"], :xref) or
21
- warn "ISO: #{x["target"]} is not a real reference!"
30
+ x["citeas"] = @anchors&.dig(x["target"], :xref) ||
31
+ warn("ISO: #{x['target']} is not a real reference!")
22
32
  x.delete("target")
23
33
  extract_localities(x) unless x.children.empty?
24
34
  end
25
35
 
26
36
  def xref_cleanup(xmldoc)
27
37
  xmldoc.xpath("//xref").each do |x|
28
- if is_refid? x["target"]
38
+ if refid? x["target"]
29
39
  x.name = "eref"
30
40
  xref_to_eref(x)
31
41
  else
@@ -34,30 +44,26 @@ module Asciidoctor
34
44
  end
35
45
  end
36
46
 
47
+ # allows us to deal with doc relation localities,
48
+ # temporarily stashed to "bpart"
49
+ def bpart_cleanup(xmldoc)
50
+ xmldoc.xpath("//relation/bpart").each do |x|
51
+ extract_localities(x)
52
+ x.replace(x.children)
53
+ end
54
+ end
55
+
37
56
  def quotesource_cleanup(xmldoc)
38
- xmldoc.xpath("//quote/source").each do |x|
57
+ xmldoc.xpath("//quote/source | //terms/source").each do |x|
39
58
  xref_to_eref(x)
40
59
  end
41
60
  end
42
61
 
43
62
  def origin_cleanup(xmldoc)
44
63
  xmldoc.xpath("//origin").each do |x|
45
- x["citeas"] = @anchors[x["bibitemid"]][:xref]
46
- n = x.next_element
47
- if !n.nil? && n.name == "isosection"
48
- n.name = "locality"
49
- n["type"] = "section"
50
- n.parent = x
51
- end
52
- end
53
- end
54
-
55
- def isotitle_cleanup(xmldoc)
56
- # Remove italicised ISO titles
57
- xmldoc.xpath("//isotitle").each do |a|
58
- if a.elements.size == 1 && a.elements[0].name == "em"
59
- a.children = a.elements[0].children
60
- end
64
+ x["citeas"] = @anchors&.dig(x["bibitemid"], :xref) ||
65
+ warn("ISO: #{x['bibitemid']} is not a real reference!")
66
+ extract_localities(x) unless x.children.empty?
61
67
  end
62
68
  end
63
69
 
@@ -67,12 +73,11 @@ module Asciidoctor
67
73
  parent = r.parent
68
74
  parent.previous = r.remove
69
75
  end
70
- xmldoc
71
76
  end
72
77
 
73
78
  def normref_cleanup(xmldoc)
74
79
  q = "//references[title = 'Normative References']"
75
- r = xmldoc.at(q)
80
+ r = xmldoc.at(q) || return
76
81
  r.elements.each do |n|
77
82
  n.remove unless ["title", "bibitem"].include? n.name
78
83
  end
@@ -87,9 +92,9 @@ module Asciidoctor
87
92
  def reference_names(xmldoc)
88
93
  xmldoc.xpath("//bibitem").each do |ref|
89
94
  isopub = ref.at("./contributor[role/@type = 'publisher']/"\
90
- "organization[name = 'ISO']")
95
+ "organization[name = 'ISO' or name = 'IEC']")
91
96
  docid = ref.at("./docidentifier")
92
- date = ref.at("./publisherdate")
97
+ date = ref.at("./date[@type = 'published']")
93
98
  reference = format_ref(docid.text, isopub)
94
99
  reference += ": #{date.text}" if date && isopub
95
100
  @anchors[ref["id"]] = { xref: reference }