isodoc 2.5.3 → 2.5.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: af49b7f014295d868870736466462acab674753399c173b2fea81b5e93bce2ea
4
- data.tar.gz: 50816b1a7bac40a6fa6d54130bfa1c199d17e9013b22fde96e3b93c30f5602cd
3
+ metadata.gz: 3cbf57138d05cbc6fb861e09c867a3f4f3a58d349be341676e3a4ff2ef3b3477
4
+ data.tar.gz: e201871207c3d77a4be10a66624cd40859baf0a09bf309382f4fb43b2154e0eb
5
5
  SHA512:
6
- metadata.gz: 0f6f487050715c2a09af3b0c5a7e5c5b3f81cf58afaa05b451bfcc240a79de055ed78b770ed8ffcc1e8c1804c2cbf6985c64ee18870df95edad4e57261911e73
7
- data.tar.gz: 98f4b78b5ab197058fb69131c097f9636e765e1a3d9f5fa05ae39a3a7e1fc777b75d4f6b4ce745249234cd9ba42409476663a9dc1800efabef37e13a0ed70395
6
+ metadata.gz: 4b543165a879e7e1a4992c6a6bf58baa5b606af5ea83773194666daf4605ac4fb2142a95817b9259c825e9aa1abfcb750e1a0b6d4663ff29225ff6b547958b92
7
+ data.tar.gz: df54828f56b89b01dea07da527868a7f6fd7cf775b7133d4877856b97d838cbe48d21dbbde53263f61e51d937b6cf278a8e897f00d726ebccf3802e254999e97
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
@@ -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
 
@@ -37,12 +37,7 @@ module IsoDoc
37
37
  def make_body3(body, docxml)
38
38
  body.div class: "main-section" do |div3|
39
39
  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
40
+ front docxml, div3
46
41
  middle docxml, div3
47
42
  footnotes div3
48
43
  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|
@@ -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/>"
@@ -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] }
@@ -39,12 +39,13 @@ module IsoDoc
39
39
  references docxml
40
40
  # triggers xrefs reparse, so put references before all other sections,
41
41
  # which alter titles and thus can alter xrefs
42
+ rearrange_clauses docxml # feeds toc, display_order, clausetitle, clause
42
43
  annex docxml
43
- clause docxml
44
+ clause docxml # feeds clausetitle
44
45
  term docxml
45
46
  index docxml
46
- clausetitle docxml
47
- floattitle docxml
47
+ clausetitle docxml # feeds floattitle
48
+ floattitle docxml # feeds rearrange_clauses
48
49
  toc docxml
49
50
  display_order docxml
50
51
  end
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "2.5.3".freeze
2
+ VERSION = "2.5.4".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|
@@ -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: 注記
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.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-10 00:00:00.000000000 Z
11
+ date: 2023-04-25 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
@@ -473,7 +473,7 @@ homepage: https://github.com/metanorma/isodoc
473
473
  licenses:
474
474
  - BSD-2-Clause
475
475
  metadata: {}
476
- post_install_message:
476
+ post_install_message:
477
477
  rdoc_options: []
478
478
  require_paths:
479
479
  - lib
@@ -488,8 +488,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
488
488
  - !ruby/object:Gem::Version
489
489
  version: '0'
490
490
  requirements: []
491
- rubygems_version: 3.3.26
492
- signing_key:
491
+ rubygems_version: 3.4.12
492
+ signing_key:
493
493
  specification_version: 4
494
494
  summary: Convert documents in IsoDoc into Word and HTML in AsciiDoc.
495
495
  test_files: []