metanorma-standoc 1.11.0.1 → 1.11.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/lib/asciidoctor/standoc/base.rb +4 -100
  4. data/lib/asciidoctor/standoc/blocks.rb +1 -1
  5. data/lib/asciidoctor/standoc/cleanup.rb +2 -1
  6. data/lib/asciidoctor/standoc/cleanup_block.rb +1 -2
  7. data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +28 -20
  8. data/lib/asciidoctor/standoc/cleanup_inline.rb +14 -4
  9. data/lib/asciidoctor/standoc/cleanup_ref_dl.rb +25 -15
  10. data/lib/asciidoctor/standoc/cleanup_reqt.rb +3 -3
  11. data/lib/asciidoctor/standoc/cleanup_section_names.rb +2 -2
  12. data/lib/asciidoctor/standoc/cleanup_terms.rb +58 -21
  13. data/lib/asciidoctor/standoc/cleanup_terms_designations.rb +58 -21
  14. data/lib/asciidoctor/standoc/cleanup_text.rb +23 -0
  15. data/lib/asciidoctor/standoc/datamodel/attributes_table_preprocessor.rb +6 -6
  16. data/lib/asciidoctor/standoc/front.rb +13 -9
  17. data/lib/asciidoctor/standoc/inline.rb +13 -11
  18. data/lib/asciidoctor/standoc/isodoc.rng +73 -19
  19. data/lib/asciidoctor/standoc/lists.rb +1 -3
  20. data/lib/asciidoctor/standoc/ref.rb +101 -75
  21. data/lib/asciidoctor/standoc/ref_date_id.rb +30 -1
  22. data/lib/asciidoctor/standoc/ref_sect.rb +16 -6
  23. data/lib/asciidoctor/standoc/render.rb +115 -0
  24. data/lib/asciidoctor/standoc/reqt.rb +1 -1
  25. data/lib/asciidoctor/standoc/section.rb +33 -15
  26. data/lib/asciidoctor/standoc/terms.rb +7 -1
  27. data/lib/asciidoctor/standoc/utils.rb +0 -16
  28. data/lib/asciidoctor/standoc/validate.rb +1 -1
  29. data/lib/isodoc/html/htmlstyle.css +20 -11
  30. data/lib/isodoc/html/htmlstyle.scss +11 -11
  31. data/lib/metanorma/standoc/version.rb +1 -1
  32. data/metanorma-standoc.gemspec +3 -3
  33. data/spec/asciidoctor/base_spec.rb +48 -0
  34. data/spec/asciidoctor/blocks_spec.rb +99 -17
  35. data/spec/asciidoctor/cleanup_blocks_spec.rb +24 -0
  36. data/spec/asciidoctor/cleanup_sections_spec.rb +1 -1
  37. data/spec/asciidoctor/cleanup_spec.rb +6 -6
  38. data/spec/asciidoctor/cleanup_terms_spec.rb +556 -89
  39. data/spec/asciidoctor/datamodel/attributes_table_preprocessor_spec.rb +21 -21
  40. data/spec/asciidoctor/datamodel/diagram_preprocessor_spec.rb +16 -16
  41. data/spec/asciidoctor/inline_spec.rb +174 -5
  42. data/spec/asciidoctor/isobib_cache_spec.rb +4 -8
  43. data/spec/asciidoctor/macros_spec.rb +2 -2
  44. data/spec/asciidoctor/refs_dl_spec.rb +4 -4
  45. data/spec/asciidoctor/refs_spec.rb +889 -495
  46. data/spec/asciidoctor/section_spec.rb +64 -2
  47. data/spec/spec_helper.rb +2 -2
  48. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +182 -182
  49. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec1.yml +12 -12
  50. data/spec/vcr_cassettes/isobib_get_123.yml +14 -14
  51. data/spec/vcr_cassettes/isobib_get_123_1.yml +99 -99
  52. data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +107 -107
  53. data/spec/vcr_cassettes/isobib_get_123_2001.yml +14 -14
  54. data/spec/vcr_cassettes/isobib_get_124.yml +12 -12
  55. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +14 -14
  56. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +46 -46
  57. metadata +9 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7cb09afdb6668a003d8ef2b58d6260631b7b8e068d3ca16baeee26535c8186d0
4
- data.tar.gz: 76b254bc985ef940d8224c85202f001cd8660a681386b8b1e774bde626314ff5
3
+ metadata.gz: 3cd9e01037065cfbc5d497224c5d6ed6ac5088cd4b4df6f404e08a7c552abcf9
4
+ data.tar.gz: 7eefde1d2046eedbce2c46c8841059210480a43cdea3656bbfd7cfbb068df1b1
5
5
  SHA512:
6
- metadata.gz: 893626c5998b7853394c39a0e4249f1a11346d0beb5cc00a9f76edc8ce129cf591ba6819ed6974b34a115f89b82c64b8acccf3c2dfcd71dcb20226c90653e62a
7
- data.tar.gz: c10c585b0274e9be19b848c9dcc175a1ef9325ee0dc875bc1b1aafb057c3fcea1c235488c986093980bc5ce6710d293c053a68d3954aae40365def0071d244e6
6
+ metadata.gz: 3fcf00d490fa157fdae4029bd261b1d2b3caf09b2d9a7d8e25c67cc0f4e7a474b6baadfedd1f8b9c90d63a8cad59184bafc237500f46cca83364ffd61dc60914
7
+ data.tar.gz: afb262667567181815daf62ba580d124874d1bba843ff6cda2c39a861acf6ec246c04766d8e5822ae3dd77326e22d687cbb255a0562644f1fb07f97f39c67416
data/Gemfile CHANGED
@@ -9,3 +9,5 @@ gemspec
9
9
  if File.exist? 'Gemfile.devel'
10
10
  eval File.read('Gemfile.devel'), nil, 'Gemfile.devel' # rubocop:disable Security/Eval
11
11
  end
12
+
13
+ gem "reline", "~> 0.2.8.pre.11"
@@ -8,6 +8,7 @@ require "relaton"
8
8
  require "fileutils"
9
9
  require "metanorma-utils"
10
10
  require "isodoc/xslfo_convert"
11
+ require_relative "render"
11
12
 
12
13
  module Asciidoctor
13
14
  module Standoc
@@ -24,85 +25,6 @@ module Asciidoctor
24
25
  self.class::XML_NAMESPACE
25
26
  end
26
27
 
27
- def html_extract_attributes(node)
28
- {
29
- script: node.attr("script"),
30
- bodyfont: node.attr("body-font"),
31
- headerfont: node.attr("header-font"),
32
- monospacefont: node.attr("monospace-font"),
33
- i18nyaml: node.attr("i18nyaml"),
34
- scope: node.attr("scope"),
35
- htmlstylesheet: node.attr("htmlstylesheet"),
36
- htmlstylesheet_override: node.attr("htmlstylesheet-override"),
37
- htmlcoverpage: node.attr("htmlcoverpage"),
38
- htmlintropage: node.attr("htmlintropage"),
39
- scripts: node.attr("scripts"),
40
- scripts_override: node.attr("scripts-override"),
41
- scripts_pdf: node.attr("scripts-pdf"),
42
- datauriimage: node.attr("data-uri-image") != "false",
43
- htmltoclevels: node.attr("htmltoclevels") || node.attr("toclevels"),
44
- doctoclevels: node.attr("doctoclevels") || node.attr("toclevels"),
45
- break_up_urls_in_tables: node.attr("break-up-urls-in-tables"),
46
- suppressasciimathdup: node.attr("suppress-asciimath-dup"),
47
- bare: node.attr("bare"),
48
- sectionsplit: node.attr("sectionsplit"),
49
- baseassetpath: node.attr("base-asset-path"),
50
- aligncrosselements: node.attr("align-cross-elements"),
51
- }
52
- end
53
-
54
- def html_converter(node)
55
- IsoDoc::HtmlConvert.new(html_extract_attributes(node))
56
- end
57
-
58
- def pdf_converter(node)
59
- return nil if node.attr("no-pdf")
60
-
61
- IsoDoc::Standoc::PdfConvert.new(doc_extract_attributes(node))
62
- end
63
-
64
- def doc_extract_attributes(node)
65
- attrs = {
66
- script: node.attr("script"),
67
- bodyfont: node.attr("body-font"),
68
- headerfont: node.attr("header-font"),
69
- monospacefont: node.attr("monospace-font"),
70
- i18nyaml: node.attr("i18nyaml"),
71
- scope: node.attr("scope"),
72
- wordstylesheet: node.attr("wordstylesheet"),
73
- wordstylesheet_override: node.attr("wordstylesheet-override"),
74
- standardstylesheet: node.attr("standardstylesheet"),
75
- header: node.attr("header"),
76
- wordcoverpage: node.attr("wordcoverpage"),
77
- wordintropage: node.attr("wordintropage"),
78
- ulstyle: node.attr("ulstyle"),
79
- olstyle: node.attr("olstyle"),
80
- htmltoclevels: node.attr("htmltoclevels") || node.attr("toclevels"),
81
- doctoclevels: node.attr("doctoclevels") || node.attr("toclevels"),
82
- break_up_urls_in_tables: node.attr("break-up-urls-in-tables"),
83
- suppressasciimathdup: node.attr("suppress-asciimath-dup"),
84
- bare: node.attr("bare"),
85
- baseassetpath: node.attr("base-asset-path"),
86
- aligncrosselements: node.attr("align-cross-elements"),
87
- }
88
-
89
- if fonts_manifest = node.attr(FONTS_MANIFEST)
90
- attrs[IsoDoc::XslfoPdfConvert::MN2PDF_OPTIONS] = {
91
- IsoDoc::XslfoPdfConvert::MN2PDF_FONT_MANIFEST => fonts_manifest,
92
- }
93
- end
94
-
95
- attrs
96
- end
97
-
98
- def doc_converter(node)
99
- IsoDoc::WordConvert.new(doc_extract_attributes(node))
100
- end
101
-
102
- def presentation_xml_converter(node)
103
- IsoDoc::PresentationXMLConvert.new(html_extract_attributes(node))
104
- end
105
-
106
28
  def init(node)
107
29
  @fn_number ||= 0
108
30
  @draft = false
@@ -124,6 +46,7 @@ module Asciidoctor
124
46
  @output_dir = outputdir node
125
47
  @no_isobib_cache = node.attr("no-isobib-cache")
126
48
  @no_isobib = node.attr("no-isobib")
49
+ @index_terms = node.attr("index-terms")
127
50
  @sourcecode_markup_start = node.attr("sourcecode-markup-start") || "{{{"
128
51
  @sourcecode_markup_end = node.attr("sourcecode-markup-end") || "}}}"
129
52
  @bibdb = nil
@@ -136,31 +59,12 @@ module Asciidoctor
136
59
  init_bib_caches(node)
137
60
  init_iev_caches(node)
138
61
  @lang = (node.attr("language") || "en")
139
- @script = (node.attr("script") || default_script(node.attr("language")))
62
+ @script = (node.attr("script") ||
63
+ Metanorma::Utils.default_script(node.attr("language")))
140
64
  @isodoc = isodoc(@lang, @script, node.attr("i18nyaml"))
141
65
  @i18n = @isodoc.i18n
142
66
  end
143
67
 
144
- def default_fonts(node)
145
- b = node.attr("body-font") ||
146
- (node.attr("script") == "Hans" ? '"Source Han Sans",serif' : '"Cambria",serif')
147
- h = node.attr("header-font") ||
148
- (node.attr("script") == "Hans" ? '"Source Han Sans",sans-serif' : '"Cambria",serif')
149
- m = node.attr("monospace-font") || '"Courier New",monospace'
150
- "$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n"
151
- end
152
-
153
- def outputs(node, ret)
154
- File.open("#{@filename}.xml", "w:UTF-8") { |f| f.write(ret) }
155
- presentation_xml_converter(node).convert("#{@filename}.xml")
156
- html_converter(node).convert("#{@filename}.presentation.xml",
157
- nil, false, "#{@filename}.html")
158
- doc_converter(node).convert("#{@filename}.presentation.xml",
159
- nil, false, "#{@filename}.doc")
160
- pdf_converter(node)&.convert("#{@filename}.presentation.xml",
161
- nil, false, "#{@filename}.pdf")
162
- end
163
-
164
68
  def document(node)
165
69
  init(node)
166
70
  ret = makexml(node).to_xml(encoding: "US-ASCII", indent: 2)
@@ -1,5 +1,5 @@
1
1
  require "htmlentities"
2
- require "uri"
2
+ require "uri" if /^2\./.match?(RUBY_VERSION)
3
3
  require_relative "./blocks_notes"
4
4
 
5
5
  module Asciidoctor
@@ -48,6 +48,7 @@ module Asciidoctor
48
48
  termdef_cleanup(xmldoc)
49
49
  RelatonIev::iev_cleanup(xmldoc, @bibdb)
50
50
  element_name_cleanup(xmldoc)
51
+ index_cleanup(xmldoc)
51
52
  bpart_cleanup(xmldoc)
52
53
  quotesource_cleanup(xmldoc)
53
54
  callout_cleanup(xmldoc)
@@ -76,7 +77,7 @@ module Asciidoctor
76
77
  street city state country postcode identifier referenceFrom surname
77
78
  referenceTo docidentifier docnumber prefix initial addition forename
78
79
  title draft secretariat title-main title-intro title-part
79
- verbaldefinition nonverbalrepresentation}.freeze
80
+ verbal-definition non-verbal-representation}.freeze
80
81
 
81
82
  # it seems Nokogiri::XML is treating the content of <script> as cdata,
82
83
  # because of its use in HTML. Bad nokogiri. Undoing that, since we use
@@ -89,8 +89,7 @@ module Asciidoctor
89
89
  def note_cleanup(xmldoc)
90
90
  q = "//note[following-sibling::*[not(local-name() = 'note')]]"
91
91
  xmldoc.xpath(q).each do |n|
92
- next if n["keep-separate"] == "true"
93
- next unless n.ancestors("table").empty?
92
+ next if n["keep-separate"] == "true" || !n.ancestors("table").empty?
94
93
 
95
94
  prev = n.previous_element || next
96
95
  n.parent = prev if ELEMS_ALLOW_NOTES.include? prev.name
@@ -15,15 +15,18 @@ module Asciidoctor
15
15
  )
16
16
  end
17
17
 
18
- def term_defs_boilerplate(div, source, term, preface, isodoc)
18
+ def term_defs_boilerplate(div, source, term, _preface, isodoc)
19
19
  a = @i18n.term_def_boilerplate and div.next = a
20
20
  source.each do |s|
21
21
  @anchors[s["bibitemid"]] or
22
22
  @log.add("Crossreferences", nil,
23
23
  "term source #{s['bibitemid']} not referenced")
24
24
  end
25
- a = source.empty? && term.nil? ? @i18n.no_terms_boilerplate :
26
- term_defs_boilerplate_cont(source, term, isodoc)
25
+ a = if source.empty? && term.nil?
26
+ @i18n.no_terms_boilerplate
27
+ else
28
+ term_defs_boilerplate_cont(source, term, isodoc)
29
+ end
27
30
  a and div.next = a
28
31
  end
29
32
 
@@ -51,10 +54,11 @@ module Asciidoctor
51
54
  end
52
55
 
53
56
  TERM_CLAUSE = "//sections/terms | "\
54
- "//sections/clause[descendant::terms]".freeze
57
+ "//sections/clause[descendant::terms]".freeze
55
58
 
56
59
  NORM_REF = "//bibliography/references[@normative = 'true'] | "\
57
- "//bibliography/clause[.//references[@normative = 'true']]".freeze
60
+ "//bibliography/clause[.//references[@normative = 'true']]"
61
+ .freeze
58
62
 
59
63
  def boilerplate_isodoc(xmldoc)
60
64
  x = xmldoc.dup
@@ -118,8 +122,11 @@ module Asciidoctor
118
122
 
119
123
  def boilerplate(xml, conv)
120
124
  file = boilerplate_file(xml)
121
- file = File.join(@localdir, @boilerplateauthority) if @boilerplateauthority
122
- !file.nil? and File.exists?(file) or return
125
+ if @boilerplateauthority
126
+ file = File.join(@localdir,
127
+ @boilerplateauthority)
128
+ end
129
+ (!file.nil? and File.exists?(file)) or return
123
130
  conv.populate_template(File.read(file, encoding: "UTF-8"), nil)
124
131
  end
125
132
 
@@ -166,28 +173,29 @@ module Asciidoctor
166
173
  end
167
174
  end
168
175
 
169
- def indirect_eref_to_xref(e, id)
170
- loc = e&.at("./localityStack[locality[@type = 'anchor']]")&.remove&.text ||
171
- e&.at("./locality[@type = 'anchor']")&.remove&.text || id
172
- e.name = "xref"
173
- e.delete("bibitemid")
174
- e.delete("citeas")
175
- e["target"] = loc
176
- unless e.document.at("//*[@id = '#{loc}']")
177
- e.children = %(** Missing target #{loc})
178
- e["target"] = id
176
+ def indirect_eref_to_xref(eref, ident)
177
+ loc = eref&.at("./localityStack[locality[@type = 'anchor']]")
178
+ &.remove&.text ||
179
+ eref&.at("./locality[@type = 'anchor']")&.remove&.text || ident
180
+ eref.name = "xref"
181
+ eref.delete("bibitemid")
182
+ eref.delete("citeas")
183
+ eref["target"] = loc
184
+ unless eref.document.at("//*[@id = '#{loc}']")
185
+ eref.children = %(** Missing target #{loc})
186
+ eref["target"] = ident
179
187
  end
180
188
  end
181
189
 
182
190
  def resolve_local_indirect_erefs(xmldoc, refs, prefix)
183
191
  refs.each_with_object([]) do |r, m|
184
192
  id = r.sub(/^#{prefix}_/, "")
185
- if n = xmldoc.at("//*[@id = '#{id}']") and n.at("./ancestor-or-self::*[@type = '#{prefix}']")
193
+ if n = xmldoc.at("//*[@id = '#{id}']") and
194
+ n.at("./ancestor-or-self::*[@type = '#{prefix}']")
186
195
  xmldoc.xpath("//eref[@bibitemid = '#{r}']").each do |e|
187
196
  indirect_eref_to_xref(e, id)
188
197
  end
189
- else
190
- m << r
198
+ else m << r
191
199
  end
192
200
  end
193
201
  end
@@ -159,15 +159,25 @@ module Asciidoctor
159
159
  end
160
160
 
161
161
  def contenthash_id_cleanup(doc)
162
- ids = doc.xpath("//*[@id]").each_with_object({}) do |x, m|
162
+ ids = contenthash_id_make(doc)
163
+ contenthash_id_update_refs(doc, ids)
164
+ end
165
+
166
+ def contenthash_id_make(doc)
167
+ doc.xpath("//*[@id]").each_with_object({}) do |x, m|
163
168
  next unless guid?(x["id"])
164
169
 
165
170
  m[x["id"]] = contenthash(x)
166
171
  x["id"] = m[x["id"]]
167
172
  end
168
- [%w(review from), %(review to), %(callout target), %(eref bibitemid),
169
- %(citation bibitemid), %(xref target), %(xref to)].each do |a|
170
- doc.xpath("//#{a[0]}").each { |x| ids[a[1]] and x[a[1]] = ids[a[1]] }
173
+ end
174
+
175
+ def contenthash_id_update_refs(doc, ids)
176
+ [%w(review from), %w(review to), %w(callout target), %w(eref bibitemid),
177
+ %w(citation bibitemid), %w(xref target), %w(xref to)].each do |a|
178
+ doc.xpath("//#{a[0]}").each do |x|
179
+ ids[x[a[1]]] and x[a[1]] = ids[x[a[1]]]
180
+ end
171
181
  end
172
182
  end
173
183
 
@@ -17,45 +17,53 @@ module Asciidoctor
17
17
 
18
18
  def validate_ref_dl(bib, c)
19
19
  id = bib["id"]
20
- id ||= c["id"] unless /^_/.match(c["id"]) # do not accept implicit id
20
+ id ||= c["id"] unless /^_/.match?(c["id"]) # do not accept implicit id
21
21
  unless id
22
- @log.add("Anchors", c, "The following reference is missing an anchor:\n" + c.to_xml)
22
+ @log.add("Anchors", c,
23
+ "The following reference is missing an anchor:\n" + c.to_xml)
23
24
  return
24
25
  end
25
26
  @refids << id
26
- bib["title"] or @log.add("Bibliography", c, "Reference #{id} is missing a title")
27
- bib["docid"] or @log.add("Bibliography", c, "Reference #{id} is missing a document identifier (docid)")
27
+ bib["title"] or
28
+ @log.add("Bibliography", c, "Reference #{id} is missing a title")
29
+ bib["docid"] or
30
+ @log.add("Bibliography", c,
31
+ "Reference #{id} is missing a document identifier (docid)")
28
32
  end
29
33
 
30
34
  def extract_from_p(tag, bib, key)
31
35
  return unless bib[tag]
36
+
32
37
  "<#{key}>#{bib[tag].at('p').children}</#{key}>"
33
38
  end
34
39
 
35
40
  # if the content is a single paragraph, replace it with its children
36
41
  # single links replaced with uri
37
- def p_unwrap(p)
38
- elems = p.elements
42
+ def p_unwrap(para)
43
+ elems = para.elements
39
44
  if elems.size == 1 && elems[0].name == "p"
40
45
  link_unwrap(elems[0]).children.to_xml.strip
41
46
  else
42
- p.to_xml.strip
47
+ para.to_xml.strip
43
48
  end
44
49
  end
45
50
 
46
- def link_unwrap(p)
47
- elems = p.elements
51
+ def link_unwrap(para)
52
+ elems = para.elements
48
53
  if elems.size == 1 && elems[0].name == "link"
49
- p.at("./link").replace(elems[0]["target"].strip)
54
+ para.at("./link").replace(elems[0]["target"].strip)
50
55
  end
51
- p
56
+ para
52
57
  end
53
58
 
54
59
  def dd_bib_extract(dtd)
55
60
  return nil if dtd.children.empty?
61
+
56
62
  dtd.at("./dl") and return dl_bib_extract(dtd)
57
63
  elems = dtd.remove.elements
58
- return p_unwrap(dtd) unless elems.size == 1 && %w(ol ul).include?(elems[0].name)
64
+ return p_unwrap(dtd) unless elems.size == 1 &&
65
+ %w(ol ul).include?(elems[0].name)
66
+
59
67
  ret = []
60
68
  elems[0].xpath("./li").each do |li|
61
69
  ret << p_unwrap(li)
@@ -64,7 +72,7 @@ module Asciidoctor
64
72
  end
65
73
 
66
74
  def add_to_hash(bib, key, val)
67
- Metanorma::Utils::set_nested_value(bib, key.split(/\./), val)
75
+ Metanorma::Utils::set_nested_value(bib, key.split("."), val)
68
76
  end
69
77
 
70
78
  # definition list, with at most one level of unordered lists
@@ -73,14 +81,16 @@ module Asciidoctor
73
81
  bib = {}
74
82
  key = ""
75
83
  dl.xpath("./dt | ./dd").each do |dtd|
76
- dtd.name == "dt" and key = dtd.text.sub(/:+$/, "") or add_to_hash(bib, key, dd_bib_extract(dtd))
84
+ (dtd.name == "dt" and key = dtd.text.sub(/:+$/, "")) or
85
+ add_to_hash(bib, key, dd_bib_extract(dtd))
77
86
  end
78
87
  c.xpath("./clause").each do |c1|
79
88
  key = c1&.at("./title")&.text&.downcase&.strip
80
89
  next unless %w(contributor relation series).include? key
90
+
81
91
  add_to_hash(bib, key, dl_bib_extract(c1, true))
82
92
  end
83
- if !nested and c.at("./title")
93
+ if !nested && c.at("./title")
84
94
  title = c.at("./title").remove.children.to_xml
85
95
  bib["title"] = [bib["title"]] if bib["title"].is_a? Hash
86
96
  bib["title"] = [bib["title"]] if bib["title"].is_a? String
@@ -48,10 +48,10 @@ module Asciidoctor
48
48
  end
49
49
 
50
50
  def requirement_description_wrap(reqt, text)
51
- return if text.element? && (reqt_subpart(text.name) ||
51
+ return if (text.element? && (reqt_subpart(text.name) ||
52
52
  %w(requirement recommendation
53
- permission).include?(text.name)) ||
54
- text.text.strip.empty?
53
+ permission).include?(text.name))) ||
54
+ (text.text.strip.empty? && !text.at(".//xref | .//eref | .//link"))
55
55
 
56
56
  t = Nokogiri::XML::Element.new("description", reqt)
57
57
  text.before(t)
@@ -21,7 +21,7 @@ module Asciidoctor
21
21
  title = get_or_make_title(node)
22
22
  fn = title.xpath("./fn")
23
23
  fn.each(&:remove)
24
- title.content = text
24
+ title.children = text
25
25
  fn.each { |n| title << n }
26
26
  end
27
27
  end
@@ -82,7 +82,7 @@ module Asciidoctor
82
82
  p.delete("id")
83
83
  p.delete("variant_title")
84
84
  p.xpath("(#{path})[last()]").each do |sect|
85
- ins = sect.at("./title") and ins.next = p or
85
+ (ins = sect.at("./title") and ins.next = p) or
86
86
  sect.children.first.previous = p
87
87
  end
88
88
  end
@@ -6,14 +6,16 @@ module Asciidoctor
6
6
  module Cleanup
7
7
  def termdomain_cleanup(xmldoc)
8
8
  xmldoc.xpath("//p/domain").each do |a|
9
- prev = a.parent.previous
9
+ parent = a.parent
10
+ prev = parent.previous
10
11
  prev.next = a.remove
12
+ parent.text.strip.empty? and parent.remove
11
13
  end
12
14
  end
13
15
 
14
16
  def termdomain1_cleanup(xmldoc)
15
17
  xmldoc.xpath("//term").each do |t|
16
- d = t.xpath("./domain | ./subject | ./usageinfo").last or next
18
+ d = t.xpath("./domain | ./subject").last or next
17
19
  defn = d.at("../definition") and defn.previous = d.remove
18
20
  end
19
21
  end
@@ -21,32 +23,46 @@ module Asciidoctor
21
23
  def termdefinition_cleanup(xmldoc)
22
24
  generate_termdefinitions(xmldoc)
23
25
  split_termdefinitions(xmldoc)
26
+ alternate_termdefinitions(xmldoc)
24
27
  end
25
28
 
29
+ TERMDEF_BLOCKS =
30
+ "./p | ./ol | ./dl[not(@metadata = 'true')] | ./ul | ./figure | "\
31
+ "./formula | ./table".freeze
32
+
26
33
  def generate_termdefinitions(xmldoc)
27
34
  xmldoc.xpath("//term[not(definition)]").each do |d|
28
- first_child = d.at("./p | ./figure | ./formula | ./table") || next
35
+ first_child = d.at(TERMDEF_BLOCKS) || next
29
36
  t = Nokogiri::XML::Element.new("definition", xmldoc)
30
37
  first_child.replace(t)
31
38
  t << first_child.remove
32
- d.xpath("./p | ./figure | ./formula | ./table").each { |n| t << n.remove }
39
+ d.xpath(TERMDEF_BLOCKS).each do |n|
40
+ t << n.remove
41
+ end
33
42
  end
34
43
  end
35
44
 
36
45
  def split_termdefinitions(xmldoc)
37
46
  xmldoc.xpath("//definition").each do |d|
38
- n = d.children.first.add_previous_sibling("<nonverbalrepresentation/>").first
39
- v = d.children.first.add_previous_sibling("<verbaldefinition/>").first
40
- nonverb = false
41
- d.elements.each do |e|
42
- case e.name
43
- when "nonverbalrepresentation", "verbaldefinition" then next
44
- when "figure", "table", "formula"
45
- n << e.remove
46
- nonverb = true
47
- when "termsource"
48
- (nonverb ? n : v) << e.remove
49
- else v << e.remove
47
+ if d.at("./p | ./ol | ./dl | ./ul")
48
+ d.children = "<verbal-definition>#{d.children}</verbal-definition>"
49
+ else
50
+ d.children = "<non-verbal-representation>"\
51
+ "#{d.children}</non-verbal-representation>"
52
+ end
53
+ end
54
+ end
55
+
56
+ def alternate_termdefinitions(xmldoc)
57
+ xmldoc.xpath("//term").each do |t|
58
+ t.xpath("./definition").each do |d|
59
+ d1 = d.next_element or next
60
+ if (v = d.at("./verbal-definition")) &&
61
+ !d.at("./non-verbal-representation") &&
62
+ !d1.at("./verbal-definition") &&
63
+ nv = d1.at("./non-verbal-representation")
64
+ v.next = nv.remove
65
+ d1.remove
50
66
  end
51
67
  end
52
68
  end
@@ -60,7 +76,7 @@ module Asciidoctor
60
76
  def term_children_cleanup(xmldoc)
61
77
  xmldoc.xpath("//terms[terms]").each { |t| t.name = "clause" }
62
78
  xmldoc.xpath("//term").each do |t|
63
- %w(termnote termexample termsource).each do |w|
79
+ %w(termnote termexample termsource term).each do |w|
64
80
  t.xpath("./#{w}").each { |n| t << n.remove }
65
81
  end
66
82
  end
@@ -76,9 +92,9 @@ module Asciidoctor
76
92
 
77
93
  def termnote_example_cleanup(xmldoc)
78
94
  %w(note example).each do |w|
79
- xmldoc.xpath("//term#{w}[not(ancestor::term)]").each do |x|
80
- x.name = w
81
- end
95
+ xmldoc.xpath("//term#{w}[not(ancestor::term)]").each do |x|
96
+ x.name = w
97
+ end
82
98
  end
83
99
  end
84
100
 
@@ -90,14 +106,35 @@ module Asciidoctor
90
106
  term_termsource_to_designation(xmldoc)
91
107
  term_designation_reorder(xmldoc)
92
108
  termdef_from_termbase(xmldoc)
93
- termdef_stem_cleanup(xmldoc)
94
109
  termdomain_cleanup(xmldoc)
110
+ termdef_stem_cleanup(xmldoc)
95
111
  termdefinition_cleanup(xmldoc)
96
112
  termdomain1_cleanup(xmldoc)
97
113
  termnote_example_cleanup(xmldoc)
98
114
  term_children_cleanup(xmldoc)
99
115
  termdocsource_cleanup(xmldoc)
100
116
  end
117
+
118
+ def index_cleanup(xmldoc)
119
+ return unless @index_terms
120
+
121
+ xmldoc.xpath("//preferred").each do |p|
122
+ index_cleanup1(p.at("./expression/name | ./letter-symbol/name"),
123
+ p.xpath("./field-of-application | ./usage-info")
124
+ &.map(&:text)&.join(", "))
125
+ end
126
+ xmldoc.xpath("//definitions/dl/dt").each do |p|
127
+ index_cleanup1(p, "")
128
+ end
129
+ end
130
+
131
+ def index_cleanup1(term, fieldofappl)
132
+ return unless term
133
+
134
+ idx = term.children.dup
135
+ fieldofappl.empty? or idx << ", &#x3c;#{fieldofappl}&#x3e;"
136
+ term << "<index><primary>#{idx.to_xml}</primary></index>"
137
+ end
101
138
  end
102
139
  end
103
140
  end