isodoc 1.7.6.1 → 1.8.2

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 (43) hide show
  1. checksums.yaml +4 -4
  2. data/isodoc.gemspec +2 -2
  3. data/lib/isodoc/class_utils.rb +24 -1
  4. data/lib/isodoc/convert.rb +9 -0
  5. data/lib/isodoc/function/cleanup.rb +4 -0
  6. data/lib/isodoc/function/inline.rb +3 -5
  7. data/lib/isodoc/html_function/html.rb +1 -0
  8. data/lib/isodoc/html_function/postprocess.rb +4 -6
  9. data/lib/isodoc/metadata_date.rb +13 -11
  10. data/lib/isodoc/presentation_function/bibdata.rb +2 -2
  11. data/lib/isodoc/presentation_function/block.rb +0 -36
  12. data/lib/isodoc/presentation_function/inline.rb +14 -11
  13. data/lib/isodoc/presentation_function/terms.rb +223 -0
  14. data/lib/isodoc/presentation_xml_convert.rb +11 -4
  15. data/lib/isodoc/version.rb +1 -1
  16. data/lib/isodoc/word_function/body.rb +24 -14
  17. data/lib/isodoc/word_function/comments.rb +0 -4
  18. data/lib/isodoc/word_function/postprocess.rb +184 -176
  19. data/lib/isodoc/xref/xref_gen.rb +18 -22
  20. data/lib/isodoc/xref/xref_gen_seq.rb +10 -16
  21. data/lib/isodoc/xref/xref_sect_gen.rb +134 -129
  22. data/lib/isodoc/xslfo_convert.rb +11 -7
  23. data/lib/isodoc-yaml/i18n-ar.yaml +25 -0
  24. data/lib/isodoc-yaml/i18n-de.yaml +23 -0
  25. data/lib/isodoc-yaml/i18n-en.yaml +23 -0
  26. data/lib/isodoc-yaml/i18n-es.yaml +23 -0
  27. data/lib/isodoc-yaml/i18n-fr.yaml +23 -0
  28. data/lib/isodoc-yaml/i18n-ru.yaml +24 -1
  29. data/lib/isodoc-yaml/i18n-zh-Hans.yaml +24 -0
  30. data/lib/metanorma/output/xslfo.rb +4 -11
  31. data/spec/assets/i18n.yaml +3 -1
  32. data/spec/isodoc/blocks_spec.rb +14 -8
  33. data/spec/isodoc/i18n_spec.rb +23 -18
  34. data/spec/isodoc/inline_spec.rb +193 -9
  35. data/spec/isodoc/lists_spec.rb +344 -222
  36. data/spec/isodoc/section_spec.rb +23 -22
  37. data/spec/isodoc/table_spec.rb +71 -73
  38. data/spec/isodoc/terms_spec.rb +498 -124
  39. data/spec/isodoc/xref_numbering_spec.rb +347 -0
  40. data/spec/isodoc/xref_spec.rb +274 -353
  41. data/spec/isodoc/xslfo_convert_spec.rb +34 -9
  42. metadata +12 -11
  43. data/lib/isodoc/presentation_function/concept.rb +0 -68
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 411fdbd359b728afea9bcab7225c1e79a2a2698dd37c6219c70a1434cfa09286
4
- data.tar.gz: 05a4997c47971d8cc74985ea8a0cf7b4e2c0d0e15a144e68eae007ce24176c9a
3
+ metadata.gz: 38ce5f3d119cf53361811f16b0ff8ed4108116c02e0816ab5ba31846934c3c29
4
+ data.tar.gz: 5ffb61e6729edb93e5e3ba1916e531bf7e1511bfdbd5fe0e0cd1405590971c4d
5
5
  SHA512:
6
- metadata.gz: 7db1599bdd9d90aada565fbb02d4744a1ac85de0798c2dfd33d2b76905e5f40894042df0e0131a282fa669509f590cf471285188f6dd8e3c091d3bf6c0809bb3
7
- data.tar.gz: cd90f9f57aa3ccd37d59d7ebc14438dd37c8812e3d131d7d82618499bfd69c25f660716a508621f536e72a68b942571347fb7218a746c42e61296e4e7fef3da8
6
+ metadata.gz: e023cfd0d05068daf11e4ccf5c6aab29ff037ec562b65e65f769f7d64c9d4a6c681895dfba5539a2b8a8ee310facba56dad371a21a5f0ced621ebacbf64a8ddf
7
+ data.tar.gz: 6412c5b7f2b11c4eedf1ab840461a703d1342e148ae89607ea30bb7faff05591aa33132dd2a1b660a92a0e3466060ef404cab4564c5a10bd909843293b4c9ad1
data/isodoc.gemspec CHANGED
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
30
30
 
31
31
  spec.add_dependency "asciimath"
32
- spec.add_dependency "html2doc", "~> 1.1.1"
32
+ spec.add_dependency "html2doc", "~> 1.2.0"
33
33
  spec.add_dependency "htmlentities", "~> 4.3.4"
34
34
  spec.add_dependency "liquid", "~> 4"
35
35
  # spec.add_dependency "metanorma", ">= 1.2.0"
@@ -43,7 +43,7 @@ Gem::Specification.new do |spec|
43
43
  spec.add_dependency "twitter_cldr", ">= 6.6.0"
44
44
  spec.add_dependency "uuidtools"
45
45
 
46
- spec.add_development_dependency "byebug", "~> 9.1"
46
+ spec.add_development_dependency "debug"
47
47
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
48
48
  spec.add_development_dependency "guard", "~> 2.14"
49
49
  spec.add_development_dependency "guard-rspec", "~> 4.7"
@@ -16,7 +16,7 @@ module IsoDoc
16
16
  xpath.gsub(%r{/([a-zA-z])}, "/xmlns:\\1")
17
17
  .gsub(%r{::([a-zA-z])}, "::xmlns:\\1")
18
18
  .gsub(%r{\[([a-zA-z][a-z0-9A-Z@/]* ?=)}, "[xmlns:\\1")
19
- .gsub(%r{\[([a-zA-z][a-z0-9A-Z@/]*\])}, "[xmlns:\\1")
19
+ .gsub(%r{\[([a-zA-z][a-z0-9A-Z@/]*[/\]])}, "[xmlns:\\1")
20
20
  end
21
21
 
22
22
  def liquid(doc)
@@ -27,5 +27,28 @@ module IsoDoc
27
27
  end.join
28
28
  Liquid::Template.parse(doc)
29
29
  end
30
+
31
+ def case_strict(text, casing, script)
32
+ return text unless %w(Latn Cyrl Grek Armn).include?(script)
33
+
34
+ letters = text.chars
35
+ case casing
36
+ when "capital" then letters.first.upcase!
37
+ when "lowercase" then letters.first.downcase!
38
+ end
39
+ letters.join
40
+ end
41
+
42
+ def case_with_markup(linkend, casing, script)
43
+ seen = false
44
+ xml = Nokogiri::XML("<root>#{linkend}</root>")
45
+ xml.traverse do |b|
46
+ next unless b.text? && !seen
47
+
48
+ b.replace(Common::case_strict(b.text, casing, script))
49
+ seen = true
50
+ end
51
+ xml.root.children.to_xml
52
+ end
30
53
  end
31
54
  end
@@ -102,6 +102,7 @@ module IsoDoc
102
102
  @bookmarks_allocated = { "X" => true }
103
103
  @fn_bookmarks = {}
104
104
  @baseassetpath = options[:baseassetpath]
105
+ @aligncrosselements = options[:aligncrosselements]
105
106
  end
106
107
 
107
108
  def tmpimagedir_suffix
@@ -118,6 +119,7 @@ module IsoDoc
118
119
 
119
120
  def convert1(docxml, filename, dir)
120
121
  @xrefs.parse docxml
122
+ bibitem_lookup(docxml)
121
123
  noko do |xml|
122
124
  xml.html **{ lang: @lang.to_s } do |html|
123
125
  html.parent.add_namespace("epub", "http://www.idpf.org/2007/ops")
@@ -129,6 +131,13 @@ module IsoDoc
129
131
  end.join("\n")
130
132
  end
131
133
 
134
+ def bibitem_lookup(docxml)
135
+ @bibitems = docxml.xpath(ns("//references/bibitem"))
136
+ .each_with_object({}) do |b, m|
137
+ m[b["id"]] = b
138
+ end
139
+ end
140
+
132
141
  def metadata_init(lang, script, i18n)
133
142
  @meta = Metadata.new(lang, script, i18n)
134
143
  end
@@ -165,6 +165,10 @@ module IsoDoc
165
165
  t << a.remove
166
166
  end
167
167
  end
168
+ table_footnote_cleanup_propagate(docxml)
169
+ end
170
+
171
+ def table_footnote_cleanup_propagate(docxml)
168
172
  docxml.xpath("//p[not(self::*[@class])]"\
169
173
  "[ancestor::*[@class = 'TableFootnote']]").each do |p|
170
174
  p["class"] = "TableFootnote"
@@ -5,7 +5,7 @@ module IsoDoc
5
5
  module Inline
6
6
  def link_parse(node, out)
7
7
  url = node["target"]
8
- node["updatetype"] == "true" and url = suffix_url(url)
8
+ node["update-type"] == "true" and url = suffix_url(url)
9
9
  out.a **attr_code(href: url, title: node["alt"]) do |l|
10
10
  if node.text.empty?
11
11
  l << node["target"].sub(/^mailto:/, "")
@@ -41,10 +41,8 @@ module IsoDoc
41
41
  end
42
42
 
43
43
  def eref_target(node)
44
- href = "##{node['bibitemid']}"
45
- url = node.at(ns("//bibitem[@id = '#{node['bibitemid']}']/"\
46
- "uri[@type = 'citation']"))
47
- return href unless url
44
+ return "##{node['bibitemid']}" unless url = @bibitems[node["bibitemid"]]
45
+ &.at(ns("./uri[@type = 'citation']"))
48
46
 
49
47
  href = suffix_url(url.text)
50
48
  anchor = node&.at(ns(".//locality[@type = 'anchor']"))&.text&.strip
@@ -5,6 +5,7 @@ module IsoDoc
5
5
  module HtmlFunction
6
6
  module Html
7
7
  def convert1(docxml, filename, dir)
8
+ bibitem_lookup(docxml)
8
9
  noko do |xml|
9
10
  xml.html **{ lang: @lang.to_s } do |html|
10
11
  info docxml, nil
@@ -1,5 +1,6 @@
1
1
  require "isodoc/html_function/mathvariant_to_plain"
2
2
  require_relative "postprocess_footnotes"
3
+ require "metanorma-utils"
3
4
 
4
5
  module IsoDoc
5
6
  module HtmlFunction
@@ -74,7 +75,8 @@ module IsoDoc
74
75
  head = docxml.at("//*[local-name() = 'head']")
75
76
  head << htmlstylesheet(@htmlstylesheet)
76
77
  s = htmlstylesheet(@htmlstylesheet_override) and head << s
77
- @bare and head << "<style>body {margin-left: 2em; margin-right: 2em;}</style>"
78
+ @bare and
79
+ head << "<style>body {margin-left: 2em; margin-right: 2em;}</style>"
78
80
  docxml
79
81
  end
80
82
 
@@ -167,11 +169,7 @@ module IsoDoc
167
169
  end
168
170
 
169
171
  def datauri(img)
170
- type = img["src"].split(".")[-1]
171
- supertype = type == "xml" ? "application" : "image"
172
- bin = IO.binread(image_localfile(img))
173
- data = Base64.strict_encode64(bin)
174
- img["src"] = "data:#{supertype}/#{type};base64,#{data}"
172
+ img["src"] = Metanorma::Utils::datauri(img["src"], @localdir)
175
173
  end
176
174
 
177
175
  def image_suffix(img)
@@ -6,7 +6,7 @@ module IsoDoc
6
6
  vote-ended}.freeze
7
7
 
8
8
  def months
9
- {
9
+ {
10
10
  "01": @labels["month_january"],
11
11
  "02": @labels["month_february"],
12
12
  "03": @labels["month_march"],
@@ -19,30 +19,32 @@ module IsoDoc
19
19
  "10": @labels["month_october"],
20
20
  "11": @labels["month_november"],
21
21
  "12": @labels["month_december"],
22
- }
22
+ }
23
23
  end
24
24
 
25
25
  def monthyr(isodate)
26
26
  m = /(?<yr>\d\d\d\d)-(?<mo>\d\d)/.match isodate
27
27
  return isodate unless m && m[:yr] && m[:mo]
28
+
28
29
  l10n("#{months[m[:mo].to_sym]} #{m[:yr]}",
29
- @lang, @script)
30
+ @lang, @script)
30
31
  end
31
32
 
32
33
  def MMMddyyyy(isodate)
33
34
  return nil if isodate.nil?
35
+
34
36
  arr = isodate.split("-")
35
- date = if arr.size == 1 and (/^\d+$/.match isodate)
36
- Date.new(*arr.map(&:to_i)).strftime("%Y")
37
- elsif arr.size == 2
38
- Date.new(*arr.map(&:to_i)).strftime("%B %Y")
39
- else
40
- Date.parse(isodate).strftime("%B %d, %Y")
41
- end
37
+ if arr.size == 1 && (/^\d+$/.match isodate)
38
+ Date.new(*arr.map(&:to_i)).strftime("%Y")
39
+ elsif arr.size == 2
40
+ Date.new(*arr.map(&:to_i)).strftime("%B %Y")
41
+ else
42
+ Date.parse(isodate).strftime("%B %d, %Y")
43
+ end
42
44
  end
43
45
 
44
46
  def bibdate(isoxml, _out)
45
- isoxml.xpath(ns('//bibdata/date')).each do |d|
47
+ isoxml.xpath(ns("//bibdata/date")).each do |d|
46
48
  set("#{d['type'].gsub(/-/, '_')}date".to_sym, Common::date_range(d))
47
49
  end
48
50
  end
@@ -10,7 +10,7 @@ module IsoDoc
10
10
  "</localized-strings>"
11
11
  end
12
12
 
13
- def docid_prefixes(docxml)
13
+ def docid_prefixes(docxml)
14
14
  docxml.xpath(ns("//references/bibitem/docidentifier")).each do |i|
15
15
  i.children = @xrefs.klass.docid_prefix(i["type"], i.text)
16
16
  end
@@ -97,7 +97,7 @@ module IsoDoc
97
97
 
98
98
  # https://stackoverflow.com/a/31822406
99
99
  def blank?(elem)
100
- elem.nil? || elem.respond_to?(:empty?) && elem.empty?
100
+ elem.nil? || (elem.respond_to?(:empty?) && elem.empty?)
101
101
  end
102
102
 
103
103
  def trim_hash(hash)
@@ -54,12 +54,6 @@ module IsoDoc
54
54
  end
55
55
  end
56
56
 
57
- def termexample(docxml)
58
- docxml.xpath(ns("//termexample")).each do |f|
59
- example1(f)
60
- end
61
- end
62
-
63
57
  def example1(elem)
64
58
  n = @xrefs.get[elem["id"]]
65
59
  lbl = if n.nil? || n[:label].nil? || n[:label].empty?
@@ -89,36 +83,6 @@ module IsoDoc
89
83
  prefix_name(elem, "", lbl, "name")
90
84
  end
91
85
 
92
- def termnote(docxml)
93
- docxml.xpath(ns("//termnote")).each do |f|
94
- termnote1(f)
95
- end
96
- end
97
-
98
- # introduce name element
99
- def termnote1(elem)
100
- lbl = l10n(@xrefs.anchor(elem["id"], :label) || "???")
101
- prefix_name(elem, "", lower2cap(lbl), "name")
102
- end
103
-
104
- def termdefinition(docxml)
105
- docxml.xpath(ns("//term[definition]")).each do |f|
106
- termdefinition1(f)
107
- end
108
- end
109
-
110
- def termdefinition1(elem)
111
- return unless elem.xpath(ns("./definition")).size > 1
112
-
113
- d = elem.at(ns("./definition"))
114
- d = d.replace("<ol><li>#{d.children.to_xml}</li></ol>").first
115
- elem.xpath(ns("./definition")).each do |f|
116
- f = f.replace("<li>#{f.children.to_xml}</li>").first
117
- d << f
118
- end
119
- d.wrap("<definition></definition>")
120
- end
121
-
122
86
  def recommendation(docxml)
123
87
  docxml.xpath(ns("//recommendation")).each do |f|
124
88
  recommendation1(f, lower2cap(@i18n.recommendation))
@@ -1,5 +1,4 @@
1
1
  require "metanorma-utils"
2
- require_relative "./concept"
3
2
 
4
3
  module IsoDoc
5
4
  class PresentationXMLConvert < ::IsoDoc::Convert
@@ -7,13 +6,16 @@ module IsoDoc
7
6
  l10n("#{@xrefs.anchor(container, :xref)}, #{linkend}")
8
7
  end
9
8
 
9
+ def anchor_value(id)
10
+ @xrefs.anchor(id, :value) || @xrefs.anchor(id, :label) ||
11
+ @xrefs.anchor(id, :xref)
12
+ end
13
+
10
14
  def anchor_linkend(node, linkend)
11
15
  if node["citeas"].nil? && node["bibitemid"]
12
16
  return @xrefs.anchor(node["bibitemid"], :xref) || "???"
13
17
  elsif node["target"] && node["droploc"]
14
- return @xrefs.anchor(node["target"], :value) ||
15
- @xrefs.anchor(node["target"], :label) ||
16
- @xrefs.anchor(node["target"], :xref) || "???"
18
+ return anchor_value(node["target"]) || "???"
17
19
  elsif node["target"] && !/.#./.match(node["target"])
18
20
  linkend = anchor_linkend1(node)
19
21
  end
@@ -27,14 +29,15 @@ module IsoDoc
27
29
  (container && get_note_container_id(node) != container &&
28
30
  @xrefs.get[node["target"]]) and
29
31
  linkend = prefix_container(container, linkend, node["target"])
30
- capitalise_xref(node, linkend)
32
+ capitalise_xref(node, linkend, anchor_value(node["target"]))
31
33
  end
32
34
 
33
- def capitalise_xref(node, linkend)
34
- return linkend unless %w(Latn Cyrl Grek).include? @script
35
- return linkend&.capitalize if node["case"] == "capital"
36
- return linkend&.downcase if node["case"] == "lowercase"
37
- return linkend if linkend[0, 1].match?(/\p{Upper}/)
35
+ def capitalise_xref(node, linkend, label)
36
+ linktext = linkend.gsub(/<[^>]+>/, "")
37
+ (label && !label.empty? && /^#{Regexp.escape(label)}/.match?(linktext)) ||
38
+ linktext[0, 1].match?(/\p{Upper}/) and return linkend
39
+ node["case"] and
40
+ return Common::case_with_markup(linkend, node["case"], @script)
38
41
 
39
42
  capitalise_xref1(node, linkend)
40
43
  end
@@ -43,7 +46,7 @@ module IsoDoc
43
46
  prec = nearest_block_parent(node).xpath("./descendant-or-self::text()") &
44
47
  node.xpath("./preceding::text()")
45
48
  if prec.empty? || /(?!<[^.].)\.\s+$/.match(prec.map(&:text).join)
46
- linkend&.capitalize
49
+ Common::case_with_markup(linkend, "capital", @script)
47
50
  else linkend
48
51
  end
49
52
  end
@@ -0,0 +1,223 @@
1
+ module IsoDoc
2
+ class PresentationXMLConvert < ::IsoDoc::Convert
3
+ def concept(docxml)
4
+ docxml.xpath(ns("//concept")).each { |f| concept1(f) }
5
+ end
6
+
7
+ def concept1(node)
8
+ xref = node&.at(ns("./xref/@target"))&.text or
9
+ return concept_render(node, ital: node["ital"] || "true",
10
+ ref: node["ref"] || "true",
11
+ linkref: node["linkref"] || "true",
12
+ linkmention: node["linkmention"] || "false")
13
+ if node.at(ns("//definitions//dt[@id = '#{xref}']"))
14
+ concept_render(node, ital: node["ital"] || "false",
15
+ ref: node["ref"] || "false",
16
+ linkref: node["linkref"] || "true",
17
+ linkmention: node["linkmention"] || "false")
18
+ else concept_render(node, ital: node["ital"] || "true",
19
+ ref: node["ref"] || "true",
20
+ linkref: node["linkref"] || "true",
21
+ linkmention: node["linkmention"] || "false")
22
+ end
23
+ end
24
+
25
+ def concept_render(node, opts)
26
+ node&.at(ns("./refterm"))&.remove
27
+ r = node.at(ns("./renderterm"))
28
+ ref = node.at(ns("./xref | ./eref | ./termref"))
29
+ ref && opts[:ref] != "false" and r&.next = " "
30
+ opts[:ital] == "true" and r&.name = "em"
31
+ concept1_linkmention(ref, r, opts)
32
+ concept1_ref(node, ref, opts)
33
+ if opts[:ital] == "false"
34
+ r = node.at(ns(".//renderterm"))
35
+ r&.replace(r&.children)
36
+ end
37
+ node.replace(node.children)
38
+ end
39
+
40
+ def concept1_linkmention(ref, renderterm, opts)
41
+ if opts[:linkmention] == "true" && !renderterm.nil? && !ref.nil?
42
+ ref2 = ref.clone
43
+ r2 = renderterm.clone
44
+ renderterm.replace(ref2).children = r2
45
+ end
46
+ end
47
+
48
+ def concept1_ref(_node, ref, opts)
49
+ ref.nil? and return
50
+ return ref.remove if opts[:ref] == "false"
51
+
52
+ r = concept1_ref_content(ref)
53
+ ref = r.at("./descendant-or-self::xmlns:xref | "\
54
+ "./descendant-or-self::xmlns:eref | "\
55
+ "./descendant-or-self::xmlns:termref")
56
+ %w(xref eref).include? ref&.name and get_linkend(ref)
57
+ if opts[:linkref] == "false" && %w(xref eref).include?(ref&.name)
58
+ ref.replace(ref.children)
59
+ end
60
+ end
61
+
62
+ def concept1_ref_content(ref)
63
+ if non_locality_elems(ref).select do |c|
64
+ !c.text? || /\S/.match(c)
65
+ end.empty?
66
+ ref.replace(@i18n.term_defined_in.sub(/%/,
67
+ ref.to_xml))
68
+ else ref.replace("[#{ref.to_xml}]")
69
+ end
70
+ end
71
+
72
+ def related(docxml)
73
+ docxml.xpath(ns("//related")).each { |f| related1(f) }
74
+ end
75
+
76
+ def related1(node)
77
+ p = node.at(ns("./preferred"))
78
+ ref = node.at(ns("./xref | ./eref | ./termref"))
79
+ label = @i18n.relatedterms[node["type"]].upcase
80
+ node.replace(l10n("<p><strong>#{label}:</strong> "\
81
+ "<em>#{p.to_xml}</em> (#{ref.to_xml})</p>"))
82
+ end
83
+
84
+ def designation(docxml)
85
+ docxml.xpath(ns("//term")).each do |t|
86
+ merge_second_preferred(t)
87
+ end
88
+ docxml.xpath(ns("//preferred | //admitted | //deprecates")).each do |p|
89
+ designation1(p)
90
+ end
91
+ end
92
+
93
+ def merge_second_preferred(term)
94
+ pref = nil
95
+ term.xpath(ns("./preferred[expression/name]")).each_with_index do |p, i|
96
+ if i.zero? then pref = p
97
+ elsif merge_preferred_eligible?(pref, p)
98
+ pref.at(ns("./expression/name")) <<
99
+ l10n("; #{p.at(ns('./expression/name')).children.to_xml}")
100
+ p.remove
101
+ end
102
+ end
103
+ end
104
+
105
+ def merge_preferred_eligible?(first, second)
106
+ firstex = first.at(ns("./expression")) || {}
107
+ secondex = second.at(ns("./expression")) || {}
108
+ first["geographic-area"] == second["geographic-area"] &&
109
+ firstex["language"] == secondex["language"] &&
110
+ !first.at(ns("./pronunciation | ./grammar")) &&
111
+ !second.at(ns("./pronunciation | ./grammar"))
112
+ end
113
+
114
+ def designation1(desgn)
115
+ s = desgn.at(ns("./termsource"))
116
+ name = desgn.at(ns("./expression/name | ./letter-symbol/name | "\
117
+ "./graphical-symbol")) or return
118
+
119
+ designation_annotate(desgn, name)
120
+ s and desgn.next = s
121
+ end
122
+
123
+ def designation_annotate(desgn, name)
124
+ designation_boldface(desgn)
125
+ designation_field(desgn, name)
126
+ g = desgn.at(ns("./expression/grammar")) and
127
+ name << ", #{designation_grammar(g).join(', ')}"
128
+ designation_localization(desgn, name)
129
+ designation_pronunciation(desgn, name)
130
+ desgn.children = name.children
131
+ end
132
+
133
+ def designation_boldface(desgn)
134
+ desgn.name == "preferred" or return
135
+ name = desgn.at(ns("./expression/name | ./letter-symbol/name")) or return
136
+ name.children = "<strong>#{name.children}</strong>"
137
+ end
138
+
139
+ def designation_field(desgn, name)
140
+ f = desgn.xpath(ns("./field-of-application | ./usage-info"))
141
+ &.map { |u| u.children.to_xml }&.join(", ")
142
+ return nil if f&.empty?
143
+
144
+ name << ", &lt;#{f}&gt;"
145
+ end
146
+
147
+ def designation_grammar(grammar)
148
+ ret = []
149
+ grammar.xpath(ns("./gender | ./number")).each do |x|
150
+ ret << @i18n.grammar_abbrevs[x.text]
151
+ end
152
+ %w(isPreposition isParticiple isAdjective isVerb isAdverb isNoun)
153
+ .each do |x|
154
+ grammar.at(ns("./#{x}[text() = 'true']")) and
155
+ ret << @i18n.grammar_abbrevs[x]
156
+ end
157
+ ret
158
+ end
159
+
160
+ def designation_localization(desgn, name)
161
+ loc = [desgn&.at(ns("./expression/@language"))&.text,
162
+ desgn&.at(ns("./expression/@script"))&.text,
163
+ desgn&.at(ns("./@geographic-area"))&.text].compact
164
+ return if loc.empty?
165
+
166
+ name << ", #{loc.join(' ')}"
167
+ end
168
+
169
+ def designation_pronunciation(desgn, name)
170
+ f = desgn.at(ns("./expression/pronunciation")) or return
171
+
172
+ name << ", /#{f.children.to_xml}/"
173
+ end
174
+
175
+ def termexample(docxml)
176
+ docxml.xpath(ns("//termexample")).each do |f|
177
+ example1(f)
178
+ end
179
+ end
180
+
181
+ def termnote(docxml)
182
+ docxml.xpath(ns("//termnote")).each do |f|
183
+ termnote1(f)
184
+ end
185
+ end
186
+
187
+ # introduce name element
188
+ def termnote1(elem)
189
+ lbl = l10n(@xrefs.anchor(elem["id"], :label) || "???")
190
+ prefix_name(elem, "", lower2cap(lbl), "name")
191
+ end
192
+
193
+ def termdefinition(docxml)
194
+ docxml.xpath(ns("//term[definition]")).each do |f|
195
+ termdefinition1(f)
196
+ end
197
+ end
198
+
199
+ def termdefinition1(elem)
200
+ unwrap_definition(elem)
201
+ multidef(elem) if elem.xpath(ns("./definition")).size > 1
202
+ end
203
+
204
+ def multidef(elem)
205
+ d = elem.at(ns("./definition"))
206
+ d = d.replace("<ol><li>#{d.children.to_xml}</li></ol>").first
207
+ elem.xpath(ns("./definition")).each do |f|
208
+ f = f.replace("<li>#{f.children.to_xml}</li>").first
209
+ d << f
210
+ end
211
+ d.wrap("<definition></definition>")
212
+ end
213
+
214
+ def unwrap_definition(elem)
215
+ elem.xpath(ns("./definition")).each do |d|
216
+ %w(verbal-definition non-verbal-representation).each do |e|
217
+ v = d&.at(ns("./#{e}"))
218
+ v&.replace(v.children)
219
+ end
220
+ end
221
+ end
222
+ end
223
+ end
@@ -1,4 +1,5 @@
1
1
  require_relative "presentation_function/block"
2
+ require_relative "presentation_function/terms"
2
3
  require_relative "presentation_function/inline"
3
4
  require_relative "presentation_function/math"
4
5
  require_relative "presentation_function/section"
@@ -25,6 +26,7 @@ module IsoDoc
25
26
  @xrefs.parse docxml
26
27
  section docxml
27
28
  block docxml
29
+ terms docxml
28
30
  inline docxml
29
31
  end
30
32
 
@@ -46,17 +48,13 @@ module IsoDoc
46
48
  sourcecode docxml
47
49
  formula docxml
48
50
  example docxml
49
- termexample docxml
50
51
  note docxml
51
- termnote docxml
52
- termdefinition docxml
53
52
  permission docxml
54
53
  requirement docxml
55
54
  recommendation docxml
56
55
  end
57
56
 
58
57
  def inline(docxml)
59
- concept docxml
60
58
  xref docxml
61
59
  eref docxml
62
60
  origin docxml
@@ -65,6 +63,15 @@ module IsoDoc
65
63
  variant docxml
66
64
  end
67
65
 
66
+ def terms(docxml)
67
+ termexample docxml
68
+ termnote docxml
69
+ termdefinition docxml
70
+ designation docxml
71
+ concept docxml
72
+ related docxml
73
+ end
74
+
68
75
  def postprocess(result, filename, _dir)
69
76
  toXML(result, filename)
70
77
  @files_to_delete.each { |f| FileUtils.rm_rf f }
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "1.7.6.1".freeze
2
+ VERSION = "1.8.2".freeze
3
3
  end