metanorma-standoc 1.11.0 → 1.11.3

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/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 +50 -19
  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 +1 -1
  17. data/lib/asciidoctor/standoc/inline.rb +13 -11
  18. data/lib/asciidoctor/standoc/isodoc.rng +68 -18
  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 +18 -7
  23. data/lib/asciidoctor/standoc/render.rb +117 -0
  24. data/lib/asciidoctor/standoc/reqt.rb +1 -1
  25. data/lib/asciidoctor/standoc/section.rb +20 -15
  26. data/lib/asciidoctor/standoc/utils.rb +0 -16
  27. data/lib/asciidoctor/standoc/validate.rb +1 -1
  28. data/lib/isodoc/html/htmlstyle.css +1 -1
  29. data/lib/isodoc/html/htmlstyle.scss +1 -1
  30. data/lib/metanorma/standoc/version.rb +1 -1
  31. data/metanorma-standoc.gemspec +3 -3
  32. data/spec/asciidoctor/blocks_spec.rb +99 -17
  33. data/spec/asciidoctor/cleanup_blocks_spec.rb +24 -0
  34. data/spec/asciidoctor/cleanup_sections_spec.rb +1 -1
  35. data/spec/asciidoctor/cleanup_spec.rb +6 -6
  36. data/spec/asciidoctor/cleanup_terms_spec.rb +448 -89
  37. data/spec/asciidoctor/datamodel/attributes_table_preprocessor_spec.rb +21 -21
  38. data/spec/asciidoctor/datamodel/diagram_preprocessor_spec.rb +16 -16
  39. data/spec/asciidoctor/inline_spec.rb +5 -5
  40. data/spec/asciidoctor/isobib_cache_spec.rb +4 -8
  41. data/spec/asciidoctor/macros_spec.rb +2 -2
  42. data/spec/asciidoctor/refs_dl_spec.rb +4 -4
  43. data/spec/asciidoctor/refs_spec.rb +858 -498
  44. data/spec/asciidoctor/section_spec.rb +32 -3
  45. data/spec/spec_helper.rb +2 -2
  46. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +179 -179
  47. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec1.yml +14 -14
  48. data/spec/vcr_cassettes/isobib_get_123.yml +13 -13
  49. data/spec/vcr_cassettes/isobib_get_123_1.yml +96 -96
  50. data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +108 -108
  51. data/spec/vcr_cassettes/isobib_get_123_2001.yml +12 -12
  52. data/spec/vcr_cassettes/isobib_get_124.yml +13 -13
  53. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +18 -18
  54. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +46 -46
  55. metadata +9 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4c272a7b64955264d820737284d46d47a03d7baaf56d0a365396a5a2cb5455ac
4
- data.tar.gz: b04e30dd2633c21853ff81aaa14ddff65ddca564e4878a1914507ba7f4d43294
3
+ metadata.gz: 7756f8b45a6897bf3a40e48df348a746bc75b30820597fa8ceadedcbbceb89d9
4
+ data.tar.gz: e62b62dd699df95d46bd13c18656bf3504c3a34936ff0a094d224d12a9f44987
5
5
  SHA512:
6
- metadata.gz: 00117f839c229ac456a92d59ea8d7d17fbdb2dc680098126fc77c67696ae1c84cd70e3785a3b9e15c055588678a8d4a27fa1d2069431b38fa83c25fe20885d1d
7
- data.tar.gz: 78bf3e8ef72cc04f40c3a98cfbf29e14176f04ff1cbade1f299c9a3c284e303d481574f7f1b07ba7fa8cd769a32f6d05b745f550c43ea648c0d354ef3ae8d5ad
6
+ metadata.gz: 9776d2bfd161b5500e5ac9e8ea47a9597befe1642880a18fdc86839ceee0688e879d37de0bd9000420294f6a0094f455c840643e091a11da0b65489434a44bf9
7
+ data.tar.gz: 4f4d5f119ce92541ee1a89320fdc094352f3ca2ac885f1d52438279e4f70b995d0f87b4f7d034bafc63f05e2192b9ae8b7f4063dd1972525d773ec2f66e27dd1
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