isodoc 2.5.3 → 2.5.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: af49b7f014295d868870736466462acab674753399c173b2fea81b5e93bce2ea
4
- data.tar.gz: 50816b1a7bac40a6fa6d54130bfa1c199d17e9013b22fde96e3b93c30f5602cd
3
+ metadata.gz: d6ca47f20afd4ccef8c44ce28bfca11c4803f9aa8988e950cf1842dc251dc855
4
+ data.tar.gz: 9f2ca8a82bb0528e05f8a6cc631cfad987c0fe8d819937af79580a119955a921
5
5
  SHA512:
6
- metadata.gz: 0f6f487050715c2a09af3b0c5a7e5c5b3f81cf58afaa05b451bfcc240a79de055ed78b770ed8ffcc1e8c1804c2cbf6985c64ee18870df95edad4e57261911e73
7
- data.tar.gz: 98f4b78b5ab197058fb69131c097f9636e765e1a3d9f5fa05ae39a3a7e1fc777b75d4f6b4ce745249234cd9ba42409476663a9dc1800efabef37e13a0ed70395
6
+ metadata.gz: 10170334bf2d0bbf492237695054a1a164c8c7f056a8cec5d782cd468f4a367524fc9dc841fccf4c3f7c90038af32d83e962d5cf224d66e5f7d05323b1b65083
7
+ data.tar.gz: 9fc62b5c28d0baff4b369f15f8811a6be8b0bd85e1b63db6a9b36017e9a84a276c9df3034c679c0bd11ecbca0d5f7056bd2aa1627873a561be29b67f5619db9a
data/isodoc.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["Ribose Inc."]
9
9
  spec.email = ["open.source@ribose.com"]
10
10
 
11
- spec.summary = "Convert documents in IsoDoc into Word and HTML "\
11
+ spec.summary = "Convert documents in IsoDoc into Word and HTML " \
12
12
  "in AsciiDoc."
13
13
  spec.description = <<~DESCRIPTION
14
14
  isodoc converts documents in the IsoDoc document model into
@@ -26,14 +26,13 @@ Gem::Specification.new do |spec|
26
26
  f.match(%r{^(test|spec|features|bin|.github)/}) \
27
27
  || f.match(%r{Rakefile|bin/rspec})
28
28
  end
29
- spec.test_files = `git ls-files -- {spec}/*`.split("\n")
30
29
  spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
31
30
 
32
31
  spec.add_dependency "html2doc", "~> 1.5.3"
33
32
  spec.add_dependency "htmlentities", "~> 4.3.4"
34
33
  # spec.add_dependency "isodoc-i18n", "~> 1.1.0" # already in relaton-render and mn-requirements
35
- spec.add_dependency "liquid", "~> 5"
36
34
  spec.add_dependency "emf2svg"
35
+ spec.add_dependency "liquid", "~> 5"
37
36
  spec.add_dependency "plurimath"
38
37
  spec.add_dependency "relaton-cli"
39
38
  # spec.add_dependency "metanorma-utils", "~> 1.5.0" # already in isodoc-i18n
@@ -85,7 +85,6 @@ module IsoDoc
85
85
 
86
86
  def convert1(docxml, filename, dir)
87
87
  @xrefs.parse docxml
88
- bibitem_lookup(docxml)
89
88
  noko do |xml|
90
89
  xml.html lang: @lang.to_s do |html|
91
90
  html.parent.add_namespace("epub", "http://www.idpf.org/2007/ops")
@@ -97,13 +96,6 @@ module IsoDoc
97
96
  end.join("\n")
98
97
  end
99
98
 
100
- def bibitem_lookup(docxml)
101
- @bibitems = docxml.xpath(ns("//references/bibitem"))
102
- .each_with_object({}) do |b, m|
103
- m[b["id"]] = b
104
- end
105
- end
106
-
107
99
  def convert_init(file, input_filename, debug)
108
100
  docxml = Nokogiri::XML(file) { |config| config.huge }
109
101
  filename, dir = init_file(input_filename, debug)
@@ -52,45 +52,15 @@ module IsoDoc
52
52
  url.sub(/#{File.extname(url)}$/, ".html")
53
53
  end
54
54
 
55
- def eref_target(node)
56
- url = suffix_url(eref_url(node["bibitemid"]))
57
- anchor = node&.at(ns(".//locality[@type = 'anchor']"))
58
- return url if url.nil? || /^#/.match?(url) || !anchor
59
-
60
- "#{url}##{anchor.text.strip}"
61
- end
62
-
63
- def eref_url(id)
64
- @bibitems.nil? and return nil
65
-
66
- b = @bibitems[id]
67
- b.nil? and return nil
68
-
69
- url = b.at(ns("./uri[@type = 'citation'][@language = '#{@lang}']")) and
70
- return url.text
71
- url = b.at(ns("./uri[@type = 'citation']")) and return url.text
72
- b["hidden"] == "true" and return b.at(ns("./uri"))&.text
73
- "##{id}"
74
- end
75
-
76
55
  def eref_parse(node, out)
77
- if href = eref_target(node)
78
- if node["type"] == "footnote"
79
- out.sup do |s|
80
- s.a(href: href) { |l| no_locality_parse(node, l) }
81
- end
82
- else
83
- out.a(href: href) { |l| no_locality_parse(node, l) }
84
- end
85
- else no_locality_parse(node, out)
86
- end
56
+ no_locality_parse(node, out)
87
57
  end
88
58
 
89
59
  def origin_parse(node, out)
90
60
  if t = node.at(ns("./termref"))
91
61
  termrefelem_parse(t, out)
92
62
  else
93
- eref_parse(node, out)
63
+ no_locality_parse(node, out)
94
64
  end
95
65
  end
96
66
 
@@ -96,57 +96,77 @@ module IsoDoc
96
96
  clause_parse(isoxml, out)
97
97
  end
98
98
 
99
- def introduction(isoxml, out)
100
- f = isoxml.at(ns("//introduction")) || return
99
+ def introduction(clause, out)
101
100
  page_break(out)
102
- out.div class: "Section3", id: f["id"] do |div|
103
- clause_name(f, f.at(ns("./title")), div, { class: "IntroTitle" })
104
- f.elements.each do |e|
101
+ out.div class: "Section3", id: clause["id"] do |div|
102
+ clause_name(clause, clause.at(ns("./title")), div,
103
+ { class: "IntroTitle" })
104
+ clause.elements.each do |e|
105
105
  parse(e, div) unless e.name == "title"
106
106
  end
107
107
  end
108
108
  end
109
109
 
110
- def foreword(isoxml, out)
111
- f = isoxml.at(ns("//foreword")) || return
110
+ def foreword(clause, out)
112
111
  page_break(out)
113
- out.div **attr_code(id: f["id"]) do |s|
114
- clause_name(f, f.at(ns("./title")) || @i18n.foreword, s,
112
+ out.div **attr_code(id: clause["id"]) do |s|
113
+ clause_name(clause, clause.at(ns("./title")) || @i18n.foreword, s,
115
114
  { class: "ForewordTitle" })
116
- f.elements.each { |e| parse(e, s) unless e.name == "title" }
115
+ clause.elements.each { |e| parse(e, s) unless e.name == "title" }
117
116
  end
118
117
  end
119
118
 
120
- def acknowledgements(isoxml, out)
121
- f = isoxml.at(ns("//acknowledgements")) || return
119
+ def acknowledgements(clause, out)
122
120
  title_attr = { class: "IntroTitle" }
123
121
  page_break(out)
124
- out.div class: "Section3", id: f["id"] do |div|
125
- clause_name(f, f&.at(ns("./title")), div, title_attr)
126
- f.elements.each do |e|
122
+ out.div class: "Section3", id: clause["id"] do |div|
123
+ clause_name(clause, clause.at(ns("./title")), div, title_attr)
124
+ clause.elements.each do |e|
127
125
  parse(e, div) unless e.name == "title"
128
126
  end
129
127
  end
130
128
  end
131
129
 
132
- def abstract(isoxml, out)
133
- f = isoxml.at(ns("//preface/abstract")) || return
130
+ def abstract(clause, out)
134
131
  page_break(out)
135
- out.div **attr_code(id: f["id"]) do |s|
136
- clause_name(f, f.at(ns("./title")), s, { class: "AbstractTitle" })
137
- f.elements.each { |e| parse(e, s) unless e.name == "title" }
132
+ out.div **attr_code(id: clause["id"]) do |s|
133
+ clause_name(clause, clause.at(ns("./title")), s,
134
+ { class: "AbstractTitle" })
135
+ clause.elements.each { |e| parse(e, s) unless e.name == "title" }
138
136
  end
139
137
  end
140
138
 
141
- def preface(isoxml, out)
142
- isoxml.xpath(ns("//preface/clause | //preface/references | " \
143
- "//preface/definitions | //preface/terms")).each do |f|
144
- page_break(out)
145
- out.div class: "Section3", id: f["id"] do |div|
146
- clause_name(f, f&.at(ns("./title")), div, { class: "IntroTitle" })
147
- f.elements.each do |e|
148
- parse(e, div) unless e.name == "title"
149
- end
139
+ def preface_attrs(node)
140
+ { id: node["id"],
141
+ class: node["type"] == "toc" ? "TOC" : "Section3" }
142
+ end
143
+
144
+ def preface(clause, out)
145
+ if clause["type"] == "toc"
146
+ table_of_contents(clause, out)
147
+ else
148
+ preface_normal(clause, out)
149
+ end
150
+ end
151
+
152
+ def preface_normal(clause, out)
153
+ page_break(out)
154
+ out.div **attr_code(preface_attrs(clause)) do |div|
155
+ clause_name(clause, clause.at(ns("./title")), div,
156
+ { class: "IntroTitle" })
157
+ clause.elements.each do |e|
158
+ parse(e, div) unless e.name == "title"
159
+ end
160
+ end
161
+ end
162
+
163
+ def table_of_contents(clause, out)
164
+ page_break(out)
165
+ out.div **attr_code(preface_attrs(clause)) do |div|
166
+ clause_name(clause, clause.at(ns("./title")), div,
167
+ { class: "IntroTitle" })
168
+ clause.elements.each do |e|
169
+ parse(e, div) unless e.name == "title"
150
170
  end
151
171
  end
152
172
  end
@@ -174,15 +194,33 @@ module IsoDoc
174
194
  t.size == 1 && %w(terms definitions references).include?(t[0].name)
175
195
  end
176
196
 
177
- def preface_block(isoxml, out)
197
+ def front(isoxml, out)
178
198
  p = isoxml.at(ns("//preface")) or return
179
199
  p.elements.each do |e|
180
- next if is_clause?(e.name)
181
-
182
- parse(e, out)
200
+ if is_clause?(e.name)
201
+ case e.name
202
+ when "abstract" then abstract e, out
203
+ when "foreword" then foreword e, out
204
+ when "introduction" then introduction e, out
205
+ when "executivesummary" then executivesummary e, out
206
+ when "clause" then preface e, out
207
+ when "acknowledgements" then acknowledgements e, out
208
+ end
209
+ else
210
+ preface_block(e, out)
211
+ end
183
212
  end
184
213
  end
185
214
 
215
+ def executivesummary(clause, out)
216
+ introduction clause, out
217
+ end
218
+
219
+ # block, e.g. note, admonition
220
+ def preface_block(block, out)
221
+ parse(block, out)
222
+ end
223
+
186
224
  def copyright_parse(node, out)
187
225
  return if @bare
188
226
 
@@ -5,7 +5,6 @@ module IsoDoc
5
5
  module HtmlFunction
6
6
  module Html
7
7
  def convert1(docxml, filename, dir)
8
- bibitem_lookup(docxml)
9
8
  noko do |xml|
10
9
  xml.html lang: @lang.to_s do |html|
11
10
  info docxml, nil
@@ -37,12 +36,7 @@ module IsoDoc
37
36
  def make_body3(body, docxml)
38
37
  body.div class: "main-section" do |div3|
39
38
  boilerplate docxml, div3
40
- preface_block docxml, div3
41
- abstract docxml, div3
42
- foreword docxml, div3
43
- introduction docxml, div3
44
- preface docxml, div3
45
- acknowledgements docxml, div3
39
+ front docxml, div3
46
40
  middle docxml, div3
47
41
  footnotes div3
48
42
  comments div3
@@ -117,16 +117,24 @@ module IsoDoc
117
117
 
118
118
  # needs to be same output as toclevel
119
119
  def html_toc(docxml)
120
- idx = docxml.at("//div[@id = 'toc']") or return docxml
120
+ idx = html_toc_init(docxml) or return docxml
121
121
  path = toclevel_classes.map do |x|
122
122
  x.map { |l| "//main//#{l}#{toc_exclude_class}" }
123
123
  end
124
124
  toc = html_toc_entries(docxml, path)
125
125
  .map { |k| k[:entry] }.join("\n")
126
- idx.children = "<ul>#{toc}</ul>"
126
+ idx << "<ul>#{toc}</ul>"
127
127
  docxml
128
128
  end
129
129
 
130
+ def html_toc_init(docxml)
131
+ dest = docxml.at("//div[@id = 'toc']") or return
132
+ if source = docxml.at("//div[@class = 'TOC']")
133
+ dest << to_xml(source.remove.children)
134
+ end
135
+ dest
136
+ end
137
+
130
138
  def html_toc_entries(docxml, path)
131
139
  path.each_with_index.with_object([]) do |(p, i), m|
132
140
  docxml.xpath(p.join(" | ")).each do |h|
@@ -203,7 +203,7 @@ module IsoDoc
203
203
  end
204
204
 
205
205
  def source_modification(mod)
206
- termsource_modification(mod)
206
+ termsource_modification(mod.parent)
207
207
  end
208
208
  end
209
209
  end
@@ -0,0 +1,90 @@
1
+ module IsoDoc
2
+ class PresentationXMLConvert < ::IsoDoc::Convert
3
+ def concept(docxml)
4
+ @definition_ids = docxml.xpath(ns("//definitions//dt"))
5
+ .each_with_object({}) { |x, m| m[x["id"]] = true }
6
+ docxml.xpath(ns("//concept")).each { |f| concept1(f) }
7
+ end
8
+
9
+ def concept1(node)
10
+ xref = node&.at(ns("./xref/@target"))&.text or
11
+ return concept_render(node, ital: "true", ref: "true", bold: "false",
12
+ linkref: "true", linkmention: "false")
13
+ if @definition_ids[xref]
14
+ concept_render(node, ital: "false", ref: "false", bold: "false",
15
+ linkref: "true", linkmention: "false")
16
+ else concept_render(node, ital: "true", ref: "true", bold: "false",
17
+ linkref: "true", linkmention: "false")
18
+ end
19
+ end
20
+
21
+ def concept_render(node, defaults)
22
+ opts, render, ref = concept_render_init(node, defaults)
23
+ node&.at(ns("./refterm"))&.remove
24
+ ref && opts[:ref] != "false" and render&.next = " "
25
+ concept1_linkmention(ref, render, opts)
26
+ concept1_ref(node, ref, opts)
27
+ concept1_style(node, opts)
28
+ node.replace(node.children)
29
+ end
30
+
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)
37
+ end
38
+
39
+ def concept_render_init(node, defaults)
40
+ opts = %i(bold ital ref linkref linkmention)
41
+ .each_with_object({}) { |x, m| m[x] = node[x.to_s] || defaults[x] }
42
+ [opts, node.at(ns("./renderterm")),
43
+ node.at(ns("./xref | ./eref | ./termref"))]
44
+ end
45
+
46
+ def concept1_linkmention(ref, renderterm, opts)
47
+ (opts[:linkmention] == "true" && !renderterm.nil? && !ref.nil?) or return
48
+ ref2 = ref.clone
49
+ r2 = renderterm.clone
50
+ renderterm.replace(ref2).children = r2
51
+ end
52
+
53
+ def concept1_ref(_node, ref, opts)
54
+ ref.nil? and return
55
+ opts[:ref] == "false" and return ref.remove
56
+ concept1_ref_content(ref)
57
+ %w(xref eref).include? ref.name and get_linkend(ref)
58
+ opts[:linkref] == "false" && %w(xref eref).include?(ref.name) and
59
+ ref.replace(ref.children)
60
+ end
61
+
62
+ def concept1_ref_content(ref)
63
+ prev = "["
64
+ foll = "]"
65
+ non_locality_elems(ref).select do |c|
66
+ !c.text? || /\S/.match(c)
67
+ end.empty? and
68
+ (prev, foll = @i18n.term_defined_in.split("%"))
69
+ ref.previous = prev
70
+ ref.next = foll
71
+ end
72
+
73
+ def related(docxml)
74
+ docxml.xpath(ns("//related")).each { |f| related1(f) }
75
+ end
76
+
77
+ def related1(node)
78
+ p = node.at(ns("./preferred"))
79
+ ref = node.at(ns("./xref | ./eref | ./termref"))
80
+ label = @i18n.relatedterms[node["type"]].upcase
81
+ if p && ref
82
+ node.replace(l10n("<p><strong>#{label}:</strong> " \
83
+ "<em>#{to_xml(p)}</em> (#{Common::to_xml(ref)})</p>"))
84
+ else
85
+ node.replace(l10n("<p><strong>#{label}:</strong> " \
86
+ "<strong>**RELATED TERM NOT FOUND**</strong></p>"))
87
+ end
88
+ end
89
+ end
90
+ end
@@ -179,5 +179,54 @@ module IsoDoc
179
179
  end
180
180
  " #{ret}"
181
181
  end
182
+
183
+ def eref2link(docxml)
184
+ docxml.xpath(ns("//eref | //origin[not(termref)] | //quote/source"))
185
+ .each do |e|
186
+ href = eref_target(e) or next
187
+ e.xpath(ns("./locality | ./localityStack")).each(&:remove)
188
+ if /^#/.match?(href) then eref2xref(e)
189
+ else eref2link1(e, href)
190
+ end
191
+ end
192
+ end
193
+
194
+ def eref2xref(node)
195
+ node.name = "xref"
196
+ node["target"] = node["bibitemid"]
197
+ node.delete("bibitemid")
198
+ node.delete("citeas")
199
+ node["type"] == "footnote" and node.wrap("<sup></sup>")
200
+ end
201
+
202
+ def eref2link1(node, href)
203
+ repl = "<link target='#{href}'>#{node.children}</link>"
204
+ node["type"] == "footnote" and repl = "<sup>#{repl}</sup>"
205
+ node.replace(repl)
206
+ end
207
+
208
+ def suffix_url(url)
209
+ return url if url.nil? || %r{^https?://|^#}.match?(url)
210
+ return url unless File.extname(url).empty?
211
+
212
+ url.sub(/#{File.extname(url)}$/, ".html")
213
+ end
214
+
215
+ def eref_target(node)
216
+ url = suffix_url(eref_url(node["bibitemid"]))
217
+ anchor = node.at(ns(".//locality[@type = 'anchor']"))
218
+ return url if url.nil? || /^#/.match?(url) || !anchor
219
+
220
+ "#{url}##{anchor.text.strip}"
221
+ end
222
+
223
+ def eref_url(id)
224
+ @bibitems.nil? and return nil
225
+ b = @bibitems[id] or return nil
226
+ url = (b.at(ns("./uri[@type = 'citation'][@language = '#{@lang}']")) ||
227
+ b.at(ns("./uri[@type = 'citation']"))) and return url.text
228
+ b["hidden"] == "true" and return b.at(ns("./uri"))&.text
229
+ "##{id}"
230
+ end
182
231
  end
183
232
  end
@@ -124,9 +124,103 @@ module IsoDoc
124
124
  display_order_xpath(docxml, "//colophon/*", i)
125
125
  end
126
126
 
127
- def clausetitle(docxml); end
127
+ def clausetitle(docxml)
128
+ cjk_extended_title(docxml)
129
+ end
130
+
131
+ def cjk_search
132
+ lang = %w(zh ja ko).map { |x| "@language = '#{x}'" }.join(" or ")
133
+ %(Hans Hant Jpan Hang Kore).include?(@script) and
134
+ lang += " or not(@language)"
135
+ lang
136
+ end
137
+
138
+ def cjk_extended_title(docxml)
139
+ l = cjk_search
140
+ docxml.xpath(ns("//bibdata/title[#{l}] | //floating-title[#{l}] | " \
141
+ "//title[@depth = '1' or not(@depth)][#{l}]")).each do |t|
142
+ t.text.size < 4 or next
143
+ t.elements.empty? or next # can't be bothered
144
+ t.children = @i18n.cjk_extend(t.text)
145
+ end
146
+ end
147
+
148
+ def preface_rearrange(doc)
149
+ preface_move(doc.at(ns("//preface/abstract")),
150
+ %w(foreword introduction clause acknowledgements), doc)
151
+ preface_move(doc.at(ns("//preface/foreword")),
152
+ %w(introduction clause acknowledgements), doc)
153
+ preface_move(doc.at(ns("//preface/introduction")),
154
+ %w(clause acknowledgements), doc)
155
+ preface_move(doc.at(ns("//preface/acknowledgements")),
156
+ %w(), doc)
157
+ end
158
+
159
+ def preface_move(clause, after, _doc)
160
+ clause or return
161
+ preface = clause.parent
162
+ float = preceding_floats(clause)
163
+ prev = nil
164
+ xpath = after.map { |n| "./self::xmlns:#{n}" }.join(" | ")
165
+ xpath.empty? and xpath = "./self::*[not(following-sibling::*)]"
166
+ preface_move1(clause, preface, float, prev, xpath)
167
+ end
168
+
169
+ def preface_move1(clause, preface, float, prev, xpath)
170
+ preface.elements.each do |x|
171
+ ((x.name == "floating-title" || x.at(xpath)) &&
172
+ xpath != "./self::*[not(following-sibling::*)]") or prev = x
173
+ # after.include?(x.name) or next
174
+ x.at(xpath) or next
175
+ clause == prev and break
176
+ prev ||= preface.children.first
177
+ float << clause
178
+ float.each { |n| prev.next = n }
179
+ break
180
+ end
181
+ end
182
+
183
+ def preceding_floats(clause)
184
+ ret = []
185
+ p = clause
186
+ while prev = p.previous_element
187
+ if prev.name == "floating-title"
188
+ ret << prev
189
+ p = prev
190
+ else break
191
+ end
192
+ end
193
+ ret
194
+ end
195
+
196
+ def rearrange_clauses(docxml)
197
+ preface_rearrange(docxml) # feeds toc_title
198
+ toc_title(docxml)
199
+ end
200
+
201
+ def toc_title(docxml)
202
+ docxml.at(ns("//preface/clause[@type = 'toc']")) and return
203
+ ins = toc_title_insert_pt(docxml) or return
204
+ id = UUIDTools::UUID.random_create.to_s
205
+ ins.previous = <<~CLAUSE
206
+ <clause type = 'toc' id='_#{id}'><title depth='1'>#{@i18n.table_of_contents}</title></clause>
207
+ CLAUSE
208
+ end
209
+
210
+ def toc_title_insert_pt(docxml)
211
+ ins = docxml.at(ns("//preface")) ||
212
+ docxml.at(ns("//sections | //annex | //bibliography"))
213
+ &.before("<preface> </preface>")
214
+ &.previous_element or return nil
215
+ ins.children.empty? and ins << " "
216
+ ins.children.first
217
+ end
128
218
 
129
219
  def toc(docxml)
220
+ toc_refs(docxml)
221
+ end
222
+
223
+ def toc_refs(docxml)
130
224
  docxml.xpath(ns("//toc//xref[text()]")).each do |x|
131
225
  lbl = @xrefs.anchor(x["target"], :label) or next
132
226
  x.children.first.previous = "#{lbl}<tab/>"
@@ -1,92 +1,5 @@
1
1
  module IsoDoc
2
2
  class PresentationXMLConvert < ::IsoDoc::Convert
3
- def concept(docxml)
4
- @definition_ids = docxml.xpath(ns("//definitions//dt"))
5
- .each_with_object({}) { |x, m| m[x["id"]] = true }
6
- docxml.xpath(ns("//concept")).each { |f| concept1(f) }
7
- end
8
-
9
- def concept1(node)
10
- xref = node&.at(ns("./xref/@target"))&.text or
11
- return concept_render(node, ital: "true", ref: "true", bold: "false",
12
- linkref: "true", linkmention: "false")
13
- if @definition_ids[xref]
14
- concept_render(node, ital: "false", ref: "false", bold: "false",
15
- linkref: "true", linkmention: "false")
16
- else concept_render(node, ital: "true", ref: "true", bold: "false",
17
- linkref: "true", linkmention: "false")
18
- end
19
- end
20
-
21
- def concept_render(node, defaults)
22
- opts, render, ref = concept_render_init(node, defaults)
23
- node&.at(ns("./refterm"))&.remove
24
- ref && opts[:ref] != "false" and render&.next = " "
25
- concept1_linkmention(ref, render, opts)
26
- concept1_ref(node, ref, opts)
27
- concept1_style(node, opts)
28
- node.replace(node.children)
29
- end
30
-
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)
37
- end
38
-
39
- def concept_render_init(node, defaults)
40
- opts = %i(bold ital ref linkref linkmention)
41
- .each_with_object({}) { |x, m| m[x] = node[x.to_s] || defaults[x] }
42
- [opts, node.at(ns("./renderterm")),
43
- node.at(ns("./xref | ./eref | ./termref"))]
44
- end
45
-
46
- def concept1_linkmention(ref, renderterm, opts)
47
- (opts[:linkmention] == "true" && !renderterm.nil? && !ref.nil?) or return
48
- ref2 = ref.clone
49
- r2 = renderterm.clone
50
- renderterm.replace(ref2).children = r2
51
- end
52
-
53
- def concept1_ref(_node, ref, opts)
54
- ref.nil? and return
55
- opts[:ref] == "false" and return ref.remove
56
- concept1_ref_content(ref)
57
- %w(xref eref).include? ref.name and get_linkend(ref)
58
- opts[:linkref] == "false" && %w(xref eref).include?(ref.name) and
59
- ref.replace(ref.children)
60
- end
61
-
62
- def concept1_ref_content(ref)
63
- prev = "["
64
- foll = "]"
65
- non_locality_elems(ref).select do |c|
66
- !c.text? || /\S/.match(c)
67
- end.empty? and
68
- (prev, foll = @i18n.term_defined_in.split("%"))
69
- ref.previous = prev
70
- ref.next = foll
71
- end
72
-
73
- def related(docxml)
74
- docxml.xpath(ns("//related")).each { |f| related1(f) }
75
- end
76
-
77
- def related1(node)
78
- p = node.at(ns("./preferred"))
79
- ref = node.at(ns("./xref | ./eref | ./termref"))
80
- label = @i18n.relatedterms[node["type"]].upcase
81
- if p && ref
82
- node.replace(l10n("<p><strong>#{label}:</strong> " \
83
- "<em>#{to_xml(p)}</em> (#{Common::to_xml(ref)})</p>"))
84
- else
85
- node.replace(l10n("<p><strong>#{label}:</strong> " \
86
- "<strong>**RELATED TERM NOT FOUND**</strong></p>"))
87
- end
88
- end
89
-
90
3
  def designation(docxml)
91
4
  docxml.xpath(ns("//term")).each { |t| merge_second_preferred(t) }
92
5
  docxml.xpath(ns("//preferred | //admitted | //deprecates"))
@@ -225,9 +138,7 @@ module IsoDoc
225
138
  end
226
139
 
227
140
  def termsource(docxml)
228
- docxml.xpath(ns("//termsource/modification")).each do |f|
229
- termsource_modification(f)
230
- end
141
+ docxml.xpath(ns("//termsource")).each { |f| termsource_modification(f) }
231
142
  docxml.xpath(ns("//termsource")).each { |f| termsource1(f) }
232
143
  end
233
144
 
@@ -238,12 +149,25 @@ module IsoDoc
238
149
  elem.children = l10n("[#{@i18n.source}: #{to_xml(elem.children).strip}]")
239
150
  end
240
151
 
241
- def termsource_modification(mod)
242
- mod.previous_element.next = l10n(", #{@i18n.modified}")
152
+ def termsource_modification(elem)
153
+ origin = elem.at(ns("./origin"))
154
+ s = termsource_status(elem["status"]) and origin.next = l10n(", #{s}")
155
+ termsource_add_modification_text(elem.at(ns("./modification")))
156
+ end
157
+
158
+ def termsource_add_modification_text(mod)
159
+ mod or return
243
160
  mod.text.strip.empty? or mod.previous = " &#x2013; "
244
161
  mod.elements.size == 1 and
245
162
  mod.elements[0].replace(mod.elements[0].children)
246
163
  mod.replace(mod.children)
247
164
  end
165
+
166
+ def termsource_status(status)
167
+ case status
168
+ when "modified" then @i18n.modified
169
+ when "adapted" then @i18n.adapted
170
+ end
171
+ end
248
172
  end
249
173
  end
@@ -76,7 +76,7 @@ module IsoDoc
76
76
  # Note % to entry and Note % to entry: cannot conflate as Note % to entry 1 and 2
77
77
  # So Notes 1 and 3, but Note 1 to entry and Note 3 to entry
78
78
  def combine_conflated_xref_locations(locs)
79
- out = if locs.any? { |l| /%/.match?(l[:elem]) }
79
+ out = if locs.any? { |l| l[:elem]&.include?("%") }
80
80
  locs.each { |l| l[:label] = @xrefs.anchor(l[:target], :xref) }
81
81
  else
82
82
  conflate_xref_locations(locs)
@@ -138,6 +138,7 @@ module IsoDoc
138
138
  end
139
139
 
140
140
  def can_conflate_xref_rendering?(locs)
141
+ @i18n.get["no_conflate_xref_locations"] == true and return false
141
142
  (locs.all? { |l| l[:container].nil? } ||
142
143
  locs.all? { |l| l[:container] == locs.first[:container] }) &&
143
144
  locs.all? { |l| l[:type] == locs[0][:type] }
@@ -1,4 +1,5 @@
1
1
  require_relative "presentation_function/block"
2
+ require_relative "presentation_function/concepts"
2
3
  require_relative "presentation_function/terms"
3
4
  require_relative "presentation_function/xrefs"
4
5
  require_relative "presentation_function/erefs"
@@ -17,12 +18,20 @@ module IsoDoc
17
18
 
18
19
  def convert1(docxml, _filename, _dir)
19
20
  @xrefs.parse docxml
21
+ bibitem_lookup(docxml)
20
22
  info docxml, nil
21
23
  conversions(docxml)
22
24
  docxml.root["type"] = "presentation"
23
25
  docxml.to_xml.gsub(/&lt;/, "&#x3c;").gsub(/&gt;/, "&#x3e;")
24
26
  end
25
27
 
28
+ def bibitem_lookup(docxml)
29
+ @bibitems = docxml.xpath(ns("//references/bibitem"))
30
+ .each_with_object({}) do |b, m|
31
+ m[b["id"]] = b
32
+ end
33
+ end
34
+
26
35
  def conversions(docxml)
27
36
  semantic_xml_insert(docxml)
28
37
  bibdata docxml
@@ -39,12 +48,13 @@ module IsoDoc
39
48
  references docxml
40
49
  # triggers xrefs reparse, so put references before all other sections,
41
50
  # which alter titles and thus can alter xrefs
51
+ rearrange_clauses docxml # feeds toc, display_order, clausetitle, clause
42
52
  annex docxml
43
- clause docxml
53
+ clause docxml # feeds clausetitle
44
54
  term docxml
45
55
  index docxml
46
- clausetitle docxml
47
- floattitle docxml
56
+ clausetitle docxml # feeds floattitle
57
+ floattitle docxml # feeds rearrange_clauses
48
58
  toc docxml
49
59
  display_order docxml
50
60
  end
@@ -68,9 +78,10 @@ module IsoDoc
68
78
 
69
79
  def inline(docxml)
70
80
  xref docxml
71
- eref docxml
72
- origin docxml
73
- quotesource docxml
81
+ eref docxml # feeds docxml
82
+ origin docxml # feeds docxml
83
+ quotesource docxml # feeds docxml
84
+ eref2link docxml
74
85
  mathml docxml
75
86
  variant docxml
76
87
  identifier docxml
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "2.5.3".freeze
2
+ VERSION = "2.5.5".freeze
3
3
  end
@@ -28,12 +28,7 @@ module IsoDoc
28
28
  def make_body2(body, docxml)
29
29
  body.div class: "WordSection2" do |div2|
30
30
  boilerplate docxml, div2
31
- preface_block docxml, div2
32
- abstract docxml, div2
33
- foreword docxml, div2
34
- introduction docxml, div2
35
- preface docxml, div2
36
- acknowledgements docxml, div2
31
+ front docxml, div2
37
32
  div2.p { |p| p << "&#xa0;" } # placeholder
38
33
  end
39
34
  section_break(body)
@@ -243,6 +238,18 @@ module IsoDoc
243
238
  .at(ns("//metanorma-extension/toc[@type = 'recommendation']/title"))&.text
244
239
  super
245
240
  end
241
+
242
+ def table_of_contents(clause, out)
243
+ page_break(out)
244
+ out.div **attr_code(preface_attrs(clause)) do |div|
245
+ div.p class: "zzContents" do |p|
246
+ clause.at(ns("./title"))&.children&.each { |c| parse(c, p) }
247
+ end
248
+ clause.elements.each do |e|
249
+ parse(e, div) unless e.name == "title"
250
+ end
251
+ end
252
+ end
246
253
  end
247
254
  end
248
255
  end
@@ -2,12 +2,28 @@ module IsoDoc
2
2
  module WordFunction
3
3
  module Postprocess
4
4
  def insert_toc(intro, docxml, level)
5
+ toc = assemble_toc(docxml, level)
6
+ if intro&.include?("WORDTOC")
7
+ if s = docxml.at("//div[@class = 'TOC']")
8
+ s&.previous_element&.elements&.first&.name == "br" and
9
+ s&.previous_element&.remove # page break
10
+ s.remove
11
+ end
12
+ intro.sub(/WORDTOC/, toc)
13
+ else
14
+ source = docxml.at("//div[@class = 'TOC']") and
15
+ source.children = toc
16
+ intro
17
+ end
18
+ end
19
+
20
+ def assemble_toc(docxml, level)
5
21
  toc = ""
6
22
  toc += make_WordToC(docxml, level)
7
23
  toc += make_table_word_toc(docxml)
8
24
  toc += make_figure_word_toc(docxml)
9
25
  toc += make_recommendation_word_toc(docxml)
10
- intro.sub(/WORDTOC/, toc)
26
+ toc
11
27
  end
12
28
 
13
29
  def word_toc_entry(toclevel, heading)
@@ -43,6 +59,9 @@ module IsoDoc
43
59
 
44
60
  def make_WordToC(docxml, level)
45
61
  toc = ""
62
+ if source = docxml.at("//div[@class = 'TOC']")
63
+ toc = to_xml(source.children)
64
+ end
46
65
  # docxml.xpath("//h1 | //h2[not(ancestor::*[@class = 'Section3'])]").
47
66
  xpath = (1..level).each.map { |i| "//h#{i}" }.join (" | ")
48
67
  docxml.xpath(xpath).each do |h|
@@ -68,6 +68,7 @@ draft_label: مسودة
68
68
  inform_annex: إخباري
69
69
  norm_annex: مقياسي
70
70
  modified: معدلة
71
+ adapted: تكيف
71
72
  deprecated: مهمل
72
73
  source: مصدر
73
74
  and: و
@@ -74,7 +74,8 @@ draft_label: Entwurf
74
74
  inform_annex: informativ
75
75
  norm_annex: normativ
76
76
  modified: geändert
77
- deprecated: DEPRECATED
77
+ adapted: angepasst
78
+ deprecated: VERALTET
78
79
  source: QUELLE
79
80
  and: und
80
81
  all_parts: Alle Teile
@@ -83,6 +83,7 @@ draft_label: draft
83
83
  inform_annex: informative
84
84
  norm_annex: normative
85
85
  modified: modified
86
+ adapted: adapted
86
87
  deprecated: DEPRECATED
87
88
  source: SOURCE
88
89
  and: and
@@ -74,6 +74,7 @@ draft_label: borrador
74
74
  inform_annex: informativo
75
75
  norm_annex: normativo
76
76
  modified: modificado
77
+ adapted: adaptado
77
78
  deprecated: OBSOLETO
78
79
  source: FUENTE
79
80
  and: y
@@ -71,6 +71,7 @@ draft_label: brouillon
71
71
  inform_annex: informative
72
72
  norm_annex: normative
73
73
  modified: modifié
74
+ adapted: adapté
74
75
  deprecated: DÉCONSEILLÉ
75
76
  source: SOURCE
76
77
  edition: édition
@@ -38,9 +38,10 @@ multiple_or: "%1, or %2"
38
38
  chain_and: "%1 and %2"
39
39
  chain_or: "%1 or %2"
40
40
  chain_from: "%1 from %2"
41
- chain_to: "%1 to %2"
41
+ chain_to: "%1~%2"
42
42
  nested_xref: "%1の%2"
43
43
  list_nested_xref: "%1の%2"
44
+ no_conflate_xref_locations: true
44
45
  ordinal_keys: []
45
46
  SpelloutRules: spellout-ordinal
46
47
  note: 注記
@@ -78,7 +79,8 @@ wholeoftext: Whole of text
78
79
  draft_label: draft
79
80
  inform_annex: 参考
80
81
  norm_annex: 規定
81
- modified: modified
82
+ modified: 修正された
83
+ adapted: 適合しました
82
84
  deprecated: 推奨しない用語
83
85
  source: 出典
84
86
  and: and
@@ -79,6 +79,7 @@ draft_label: проект
79
79
  inform_annex: информативное
80
80
  norm_annex: нормативное
81
81
  modified: изменен
82
+ adapted: адаптированный
82
83
  deprecated: НЕ РЕКОМЕНДУЕТСЯ
83
84
  source: ИСТОЧНИК
84
85
  and: и
@@ -69,6 +69,7 @@ draft_label: 稿
69
69
  inform_annex: 资料性附录
70
70
  norm_annex: 规范性附录
71
71
  modified: 改写
72
+ adapted: 改编
72
73
  deprecated: 被取代
73
74
  source: 定义
74
75
  and: 和
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isodoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.3
4
+ version: 2.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-10 00:00:00.000000000 Z
11
+ date: 2023-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: html2doc
@@ -39,33 +39,33 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: 4.3.4
41
41
  - !ruby/object:Gem::Dependency
42
- name: liquid
42
+ name: emf2svg
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '5'
47
+ version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '5'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: emf2svg
56
+ name: liquid
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '5'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '5'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: plurimath
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -433,6 +433,7 @@ files:
433
433
  - lib/isodoc/pdf_convert.rb
434
434
  - lib/isodoc/presentation_function/bibdata.rb
435
435
  - lib/isodoc/presentation_function/block.rb
436
+ - lib/isodoc/presentation_function/concepts.rb
436
437
  - lib/isodoc/presentation_function/erefs.rb
437
438
  - lib/isodoc/presentation_function/image.rb
438
439
  - lib/isodoc/presentation_function/inline.rb