isodoc 2.4.4 → 2.4.5

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: 9a2cc598b5e8c9690a42329b2af309d75d281db2767adc8fc00eb21a498f69cf
4
- data.tar.gz: 1026ad146597f3e93b46f035506f648e7775bb0cf3e846d6f578d2af029dfb1a
3
+ metadata.gz: 9cbb9d45ce42c28917d84ebd31912cd4218cd47f633d27cf58f1060396c14d67
4
+ data.tar.gz: 25872abe5383206f171fadb766688bd46e751cb83852fa0c09848cdb8a4a45a6
5
5
  SHA512:
6
- metadata.gz: 5923a84bcb2fa4ba407eae39adf36202ebd07902ec425274641717d38b00daea3e035c9c8f12a936f1c6f4126e3d38db68a5184dfe63718adbe08b8c6ed4046d
7
- data.tar.gz: 36a2d61a352858557db3c8f8f097b590842bf148b0ffaf48fcf3a5dd45f0781dcfe929000de3704427d9bde7c1a2c74458f931c0976356e4594bb510631c66c7
6
+ metadata.gz: 8734f21809f2c71d90bbb291c2da8e703cf25e06bebeb83cf3db464d2b97179dd2744be793e11b2657435309c2faf8a08d4d8d48a16c2fad34bdc8fe628a3b1d
7
+ data.tar.gz: ebbcfc1ca95fe1b7d3c8ec89a73823176ae72ad0cd3b43cdc9061a9eafc6dce8612832c0a6dc1fc3f3be4948367567e74fc8c78eb90d5e234a8bd6fbd9cd467a
data/isodoc.gemspec CHANGED
@@ -40,7 +40,6 @@ Gem::Specification.new do |spec|
40
40
  spec.add_dependency "metanorma-utils", "~> 1.4.5"
41
41
  spec.add_dependency "mn2pdf"
42
42
  spec.add_dependency "mn-requirements", "~> 0.3.1"
43
- spec.add_dependency "relaton-cli"
44
43
  spec.add_dependency "relaton-render", "~> 0.5.2"
45
44
  spec.add_dependency "roman-numerals"
46
45
  spec.add_dependency "rouge", "~> 4.0"
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require "isodoc/common"
4
2
  require "fileutils"
5
3
  require "tempfile"
@@ -161,10 +159,8 @@ module IsoDoc
161
159
  end
162
160
 
163
161
  def init_toc(options)
164
- @wordToClevels = (options[:doctoclevels] || options[:toclevels]).to_i
165
- @wordToClevels = 2 if @wordToClevels.zero?
166
- @htmlToClevels = (options[:htmltoclevels] || options[:toclevels]).to_i
167
- @htmlToClevels = 2 if @htmlToClevels.zero?
162
+ @htmlToClevels = 2
163
+ @wordToClevels = 2
168
164
  @tocfigures = options[:tocfigures]
169
165
  @toctables = options[:toctables]
170
166
  @tocrecommendations = options[:tocrecommendations]
@@ -218,6 +214,7 @@ module IsoDoc
218
214
  convert_i18n_init(docxml)
219
215
  metadata_init(@lang, @script, @locale, @i18n)
220
216
  xref_init(@lang, @script, self, @i18n, { locale: @locale })
217
+ toc_init(docxml)
221
218
  [docxml, filename, dir]
222
219
  end
223
220
 
@@ -4,7 +4,7 @@ module IsoDoc
4
4
  def example_label(_node, div, name)
5
5
  return if name.nil?
6
6
 
7
- div.p **{ class: "example-title" } do |_p|
7
+ div.p class: "example-title" do |_p|
8
8
  name.children.each { |n| parse(n, div) }
9
9
  end
10
10
  end
@@ -29,7 +29,7 @@ module IsoDoc
29
29
 
30
30
  def example_table_attr(node)
31
31
  attr_code(id: node["id"], class: "example",
32
- style: "border-collapse:collapse;border-spacing:0;"\
32
+ style: "border-collapse:collapse;border-spacing:0;" \
33
33
  "#{keep_style(node)}")
34
34
  end
35
35
 
@@ -60,7 +60,7 @@ module IsoDoc
60
60
  def note_p_parse(node, div)
61
61
  name = node&.at(ns("./name"))&.remove
62
62
  div.p do |p|
63
- name and p.span **{ class: "note_label" } do |s|
63
+ name and p.span class: "note_label" do |s|
64
64
  name.children.each { |n| parse(n, s) }
65
65
  s << note_delim
66
66
  end
@@ -73,7 +73,7 @@ module IsoDoc
73
73
  def note_parse1(node, div)
74
74
  name = node&.at(ns("./name"))&.remove
75
75
  name and div.p do |p|
76
- p.span **{ class: "note_label" } do |s|
76
+ p.span class: "note_label" do |s|
77
77
  name.children.each { |n| parse(n, s) }
78
78
  s << note_delim
79
79
  end
@@ -117,7 +117,7 @@ module IsoDoc
117
117
  end
118
118
 
119
119
  def admonition_name_parse(_node, div, name)
120
- div.p **{ class: "AdmonitionTitle", style: "text-align:center;" } do |p|
120
+ div.p class: "AdmonitionTitle", style: "text-align:center;" do |p|
121
121
  name.children.each { |n| parse(n, p) }
122
122
  end
123
123
  end
@@ -152,6 +152,19 @@ module IsoDoc
152
152
  end
153
153
  end
154
154
 
155
+ def colophon(isoxml, out)
156
+ isoxml.at(ns("//colophon")) or return
157
+ page_break(out)
158
+ isoxml.xpath(ns("//colophon/clause")).each do |f|
159
+ out.div class: "Section3", id: f["id"] do |div|
160
+ clause_name(nil, f&.at(ns("./title")), div, { class: "IntroTitle" })
161
+ f.elements.each do |e|
162
+ parse(e, div) unless e.name == "title"
163
+ end
164
+ end
165
+ end
166
+ end
167
+
155
168
  def is_clause?(name)
156
169
  %w(clause references definitions terms foreword introduction abstract
157
170
  acknowledgements).include? name
@@ -3,7 +3,7 @@ module IsoDoc
3
3
  module Table
4
4
  def table_title_parse(node, out)
5
5
  name = node.at(ns("./name")) or return
6
- out.p **{ class: "TableTitle", style: "text-align:center;" } do |p|
6
+ out.p class: "TableTitle", style: "text-align:center;" do |p|
7
7
  name&.children&.each { |n| parse(n, p) }
8
8
  end
9
9
  end
@@ -56,7 +56,7 @@ module IsoDoc
56
56
  return unless node["summary"]
57
57
 
58
58
  table.caption do |c|
59
- c.span **{ style: "display:none" } do |s|
59
+ c.span style: "display:none" do |s|
60
60
  s << node["summary"]
61
61
  end
62
62
  end
@@ -66,7 +66,7 @@ module IsoDoc
66
66
  colgroup = node.at(ns("./colgroup")) or return
67
67
  table.colgroup do |cg|
68
68
  colgroup.xpath(ns("./col")).each do |c|
69
- cg.col **{ style: "width: #{c['width']};" }
69
+ cg.col style: "width: #{c['width']};"
70
70
  end
71
71
  end
72
72
  end
@@ -75,16 +75,19 @@ module IsoDoc
75
75
  @in_table = true
76
76
  table_title_parse(node, out)
77
77
  out.table **table_attrs(node) do |t|
78
- tcaption(node, t)
79
- colgroup(node, t)
80
- thead_parse(node, t)
81
- tbody_parse(node, t)
82
- tfoot_parse(node, t)
78
+ table_parse_core(node, t)
83
79
  (dl = node.at(ns("./dl"))) && parse(dl, out)
84
80
  node.xpath(ns("./note")).each { |n| parse(n, out) }
85
81
  end
86
82
  @in_table = false
87
- # out.p { |p| p << "&#xa0;" }
83
+ end
84
+
85
+ def table_parse_core(node, out)
86
+ tcaption(node, out)
87
+ colgroup(node, out)
88
+ thead_parse(node, out)
89
+ tbody_parse(node, out)
90
+ tfoot_parse(node, out)
88
91
  end
89
92
 
90
93
  SW = "solid windowtext".freeze
@@ -69,21 +69,21 @@ module IsoDoc
69
69
  end
70
70
 
71
71
  def make_body1(body, _docxml)
72
- body.div **{ class: "title-section" } do |div1|
72
+ body.div class: "title-section" do |div1|
73
73
  div1.p { |p| p << "&#xa0;" } # placeholder
74
74
  end
75
75
  section_break(body)
76
76
  end
77
77
 
78
78
  def make_body2(body, _docxml)
79
- body.div **{ class: "prefatory-section" } do |div2|
79
+ body.div class: "prefatory-section" do |div2|
80
80
  div2.p { |p| p << "&#xa0;" } # placeholder
81
81
  end
82
82
  section_break(body)
83
83
  end
84
84
 
85
85
  def make_body3(body, docxml)
86
- body.div **{ class: "main-section" } do |div3|
86
+ body.div class: "main-section" do |div3|
87
87
  boilerplate docxml, div3
88
88
  preface_block docxml, div3
89
89
  abstract docxml, div3
@@ -125,13 +125,14 @@ module IsoDoc
125
125
  clause isoxml, out
126
126
  annex isoxml, out
127
127
  bibliography isoxml, out
128
+ colophon isoxml, out
128
129
  end
129
130
 
130
131
  def boilerplate(node, out)
131
132
  return if @bare
132
133
 
133
134
  boilerplate = node.at(ns("//boilerplate")) or return
134
- out.div **{ class: "authority" } do |s|
135
+ out.div class: "authority" do |s|
135
136
  boilerplate.children.each do |n|
136
137
  if n.name == "title"
137
138
  s.h1 do |h|
data/lib/isodoc/init.rb CHANGED
@@ -17,5 +17,14 @@ module IsoDoc
17
17
  def l10n(expr, lang = @lang, script = @script, locale = @locale)
18
18
  @i18n.l10n(expr, lang, script, locale)
19
19
  end
20
+
21
+ def toc_init(docxml)
22
+ x = "//metanorma-extension/presentation-metadata" \
23
+ "[name[text() = 'TOC Heading Levels']]/value"
24
+ n = docxml.at(ns(x.sub(/TOC/, "DOC TOC"))) and
25
+ @wordToClevels = n.text.to_i
26
+ n = docxml.at(ns(x.sub(/TOC/, "HTML TOC"))) and
27
+ @htmlToClevels = n.text.to_i
28
+ end
20
29
  end
21
30
  end
@@ -20,16 +20,14 @@ module IsoDoc
20
20
 
21
21
  def extract_person_affiliations(authors)
22
22
  authors.reduce([]) do |m, a|
23
+ pos = a.at(ns("./affiliation/name"))&.text
23
24
  name = a.at(ns("./affiliation/organization/name"))&.text
24
- subdivs = a.xpath(ns("./affiliation/organization/subdivision"))&.map(&:text)&.join(", ")
25
- name and subdivs and !subdivs.empty? and
26
- name = l10n("#{name}, #{subdivs}")
27
- location = a.at(ns("./affiliation/organization/address/formattedAddress"))&.text
28
- m << (if !name.nil? && !location.nil?
29
- l10n("#{name}, #{location}")
30
- else
31
- (name || location || "")
32
- end)
25
+ subdivs = a.xpath(ns("./affiliation/organization/subdivision"))
26
+ &.map(&:text)&.join(", ")
27
+ location =
28
+ a.at(ns("./affiliation/organization/address/formattedAddress"))&.text
29
+ m << l10n([pos, name, subdivs, location].map { |x| x&.empty? ? nil : x }
30
+ .compact.join(", "))
33
31
  m
34
32
  end
35
33
  end
@@ -16,8 +16,8 @@ module IsoDoc
16
16
  def svg_wrap(elem)
17
17
  return if elem.parent.name == "image"
18
18
 
19
- elem.replace("<image src='' mimetype='image/svg+xml' height='auto' "\
20
- "width='auto'>#{elem.to_xml}</image>")
19
+ elem.wrap("<image src='' mimetype='image/svg+xml' height='auto' " \
20
+ "width='auto'></image>")
21
21
  end
22
22
 
23
23
  def svgmap_extract(elem)
@@ -6,11 +6,16 @@ module IsoDoc
6
6
  docxml.xpath(ns("//references/bibitem")).each do |x|
7
7
  bibitem(x, renderings)
8
8
  end
9
+ hidden_items(docxml)
10
+ @xrefs.parse_inclusions(refs: true).parse(docxml)
11
+ end
12
+
13
+ def hidden_items(docxml)
9
14
  docxml.xpath(ns("//references[bibitem/@hidden = 'true']")).each do |x|
10
15
  x.at(ns("./bibitem[not(@hidden = 'true')]")) and next
16
+ x.elements.map(&:name).any? { |n| n != "bibitem" } and next
11
17
  x["hidden"] = "true"
12
18
  end
13
- @xrefs.parse_inclusions(refs: true).parse(docxml)
14
19
  end
15
20
 
16
21
  def references_render(docxml)
@@ -125,13 +130,13 @@ module IsoDoc
125
130
  ids = @xrefs.klass.bibitem_ref_code(bib)
126
131
  idents = @xrefs.klass.render_identifier(ids)
127
132
  ret = if biblio then biblio_ref_entry_code(ordinal, idents, ids,
128
- standard, datefn)
129
- else norm_ref_entry_code(ordinal, idents, ids, standard, datefn)
133
+ standard, datefn, bib)
134
+ else norm_ref_entry_code(ordinal, idents, ids, standard, datefn, bib)
130
135
  end
131
136
  bib << "<biblio-tag>#{ret}</biblio-tag>"
132
137
  end
133
138
 
134
- def norm_ref_entry_code(_ordinal, idents, _ids, _standard, datefn)
139
+ def norm_ref_entry_code(_ordinal, idents, _ids, _standard, datefn, _bib)
135
140
  ret = (idents[:ordinal] || idents[:metanorma] || idents[:sdo]).to_s
136
141
  (idents[:ordinal] || idents[:metanorma]) && idents[:sdo] and
137
142
  ret += ", #{idents[:sdo]}"
@@ -143,8 +148,8 @@ module IsoDoc
143
148
 
144
149
  # if ids is just a number, only use that ([1] Non-Standard)
145
150
  # else, use both ordinal, as prefix, and ids
146
- def biblio_ref_entry_code(ordinal, ids, _id, standard, datefn)
147
- standard and id = nil
151
+ def biblio_ref_entry_code(ordinal, ids, _id, standard, datefn, _bib)
152
+ #standard and id = nil
148
153
  ret = (ids[:ordinal] || ids[:metanorma] || "[#{ordinal}]")
149
154
  if ids[:sdo]
150
155
  ret = prefix_bracketed_ref(ret)
@@ -28,12 +28,13 @@ module IsoDoc
28
28
  def floattitle(docxml)
29
29
  docxml.xpath(ns("//clause | //annex | //appendix | //introduction | " \
30
30
  "//foreword | //preface/abstract | //acknowledgements | " \
31
- "//terms | //definitions | //references"))
31
+ "//terms | //definitions | //references | //colophon"))
32
32
  .each do |f|
33
33
  floattitle1(f)
34
34
  end
35
35
  # top-level
36
- docxml.xpath(ns("//sections | //preface")).each { |f| floattitle1(f) }
36
+ docxml.xpath(ns("//sections | //preface | //colophon"))
37
+ .each { |f| floattitle1(f) }
37
38
  end
38
39
 
39
40
  def floattitle1(elem)
@@ -119,7 +120,8 @@ module IsoDoc
119
120
  i = display_order_xpath(docxml, @xrefs.klass.middle_clause(docxml), i)
120
121
  i = display_order_xpath(docxml, "//annex", i)
121
122
  i = display_order_xpath(docxml, @xrefs.klass.bibliography_xpath, i)
122
- display_order_xpath(docxml, "//indexsect", i)
123
+ i = display_order_xpath(docxml, "//indexsect", i)
124
+ display_order_xpath(docxml, "//colophon/*", i)
123
125
  end
124
126
 
125
127
  def clausetitle(docxml); end
@@ -108,9 +108,16 @@ module IsoDoc
108
108
  end
109
109
 
110
110
  def embedable_semantic_xml_tags(xml)
111
- Nokogiri::XML(to_xml(xml)
112
- .sub(/ xmlns=['"][^"']+['"]/, "")
113
- .gsub(%r{(</?)([[:alpha:]])}, "\\1semantic__\\2")).root
111
+ ret = to_xml(xml)
112
+ .sub(/ xmlns=['"][^"']+['"]/, "") # root XMLNS
113
+ .split(/(?=[<> \t\r\n\f\v])/).map do |x|
114
+ case x
115
+ when /^<[^:]+:/ then x.sub(/:/, ":semantic__")
116
+ when /^<[^:]+$/ then x.sub(%r{(</?)([[:alpha:]])},
117
+ "\\1semantic__\\2")
118
+ else x end
119
+ end
120
+ Nokogiri::XML(ret.join).root
114
121
  end
115
122
 
116
123
  def embedable_semantic_xml_attributes(xml)
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "2.4.4".freeze
2
+ VERSION = "2.4.5".freeze
3
3
  end
@@ -89,16 +89,20 @@ module IsoDoc
89
89
  table_title_parse(node, out)
90
90
  out.div align: "center", class: "table_container" do |div|
91
91
  div.table **table_attrs(node) do |t|
92
- colgroup(node, t)
93
- thead_parse(node, t)
94
- tbody_parse(node, t)
95
- tfoot_parse(node, t)
92
+ table_parse_core(node, out)
96
93
  (dl = node.at(ns("./dl"))) && parse(dl, out)
97
94
  node.xpath(ns("./note")).each { |n| parse(n, out) }
98
95
  end
99
96
  end
100
97
  @in_table = false
101
98
  end
99
+
100
+ def table_parse_core(node, out)
101
+ colgroup(node, out)
102
+ thead_parse(node, out)
103
+ tbody_parse(node, out)
104
+ tfoot_parse(node, out)
105
+ end
102
106
  end
103
107
  end
104
108
  end
@@ -108,9 +108,7 @@ module IsoDoc
108
108
  end
109
109
 
110
110
  def note_anchor_names1(notes, counter)
111
- notes.each do |n|
112
- next if @anchors[n["id"]] || blank?(n["id"])
113
-
111
+ notes.noblank.each do |n|
114
112
  @anchors[n["id"]] =
115
113
  anchor_struct(increment_label(notes, n, counter), n,
116
114
  @labels["note_xref"], "note", false)
@@ -45,10 +45,14 @@ module IsoDoc
45
45
  end
46
46
  end
47
47
 
48
+ def subfigure_label(subfignum)
49
+ subfignum.zero? and return ""
50
+ "-#{subfignum}"
51
+ end
52
+
48
53
  def sequential_figure_body(subfignum, counter, block, klass)
49
54
  label = counter.print
50
- label &&= label + (subfignum.zero? ? "" : "-#{subfignum}")
51
-
55
+ label &&= label + subfigure_label(subfignum)
52
56
  @anchors[block["id"]] = anchor_struct(
53
57
  label, nil, @labels[klass] || klass.capitalize, klass,
54
58
  block["unnumbered"]
@@ -58,8 +62,7 @@ module IsoDoc
58
62
  def sequential_table_names(clause)
59
63
  c = Counter.new
60
64
  clause.xpath(ns(".//table")).noblank.each do |t|
61
- next if labelled_ancestor(t)
62
-
65
+ labelled_ancestor(t) and next
63
66
  @anchors[t["id"]] = anchor_struct(
64
67
  c.increment(t).print, nil,
65
68
  @labels["table"], "table", t["unnumbered"]
@@ -117,7 +120,6 @@ module IsoDoc
117
120
  block, anchor_struct(id, block,
118
121
  label, klass, block["unnumbered"])
119
122
  )
120
-
121
123
  model.permission_parts(block, id, label, klass).each do |n|
122
124
  @anchors[n[:id]] = anchor_struct(n[:number], n[:elem], n[:label],
123
125
  n[:klass], false)
@@ -171,8 +173,7 @@ module IsoDoc
171
173
 
172
174
  def hierarchical_figure_body(num, subfignum, counter, block, klass)
173
175
  label = "#{num}#{hiersep}#{counter.print}" +
174
- (subfignum.zero? ? "" : "#{hierfigsep}#{subfignum}")
175
-
176
+ subfigure_label(subfignum)
176
177
  @anchors[block["id"]] =
177
178
  anchor_struct(label, nil, @labels[klass] || klass.capitalize,
178
179
  klass, block["unnumbered"])
@@ -181,8 +182,7 @@ module IsoDoc
181
182
  def hierarchical_table_names(clause, num)
182
183
  c = Counter.new
183
184
  clause.xpath(ns(".//table")).noblank.each do |t|
184
- next if labelled_ancestor(t)
185
-
185
+ labelled_ancestor(t) and next
186
186
  @anchors[t["id"]] =
187
187
  anchor_struct("#{num}#{hiersep}#{c.increment(t).print}",
188
188
  nil, @labels["table"], "table", t["unnumbered"])
@@ -1,17 +1,18 @@
1
1
  module IsoDoc
2
2
  module XrefGen
3
3
  module Sections
4
- def back_anchor_names(docxml)
4
+ def back_anchor_names(xml)
5
5
  if @parse_settings.empty? || @parse_settings[:clauses]
6
6
  i = Counter.new("@")
7
- docxml.xpath(ns("//annex")).each do |c|
7
+ xml.xpath(ns("//annex")).each do |c|
8
8
  annex_names(c, i.increment(c).print)
9
9
  end
10
- docxml.xpath(ns(@klass.bibliography_xpath)).each do |b|
10
+ xml.xpath(ns(@klass.bibliography_xpath)).each do |b|
11
11
  preface_names(b)
12
12
  end
13
+ xml.xpath(ns("//colophon/clause")).each { |b| preface_names(b) }
13
14
  end
14
- references(docxml) if @parse_settings.empty? || @parse_settings[:refs]
15
+ references(xml) if @parse_settings.empty? || @parse_settings[:refs]
15
16
  end
16
17
 
17
18
  def references(docxml)
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.4.4
4
+ version: 2.4.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-02-07 00:00:00.000000000 Z
11
+ date: 2023-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciimath
@@ -136,20 +136,6 @@ dependencies:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: 0.3.1
139
- - !ruby/object:Gem::Dependency
140
- name: relaton-cli
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :runtime
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- version: '0'
153
139
  - !ruby/object:Gem::Dependency
154
140
  name: relaton-render
155
141
  requirement: !ruby/object:Gem::Requirement