isodoc 2.3.6 → 2.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,5 @@
1
1
  require_relative "./image"
2
+ require "rouge"
2
3
 
3
4
  module IsoDoc
4
5
  class PresentationXMLConvert < ::IsoDoc::Convert
@@ -25,24 +26,106 @@ module IsoDoc
25
26
  end
26
27
  end
27
28
 
29
+ def sourcehighlighter_theme
30
+ "igorpro"
31
+ end
32
+
33
+ def sourcehighlighter_css(docxml)
34
+ @sourcehighlighter or return
35
+ ins = docxml.at(ns("//misc-container")) ||
36
+ docxml.at(ns("//bibdata")).after("<misc-container/>").next_element
37
+ x = Rouge::Theme.find(sourcehighlighter_theme)
38
+ .render(scope: "sourcecode")
39
+ ins << "<source-highlighter-css>#{x}</source-highlighter-css>"
40
+ end
41
+
42
+ def sourcehighlighter
43
+ @sourcehighlighter or return
44
+ f = Rouge::Formatters::HTML.new
45
+ { formatter: f,
46
+ formatter_line: Rouge::Formatters::HTMLTable.new(f, {}) }
47
+ end
48
+
28
49
  def sourcecode(docxml)
50
+ sourcehighlighter_css(docxml)
51
+ @highlighter = sourcehighlighter
29
52
  docxml.xpath(ns("//sourcecode")).each do |f|
30
53
  sourcecode1(f)
31
54
  end
32
55
  end
33
56
 
34
57
  def sourcecode1(elem)
35
- return if labelled_ancestor(elem)
58
+ source_highlight(elem)
59
+ source_label(elem)
60
+ end
61
+
62
+ def source_highlight(elem)
63
+ @highlighter or return
64
+ markup = source_remove_markup(elem)
65
+ p = source_lex(elem)
66
+ wrapper, code =
67
+ if elem["linenums"] == "true" then sourcecode_table_to_elem(elem, p)
68
+ else
69
+ r = Nokogiri::XML.fragment(@highlighter[:formatter].format(p))
70
+ [r, r]
71
+ end
72
+ elem.children = source_restore_markup(wrapper, code, markup)
73
+ end
74
+
75
+ def source_remove_markup(elem)
76
+ ret = {}
77
+ name = elem.at(ns("./name")) and ret[:name] = name.remove.to_xml
78
+ ret[:ann] = elem.xpath(ns("./annotation")).each(&:remove)
79
+ ret[:call] = elem.xpath(ns("./callout")).each_with_object([]) do |c, m|
80
+ m << { xml: c.remove.to_xml, line: c.line - elem.line }
81
+ end
82
+ ret
83
+ end
84
+
85
+ def source_restore_markup(wrapper, code, markup)
86
+ text = source_restore_callouts(code, markup[:call])
87
+ ret = if code == wrapper
88
+ text
89
+ else
90
+ code.replace(text)
91
+ to_xml(wrapper)
92
+ end
93
+ "#{markup[:name]}#{ret}#{markup[:ann]}"
94
+ end
95
+
96
+ def source_restore_callouts(code, callouts)
97
+ text = to_xml(code)
98
+ text.split(/[\n\r]/).each_with_index do |c, i|
99
+ while !callouts.empty? && callouts[0][:line] == i
100
+ c.sub!(/\s+$/, " #{callouts[0][:xml]} ")
101
+ callouts.shift
102
+ end
103
+ end.join("\n")
104
+ end
36
105
 
106
+ def sourcecode_table_to_elem(elem, tokens)
107
+ r = Nokogiri::XML(@highlighter[:formatter_line].format(tokens)).root
108
+ pre = r.at(".//td[@class = 'rouge-code']/pre")
109
+ %w(style).each { |n| elem[n] and pre[n] = elem[n] }
110
+ pre.name = "sourcecode"
111
+ [r, pre]
112
+ end
113
+
114
+ def source_lex(elem)
115
+ l = (Rouge::Lexer.find(elem["lang"] || "plaintext") ||
116
+ Rouge::Lexer.find("plaintext"))
117
+ l.lex(@c.decode(elem.children.to_xml))
118
+ end
119
+
120
+ def source_label(elem)
121
+ labelled_ancestor(elem) and return
37
122
  lbl = @xrefs.anchor(elem["id"], :label, false) or return
38
123
  prefix_name(elem, block_delim,
39
124
  l10n("#{lower2cap @i18n.figure} #{lbl}"), "name")
40
125
  end
41
126
 
42
127
  def formula(docxml)
43
- docxml.xpath(ns("//formula")).each do |f|
44
- formula1(f)
45
- end
128
+ docxml.xpath(ns("//formula")).each { |f| formula1(f) }
46
129
  end
47
130
 
48
131
  def formula1(elem)
@@ -51,48 +134,38 @@ module IsoDoc
51
134
  end
52
135
 
53
136
  def example(docxml)
54
- docxml.xpath(ns("//example")).each do |f|
55
- example1(f)
56
- end
137
+ docxml.xpath(ns("//example")).each { |f| example1(f) }
57
138
  end
58
139
 
59
140
  def example1(elem)
60
141
  n = @xrefs.get[elem["id"]]
61
142
  lbl = if n.nil? || n[:label].nil? || n[:label].empty?
62
143
  @i18n.example
63
- else
64
- l10n("#{@i18n.example} #{n[:label]}")
144
+ else l10n("#{@i18n.example} #{n[:label]}")
65
145
  end
66
146
  prefix_name(elem, block_delim, lbl, "name")
67
147
  end
68
148
 
69
149
  def note(docxml)
70
- docxml.xpath(ns("//note")).each do |f|
71
- note1(f)
72
- end
150
+ docxml.xpath(ns("//note")).each { |f| note1(f) }
73
151
  end
74
152
 
75
153
  def note1(elem)
76
- return if elem.parent.name == "bibitem" || elem["notag"] == "true"
77
-
154
+ elem.parent.name == "bibitem" || elem["notag"] == "true" and return
78
155
  n = @xrefs.get[elem["id"]]
79
156
  lbl = if n.nil? || n[:label].nil? || n[:label].empty?
80
157
  @i18n.note
81
- else
82
- l10n("#{@i18n.note} #{n[:label]}")
158
+ else l10n("#{@i18n.note} #{n[:label]}")
83
159
  end
84
160
  prefix_name(elem, "", lbl, "name")
85
161
  end
86
162
 
87
163
  def admonition(docxml)
88
- docxml.xpath(ns("//admonition")).each do |f|
89
- admonition1(f)
90
- end
164
+ docxml.xpath(ns("//admonition")).each { |f| admonition1(f) }
91
165
  end
92
166
 
93
167
  def admonition1(elem)
94
- return if elem.at(ns("./name")) || elem["notag"] == "true"
95
-
168
+ elem.at(ns("./name")) || elem["notag"] == "true" and return
96
169
  prefix_name(elem, "", @i18n.admonition[elem["type"]]&.upcase, "name")
97
170
  end
98
171
 
@@ -121,15 +194,12 @@ module IsoDoc
121
194
  end
122
195
 
123
196
  def table(docxml)
124
- docxml.xpath(ns("//table")).each do |f|
125
- table1(f)
126
- end
197
+ docxml.xpath(ns("//table")).each { |f| table1(f) }
127
198
  end
128
199
 
129
200
  def table1(elem)
130
- return if labelled_ancestor(elem)
131
- return if elem["unnumbered"] && !elem.at(ns("./name"))
132
-
201
+ labelled_ancestor(elem) and return
202
+ elem["unnumbered"] && !elem.at(ns("./name")) and return
133
203
  n = @xrefs.anchor(elem["id"], :label, false)
134
204
  prefix_name(elem, block_delim, l10n("#{lower2cap @i18n.table} #{n}"),
135
205
  "name")
@@ -137,9 +207,7 @@ module IsoDoc
137
207
 
138
208
  # we use this to eliminate the semantic amend blocks from rendering
139
209
  def amend(docxml)
140
- docxml.xpath(ns("//amend")).each do |f|
141
- amend1(f)
142
- end
210
+ docxml.xpath(ns("//amend")).each { |f| amend1(f) }
143
211
  end
144
212
 
145
213
  def amend1(elem)
@@ -150,9 +218,7 @@ module IsoDoc
150
218
  end
151
219
 
152
220
  def ol(docxml)
153
- docxml.xpath(ns("//ol")).each do |f|
154
- ol1(f)
155
- end
221
+ docxml.xpath(ns("//ol")).each { |f| ol1(f) }
156
222
  @xrefs.list_anchor_names(docxml.xpath(ns(@xrefs.sections_xpath)))
157
223
  end
158
224
 
@@ -9,7 +9,7 @@ module IsoDoc
9
9
 
10
10
  def erefstack1(elem)
11
11
  locs = elem.xpath(ns("./eref")).map do |e|
12
- [e["connective"], e.to_xml]
12
+ [e["connective"], to_xml(e)]
13
13
  end.flatten
14
14
  ret = resolve_eref_connectives(locs)
15
15
  elem.replace(ret[1])
@@ -30,9 +30,9 @@ module IsoDoc
30
30
  ret = resolve_eref_connectives(eref_locality_stacks(refs, target,
31
31
  node))
32
32
  node.delete("droploc") unless droploc
33
- eref_localities1(target,
34
- refs.first.at(ns("./locality/@type")).text,
35
- l10n(ret[1..-1].join), nil, node, @lang)
33
+ eref_localities1({ target: target, number: "pl",
34
+ type: refs.first.at(ns("./locality/@type")).text,
35
+ from: l10n(ret[1..-1].join), node: node, lang: @lang })
36
36
  end
37
37
 
38
38
  def can_conflate_eref_rendering?(refs)
@@ -61,19 +61,24 @@ module IsoDoc
61
61
  locs1 = []
62
62
  add = ""
63
63
  until locs.empty?
64
- if [", ", " "].include?(locs[1])
65
- add += locs[0..2].join
66
- locs.shift(3)
67
- else
68
- locs1 << add unless add.empty?
69
- add = ""
70
- locs1 << locs.shift
71
- end
64
+ locs, locs1, add = resolve_comma_connectives1(locs, locs1, add)
72
65
  end
73
66
  locs1 << add unless add.empty?
74
67
  locs1
75
68
  end
76
69
 
70
+ def resolve_comma_connectives1(locs, locs1, add)
71
+ if [", ", " "].include?(locs[1])
72
+ add += locs[0..2].join
73
+ locs.shift(3)
74
+ else
75
+ locs1 << add unless add.empty?
76
+ add = ""
77
+ locs1 << locs.shift
78
+ end
79
+ [locs, locs1, add]
80
+ end
81
+
77
82
  def resolve_to_connectives(locs)
78
83
  locs1 = []
79
84
  until locs.empty?
@@ -108,12 +113,7 @@ module IsoDoc
108
113
  def eref_locality_stack(ref, idx, target, node)
109
114
  ret = []
110
115
  if ref.name == "localityStack"
111
- ref.elements.each_with_index do |rr, j|
112
- l = eref_localities0(rr, j, target, node) or next
113
-
114
- ret << l
115
- ret << locality_delimiter(rr) unless j == ref.elements.size - 1
116
- end
116
+ ret = eref_locality_stack1(ref, target, node, ret)
117
117
  else
118
118
  l = eref_localities0(ref, idx, target, node) and ret << l
119
119
  end
@@ -121,6 +121,15 @@ module IsoDoc
121
121
  ret
122
122
  end
123
123
 
124
+ def eref_locality_stack1(ref, target, node, ret)
125
+ ref.elements.each_with_index do |rr, j|
126
+ l = eref_localities0(rr, j, target, node) or next
127
+ ret << l
128
+ ret << locality_delimiter(rr) unless j == ref.elements.size - 1
129
+ end
130
+ ret
131
+ end
132
+
124
133
  def locality_delimiter(_loc)
125
134
  ", "
126
135
  end
@@ -128,38 +137,43 @@ module IsoDoc
128
137
  def eref_localities0(ref, _idx, target, node)
129
138
  if ref["type"] == "whole" then @i18n.wholeoftext
130
139
  else
131
- eref_localities1(target, ref["type"],
132
- ref&.at(ns("./referenceFrom"))&.text,
133
- ref&.at(ns("./referenceTo"))&.text, node, @lang)
140
+ eref_localities1({ target: target, type: ref["type"], number: "sg",
141
+ from: ref.at(ns("./referenceFrom"))&.text,
142
+ upto: ref.at(ns("./referenceTo"))&.text, node: node,
143
+ lang: @lang })
134
144
  end
135
145
  end
136
146
 
137
- def eref_localities1_zh(_target, type, from, upto, node)
138
- ret = "第#{from}" if from
139
- ret += "&#x2013;#{upto}" if upto
140
- loc = eref_locality_populate(type, node)
141
- ret += " #{loc}" unless node["droploc"] == "true"
147
+ # def eref_localities1_zh(_target, type, from, upto, node)
148
+ def eref_localities1_zh(opt)
149
+ ret = "第#{opt[:from]}" if opt[:from]
150
+ ret += "&#x2013;#{opt[:upto]}" if opt[:upto]
151
+ loc = eref_locality_populate(opt[:type], opt[:node], "sg")
152
+ ret += " #{loc}" unless opt[:node]["droploc"] == "true"
142
153
  ret
143
154
  end
144
155
 
145
- def eref_localities1(target, type, from, upto, node, lang = "en")
146
- return nil if type == "anchor"
156
+ # def eref_localities1(target, type, from, upto, node, lang = "en")
157
+ def eref_localities1(opt)
158
+ return nil if opt[:type] == "anchor"
147
159
 
148
- lang == "zh" and
149
- return l10n(eref_localities1_zh(target, type, from, upto, node))
150
- ret = eref_locality_populate(type, node)
151
- ret += " #{from}" if from
152
- ret += "&#x2013;#{upto}" if upto
160
+ opt[:lang] == "zh" and
161
+ # return l10n(eref_localities1_zh(target, type, from, upto, node))
162
+ return l10n(eref_localities1_zh(opt))
163
+ ret = eref_locality_populate(opt[:type], opt[:node], opt[:number])
164
+ ret += " #{opt[:from]}" if opt[:from]
165
+ ret += "&#x2013;#{opt[:upto]}" if opt[:upto]
153
166
  l10n(ret)
154
167
  end
155
168
 
156
- def eref_locality_populate(type, node)
169
+ def eref_locality_populate(type, node, number)
157
170
  return "" if node["droploc"] == "true"
158
171
 
159
172
  loc = type.sub(/^locality:/, "")
160
173
  ret = @i18n.locality[loc] || loc
174
+ number == "pl" and ret = @i18n.inflect(ret, number: "pl")
161
175
  ret = case node["case"]
162
- when "lowercase" then loc.downcase
176
+ when "lowercase" then ret.downcase
163
177
  else Metanorma::Utils.strict_capitalize_first(ret)
164
178
  end
165
179
  " #{ret}"
@@ -20,7 +20,7 @@ module IsoDoc
20
20
  d.remove_namespaces!
21
21
  refs = d.xpath("//references/bibitem").each_with_object([]) do |b, m|
22
22
  prep_for_rendering(b)
23
- m << b.to_xml
23
+ m << to_xml(b)
24
24
  end.join
25
25
  bibrenderer.render_all("<references>#{refs}</references>",
26
26
  type: citestyle)
@@ -49,8 +49,8 @@ module IsoDoc
49
49
  def bibrender_relaton(xml, renderings)
50
50
  f = renderings[xml["id"]][:formattedref]
51
51
  f &&= "<formattedref>#{f}</formattedref>"
52
- xml.children =
53
- "#{f}#{xml.xpath(ns('./docidentifier | ./uri | ./note')).to_xml}"
52
+ x = xml.xpath(ns("./docidentifier | ./uri | ./note | ./biblio-tag"))
53
+ xml.children = "#{f}#{x.to_xml}"
54
54
  end
55
55
 
56
56
  def bibrenderer
@@ -74,6 +74,7 @@ module IsoDoc
74
74
  i = bibliography_bibitem_number1(b, i)
75
75
  end
76
76
  @xrefs.references docxml
77
+ bibliography_bibitem_tag(docxml)
77
78
  end
78
79
 
79
80
  def bibliography_bibitem_number1(bibitem, idx)
@@ -99,8 +100,79 @@ module IsoDoc
99
100
 
100
101
  def docid_prefixes(docxml)
101
102
  docxml.xpath(ns("//references/bibitem/docidentifier")).each do |i|
102
- i.children = @xrefs.klass.docid_prefix(i["type"], i.text)
103
+ i.children = @xrefs.klass.docid_prefix(i["type"], to_xml(i.children))
103
104
  end
104
105
  end
106
+
107
+ def bibliography_bibitem_tag(docxml)
108
+ [true, false].each do |norm|
109
+ i = 0
110
+ docxml.xpath(ns("//references[@normative = '#{norm}']")).each do |r|
111
+ i = bibliography_bibitem_tag1(r, i, norm)
112
+ end
113
+ end
114
+ end
115
+
116
+ def bibliography_bibitem_tag1(ref, idx, norm)
117
+ ref.xpath(ns("./bibitem")).each do |b|
118
+ @xrefs.klass.implicit_reference(b) and next
119
+ idx += 1 unless b["hidden"]
120
+ insert_biblio_tag(b, idx, !norm, @xrefs.klass.standard?(b))
121
+ end
122
+ idx
123
+ end
124
+
125
+ def insert_biblio_tag(bib, ordinal, biblio, standard)
126
+ datefn = date_note_process(bib)
127
+ ids = @xrefs.klass.bibitem_ref_code(bib)
128
+ idents = @xrefs.klass.render_identifier(ids)
129
+ ret = if biblio then biblio_ref_entry_code(ordinal, idents, ids,
130
+ standard, datefn)
131
+ else norm_ref_entry_code(ordinal, idents, ids, standard, datefn)
132
+ end
133
+ bib << "<biblio-tag>#{ret}</biblio-tag>"
134
+ end
135
+
136
+ def norm_ref_entry_code(_ordinal, idents, _ids, _standard, datefn)
137
+ ret = (idents[:ordinal] || idents[:metanorma] || idents[:sdo]).to_s
138
+ (idents[:ordinal] || idents[:metanorma]) && idents[:sdo] and
139
+ ret += ", #{idents[:sdo]}"
140
+ ret += datefn
141
+ ret.empty? and return ret
142
+ idents[:sdo] and ret += ","
143
+ "#{ret} "
144
+ end
145
+
146
+ # if ids is just a number, only use that ([1] Non-Standard)
147
+ # else, use both ordinal, as prefix, and ids
148
+ def biblio_ref_entry_code(ordinal, ids, _id, standard, datefn)
149
+ standard and id = nil
150
+ ret = (ids[:ordinal] || ids[:metanorma] || "[#{ordinal}]")
151
+ if ids[:sdo]
152
+ ret = prefix_bracketed_ref(ret)
153
+ ret += "#{ids[:sdo]}#{datefn}, "
154
+ else
155
+ ret = prefix_bracketed_ref("#{ret}#{datefn}")
156
+ end
157
+ ret
158
+ end
159
+
160
+ def prefix_bracketed_ref(text)
161
+ "#{text}<tab/>"
162
+ end
163
+
164
+ # strip any fns in docidentifier before they are extracted for rendering
165
+ def date_note_process(bib)
166
+ ret = ident_fn(bib)
167
+ date_note = bib.at(ns("./note[@type = 'Unpublished-Status']"))
168
+ date_note.nil? and return ret
169
+ id = UUIDTools::UUID.random_create.to_s
170
+ "#{ret}<fn reference='#{id}'><p>#{date_note.content}</p></fn>"
171
+ end
172
+
173
+ def ident_fn(bib)
174
+ ret = bib.at(ns("./docidentifier//fn")) or return ""
175
+ to_xml(ret.remove)
176
+ end
105
177
  end
106
178
  end
@@ -55,7 +55,7 @@ module IsoDoc
55
55
  def annex1(elem)
56
56
  lbl = @xrefs.anchor(elem["id"], :label)
57
57
  if t = elem.at(ns("./title"))
58
- t.children = "<strong>#{t.children.to_xml}</strong>"
58
+ t.children = "<strong>#{to_xml(t.children)}</strong>"
59
59
  end
60
60
  prefix_name(elem, "<br/><br/>", lbl, "title")
61
61
  end
@@ -1,17 +1,19 @@
1
1
  module IsoDoc
2
2
  class PresentationXMLConvert < ::IsoDoc::Convert
3
3
  def concept(docxml)
4
+ @definition_ids = docxml.xpath(ns("//definitions//dt"))
5
+ .each_with_object({}) { |x, m| m[x["id"]] = true }
4
6
  docxml.xpath(ns("//concept")).each { |f| concept1(f) }
5
7
  end
6
8
 
7
9
  def concept1(node)
8
10
  xref = node&.at(ns("./xref/@target"))&.text or
9
- return concept_render(node, ital: "true", ref: "true",
11
+ return concept_render(node, ital: "true", ref: "true", bold: "false",
10
12
  linkref: "true", linkmention: "false")
11
- if node.at(ns("//definitions//dt[@id = '#{xref}']"))
12
- concept_render(node, ital: "false", ref: "false",
13
+ if @definition_ids[xref]
14
+ concept_render(node, ital: "false", ref: "false", bold: "false",
13
15
  linkref: "true", linkmention: "false")
14
- else concept_render(node, ital: "true", ref: "true",
16
+ else concept_render(node, ital: "true", ref: "true", bold: "false",
15
17
  linkref: "true", linkmention: "false")
16
18
  end
17
19
  end
@@ -20,21 +22,23 @@ module IsoDoc
20
22
  opts, render, ref = concept_render_init(node, defaults)
21
23
  node&.at(ns("./refterm"))&.remove
22
24
  ref && opts[:ref] != "false" and render&.next = " "
23
- opts[:ital] == "true" and render&.name = "em"
24
25
  concept1_linkmention(ref, render, opts)
25
26
  concept1_ref(node, ref, opts)
26
- concept1_nonital(node, opts)
27
- node.replace(node.children.to_xml.strip)
27
+ concept1_style(node, opts)
28
+ node.replace(node.children)
28
29
  end
29
30
 
30
- def concept1_nonital(node, opts)
31
- opts[:ital] == "false" or return
32
- r = node.at(ns(".//renderterm"))
33
- r&.replace(r&.children)
31
+ def concept1_style(node, opts)
32
+ r = node.at(ns(".//renderterm")) or return
33
+ opts[:ital] == "true" and r.children = "<em>#{to_xml(r.children)}</em>"
34
+ opts[:bold] == "true" and
35
+ r.children = "<strong>#{to_xml(r.children)}</strong>"
36
+ r.replace(r.children)
34
37
  end
35
38
 
36
39
  def concept_render_init(node, defaults)
37
- opts = %i(ital ref linkref linkmention).each_with_object({}) do |x, m|
40
+ opts = %i(bold ital ref linkref linkmention)
41
+ .each_with_object({}) do |x, m|
38
42
  m[x] = node[x.to_s] || defaults[x]
39
43
  end
40
44
  [opts, node.at(ns("./renderterm")),
@@ -42,7 +46,8 @@ module IsoDoc
42
46
  end
43
47
 
44
48
  def concept1_linkmention(ref, renderterm, opts)
45
- return unless opts[:linkmention] == "true" && !renderterm.nil? && !ref.nil?
49
+ return unless opts[:linkmention] == "true" &&
50
+ !renderterm.nil? && !ref.nil?
46
51
 
47
52
  ref2 = ref.clone
48
53
  r2 = renderterm.clone
@@ -68,8 +73,8 @@ module IsoDoc
68
73
  !c.text? || /\S/.match(c)
69
74
  end.empty?
70
75
  ref.replace(@i18n.term_defined_in.sub(/%/,
71
- ref.to_xml))
72
- else ref.replace("[#{ref.to_xml}]")
76
+ to_xml(ref)))
77
+ else ref.replace("[#{to_xml(ref)}]")
73
78
  end
74
79
  end
75
80
 
@@ -83,7 +88,7 @@ module IsoDoc
83
88
  label = @i18n.relatedterms[node["type"]].upcase
84
89
  if p && ref
85
90
  node.replace(l10n("<p><strong>#{label}:</strong> " \
86
- "<em>#{p.to_xml}</em> (#{ref.to_xml})</p>"))
91
+ "<em>#{to_xml(p)}</em> (#{Common::to_xml(ref)})</p>"))
87
92
  else
88
93
  node.replace(l10n("<p><strong>#{label}:</strong> " \
89
94
  "<strong>**RELATED TERM NOT FOUND**</strong></p>"))
@@ -110,7 +115,7 @@ module IsoDoc
110
115
  if merge_preferred_eligible?(pref, second)
111
116
  n1 = pref.at(ns("./expression/name"))
112
117
  n2 = second.remove.at(ns("./expression/name"))
113
- n1.children = l10n("#{n1.children.to_xml}; #{n2.children.to_xml}")
118
+ n1.children = l10n("#{to_xml(n1.children)}; #{Common::to_xml(n2.children)}")
114
119
  end
115
120
  end
116
121
 
@@ -150,7 +155,7 @@ module IsoDoc
150
155
 
151
156
  def designation_field(desgn, name)
152
157
  f = desgn.xpath(ns("./field-of-application | ./usage-info"))
153
- &.map { |u| u.children.to_xml }&.join(", ")
158
+ &.map { |u| to_xml(u.children) }&.join(", ")
154
159
  return nil if f&.empty?
155
160
 
156
161
  name << ", &#x3c;#{f}&#x3e;"
@@ -181,7 +186,7 @@ module IsoDoc
181
186
  def designation_pronunciation(desgn, name)
182
187
  f = desgn.at(ns("./expression/pronunciation")) or return
183
188
 
184
- name << ", /#{f.children.to_xml}/"
189
+ name << ", /#{to_xml(f.children)}/"
185
190
  end
186
191
 
187
192
  def termexample(docxml)
@@ -214,9 +219,9 @@ module IsoDoc
214
219
 
215
220
  def multidef(elem)
216
221
  d = elem.at(ns("./definition"))
217
- d = d.replace("<ol><li>#{d.children.to_xml}</li></ol>").first
222
+ d = d.replace("<ol><li>#{to_xml(d.children)}</li></ol>").first
218
223
  elem.xpath(ns("./definition")).each do |f|
219
- f = f.replace("<li>#{f.children.to_xml}</li>").first
224
+ f = f.replace("<li>#{to_xml(f.children)}</li>").first
220
225
  d << f
221
226
  end
222
227
  d.wrap("<definition></definition>")
@@ -242,9 +247,9 @@ module IsoDoc
242
247
 
243
248
  def termsource1(elem)
244
249
  while elem&.next_element&.name == "termsource"
245
- elem << "; #{elem.next_element.remove.children.to_xml}"
250
+ elem << "; #{to_xml(elem.next_element.remove.children)}"
246
251
  end
247
- elem.children = l10n("[#{@i18n.source}: #{elem.children.to_xml.strip}]")
252
+ elem.children = l10n("[#{@i18n.source}: #{to_xml(elem.children).strip}]")
248
253
  end
249
254
 
250
255
  def termsource_modification(mod)
@@ -38,14 +38,23 @@ module IsoDoc
38
38
  def anchor_xref(node, target)
39
39
  x = @xrefs.anchor(target, :xref)
40
40
  t = @xrefs.anchor(target, :title)
41
- if node["style"] == "basic" && t then t
42
- elsif node["style"] == "full" && t
43
- l10n("#{x}, #{t}")
44
- else x
45
- end
41
+ ret = case node["style"]
42
+ when "basic" then t
43
+ when "full" then anchor_xref_full(x, t)
44
+ when "short", nil then x
45
+ else @xrefs.anchor(target, node[:style].to_sym)
46
+ end
47
+ ret || x
48
+ end
49
+
50
+ def anchor_xref_full(num, title)
51
+ (!title.nil? && !title.empty?) or return nil
52
+
53
+ l10n("#{num}, #{title}")
46
54
  end
47
55
 
48
56
  def prefix_container?(container, node)
57
+ node["style"] == "modspec" and return false # TODO: move to mn-requirements?
49
58
  type = @xrefs.anchor(node["target"], :type)
50
59
  container &&
51
60
  get_note_container_id(node, type) != container &&
@@ -66,8 +75,8 @@ module IsoDoc
66
75
  def combine_conflated_xref_locations(locs)
67
76
  out = locs.each { |l| l[:label] = anchor_value(l[:target]) }
68
77
  label = @i18n.inflect(locs.first[:elem], number: "pl")
69
- ret = l10n("#{label} #{combine_conn(out)}")
70
- combine_conflated_xref_locations_container(locs, ret)
78
+ out[0][:label] = l10n("#{label} #{out[0][:label]}")
79
+ combine_conflated_xref_locations_container(locs, l10n(combine_conn(out)))
71
80
  end
72
81
 
73
82
  def combine_conflated_xref_locations_container(locs, ret)
@@ -85,11 +85,11 @@ module IsoDoc
85
85
  end
86
86
 
87
87
  def postprocess(result, filename, _dir)
88
- to_xml(result, filename)
88
+ to_xml_file(result, filename)
89
89
  @files_to_delete.each { |f| FileUtils.rm_rf f }
90
90
  end
91
91
 
92
- def to_xml(result, filename)
92
+ def to_xml_file(result, filename)
93
93
  File.open(filename, "w:UTF-8") { |f| f.write(result) }
94
94
  end
95
95
  end
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "2.3.6".freeze
2
+ VERSION = "2.4.1".freeze
3
3
  end