isodoc 2.6.4 → 2.6.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: 7006fe8d8b97cf4224ddb1887323ed738c7710641451295fe87caf164e158059
4
- data.tar.gz: 63926717876a67586dd1182af72a3c777690b7993f4b10b9b58fd09449a17739
3
+ metadata.gz: d1b8b00c0831edf5095dd6d4e24e93f9f6c5fb1fb5fa54d7b9ee67d6821f46d4
4
+ data.tar.gz: 991204e016a3bc3817ecab867cbdfce29dfec3d9c58b46d84a08e1a557828f22
5
5
  SHA512:
6
- metadata.gz: 30c171d99b4ca59293c0679ca8906c46bd21d5deba795a39f731c8705f53f2ec38bbd4f4c4b4578536e440088de8e67b985c75f057453d39bc89e4163b6351e1
7
- data.tar.gz: 52a0c50bdd62a0a973905c71984bf19d12c4b9e9734cf804d89aabff958a922fb77ef0d62e98983fb44994afdfdc5c52d1a39628f88c606b970e52576ab8063c
6
+ metadata.gz: d2fe45089897f94107456c2b5035b30fb1b5b4ec30b102e7a057aadd4df3e46a00bef8b61bbbcd97265ee526bbd4ed758ead5c01c6d1086a6f22fa7f76558ed5
7
+ data.tar.gz: 1b9bb6319fc0f65c4b613080cc05fe04da20cfec092b62976ea4664d58d3998eb3ad4c87ff6645d03a22f84b2dcc000e43de39d4351b55befac7b01471d6ddf7
data/isodoc.gemspec CHANGED
@@ -36,9 +36,9 @@ Gem::Specification.new do |spec|
36
36
  spec.add_dependency "relaton-cli"
37
37
  # spec.add_dependency "metanorma-utils", "~> 1.5.0" # already in isodoc-i18n
38
38
  spec.add_dependency "mn2pdf"
39
- spec.add_dependency "mn-requirements", "~> 0.3.1"
39
+ spec.add_dependency "mn-requirements", "~> 0.3.4"
40
40
 
41
- spec.add_dependency "relaton-render", "~> 0.5.2"
41
+ spec.add_dependency "relaton-render", "~> 0.6.0"
42
42
  spec.add_dependency "roman-numerals"
43
43
  spec.add_dependency "rouge", "~> 4.0"
44
44
  spec.add_dependency "thread_safe"
@@ -34,12 +34,14 @@ module IsoDoc
34
34
  #{SKIP_DOCID} or @type = 'metanorma-ordinal' or @type = 'metanorma'
35
35
  XPATH
36
36
 
37
+ PRIMARY_ID = "docidentifier[@primary = 'true']".freeze
38
+
37
39
  def pref_ref_code(bib)
38
40
  bib["suppress_identifier"] == "true" and return nil
39
41
  lang = "[@language = '#{@lang}']"
40
- ret = bib.xpath(ns("./docidentifier[@primary = 'true']#{lang}"))
42
+ ret = bib.xpath(ns("./#{PRIMARY_ID}[not(#{SKIP_DOCID})]#{lang}"))
41
43
  ret.empty? and
42
- ret = bib.xpath(ns("./docidentifier[@primary = 'true']"))
44
+ ret = bib.xpath(ns("./#{PRIMARY_ID}[not(#{SKIP_DOCID})]"))
43
45
  ret.empty? and
44
46
  ret = bib.at(ns("./docidentifier[not(#{SKIP_DOC1})]#{lang}")) ||
45
47
  bib.at(ns("./docidentifier[not(#{SKIP_DOC1})]"))
@@ -106,69 +106,12 @@ module IsoDoc
106
106
  docxml.xpath(ns("//td | //th")).each do |d|
107
107
  d.traverse do |n|
108
108
  n.text? or next
109
- ret = break_up_long_str(n.text)
109
+ ret = Metanorma::Utils::break_up_long_str(n.text)
110
110
  n.content = ret
111
111
  end
112
112
  end
113
113
  end
114
114
 
115
- LONGSTR_THRESHOLD = 10
116
- LONGSTR_NOPUNCT = 2
117
-
118
- def break_up_long_str(text)
119
- /^\s*$/.match?(text) and return text
120
- text.split(/(?=\s)/).map do |w|
121
- if /^\s*$/.match(text) || (w.size < LONGSTR_THRESHOLD) then w
122
- else
123
- w.scan(/.{,#{LONGSTR_THRESHOLD}}/o).map.with_index do |w1, i|
124
- w1.size < LONGSTR_THRESHOLD ? w1 : break_up_long_str1(w1, i + 1)
125
- end.join
126
- end
127
- end.join
128
- end
129
-
130
- STR_BREAKUP_RE = %r{
131
- (?<=[=_—–\u2009→?+;]) | # break after any of these
132
- (?<=[,.:])(?!\d) | # break on punct only if not preceding digit
133
- (?<=[>])(?![>]) | # > not >->
134
- (?<=[\]])(?![\]]) | # ] not ]-]
135
- (?<=//) | # //
136
- (?<=[/])(?![/]) | # / not /-/
137
- (?<![<])(?=[<]) | # < not <-<
138
- (?<=\p{L})(?=[(\{\[]\p{L}) # letter and bracket, followed by letter
139
- }x.freeze
140
-
141
-
142
- CAMEL_CASE_RE = %r{
143
- (?<=\p{Ll}\p{Ll})(?=\p{Lu}\p{Ll}\p{Ll}) # 2 lowerc / upperc, 2 lowerc
144
- }x.freeze
145
-
146
- # break on punct every LONGSTRING_THRESHOLD chars, with zero width space
147
- # if punct fails, try break on camel case, with soft hyphen
148
- # break regardless every LONGSTRING_THRESHOLD * LONGSTR_NOPUNCT,
149
- # with soft hyphen
150
- def break_up_long_str1(text, iteration)
151
- s, separator = break_up_long_str2(text)
152
- if s.size == 1 # could not break up
153
- (iteration % LONGSTR_NOPUNCT).zero? and
154
- text += "\u00ad" # force soft hyphen
155
- text
156
- else
157
- s[-1] = "#{separator}#{s[-1]}"
158
- s.join
159
- end
160
- end
161
-
162
- def break_up_long_str2(text)
163
- s = text.split(STR_BREAKUP_RE, -1)
164
- separator = "\u200b"
165
- if s.size == 1
166
- s = text.split(CAMEL_CASE_RE)
167
- separator = "\u00ad"
168
- end
169
- [s, separator]
170
- end
171
-
172
115
  # we use this to eliminate the semantic amend blocks from rendering
173
116
  def amend(docxml)
174
117
  docxml.xpath(ns("//amend")).each { |f| amend1(f) }
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "2.6.4".freeze
2
+ VERSION = "2.6.5".freeze
3
3
  end
@@ -31,8 +31,7 @@ module IsoDoc
31
31
  <<~TOC
32
32
  <p class="MsoToc#{toclevel}"><span class="MsoHyperlink"><span lang="EN-GB" style='mso-no-proof:yes'>
33
33
  <a href="#_Toc#{bookmark}">#{heading}<span lang="EN-GB" class="MsoTocTextSpan">
34
- <span style='mso-tab-count:1 dotted'>. </span>
35
- </span><span lang="EN-GB" class="MsoTocTextSpan">
34
+ <span style='mso-tab-count:1 dotted'>. </span></span><span lang="EN-GB" class="MsoTocTextSpan">
36
35
  <span style='mso-element:field-begin'></span></span>
37
36
  <span lang="EN-GB" class="MsoTocTextSpan"> PAGEREF _Toc#{bookmark} \\h </span>
38
37
  <span lang="EN-GB" class="MsoTocTextSpan"><span style='mso-element:field-separator'></span></span><span
@@ -1,12 +1,5 @@
1
1
  require_relative "xref_gen_seq"
2
-
3
- module Enumerable
4
- def noblank
5
- reject do |n|
6
- n["id"].nil? || n["id"].empty?
7
- end
8
- end
9
- end
2
+ require_relative "xref_util"
10
3
 
11
4
  module IsoDoc
12
5
  module XrefGen
@@ -15,14 +8,6 @@ module IsoDoc
15
8
  recommendation permission figure table formula
16
9
  admonition sourcecode).freeze
17
10
 
18
- def blank?(text)
19
- text.nil? || text.empty?
20
- end
21
-
22
- def noblank(xpath)
23
- xpath.reject { |n| blank?(n["id"]) }
24
- end
25
-
26
11
  def amend_preprocess(xmldoc)
27
12
  xmldoc.xpath(ns("//amend[newcontent]")).each do |a|
28
13
  autonum = amend_autonums(a)
@@ -84,23 +69,6 @@ module IsoDoc
84
69
  end
85
70
  end
86
71
 
87
- SECTIONS_XPATH =
88
- "//foreword | //introduction | //acknowledgements | " \
89
- "//preface/terms | preface/definitions | preface/references | " \
90
- "//preface/clause | //sections/terms | //annex | " \
91
- "//sections/clause | //sections/definitions | " \
92
- "//bibliography/references | //bibliography/clause".freeze
93
-
94
- def sections_xpath
95
- SECTIONS_XPATH
96
- end
97
-
98
- def child_asset_path(asset)
99
- "./*[not(self::xmlns:clause) and not(self::xmlns:appendix) and " \
100
- "not(self::xmlns:terms) and not(self::xmlns:definitions)]//xmlns:X | " \
101
- "./xmlns:X".gsub("X", asset)
102
- end
103
-
104
72
  def note_anchor_names(sections)
105
73
  sections.each do |s|
106
74
  notes = s.xpath(child_asset_path("note")) -
@@ -118,9 +86,6 @@ module IsoDoc
118
86
  end
119
87
  end
120
88
 
121
- CHILD_SECTIONS = "./clause | ./appendix | ./terms | ./definitions | " \
122
- "./references".freeze
123
-
124
89
  def admonition_anchor_names(sections)
125
90
  sections.each do |s|
126
91
  notes = s.xpath(child_asset_path("admonition[@type = 'box']"))
@@ -239,16 +204,33 @@ refer_list)
239
204
  Common::to_xml(label.children)
240
205
  end
241
206
 
242
- def bookmark_anchor_names(xml)
243
- xml.xpath(ns(".//bookmark")).noblank.each do |n|
244
- parent = nil
245
- n.ancestors.each do |a|
246
- next unless a["id"] && parent = @anchors.dig(a["id"], :xref)
207
+ def id_ancestor(node)
208
+ parent = nil
209
+ node.ancestors.each do |a|
210
+ (a["id"] && (parent = a) && @anchors.dig(a["id"], :xref)) or next
211
+ break
212
+ end
213
+ parent ? [parent, parent["id"]] : [nil, nil]
214
+ end
247
215
 
248
- break
216
+ def bookmark_container(parent)
217
+ if parent
218
+ clause = parent.xpath(CLAUSE_ANCESTOR)&.last
219
+ if clause["id"] == id
220
+ nil
221
+ else
222
+ @anchors.dig(clause["id"], :xref)
249
223
  end
224
+ end
225
+ end
226
+
227
+ def bookmark_anchor_names(xml)
228
+ xml.xpath(ns(".//bookmark")).noblank.each do |n|
229
+ _parent, id = id_ancestor(n)
230
+ #container = bookmark_container(parent)
250
231
  @anchors[n["id"]] = { type: "bookmark", label: nil, value: nil,
251
- xref: parent || "???" }
232
+ xref: @anchors.dig(id, :xref) || "???",
233
+ container: @anchors.dig(id, :container) }
252
234
  end
253
235
  end
254
236
  end
@@ -84,11 +84,9 @@ module IsoDoc
84
84
  FIRST_LVL_REQ_RULE = <<~XPATH.freeze
85
85
  [not(ancestor::permission or ancestor::requirement or ancestor::recommendation)]
86
86
  XPATH
87
-
88
87
  FIRST_LVL_REQ = <<~XPATH.freeze
89
88
  .//permission#{FIRST_LVL_REQ_RULE} | .//requirement#{FIRST_LVL_REQ_RULE} | .//recommendation#{FIRST_LVL_REQ_RULE}
90
89
  XPATH
91
-
92
90
  REQ_CHILDREN = <<~XPATH.freeze
93
91
  ./permission | ./requirement | ./recommendation
94
92
  XPATH
@@ -234,7 +232,6 @@ module IsoDoc
234
232
  block, anchor_struct(id, nil,
235
233
  label, klass, block["unnumbered"])
236
234
  )
237
-
238
235
  model.permission_parts(block, id, label, klass).each do |n|
239
236
  @anchors[n[:id]] = anchor_struct(n[:number], nil, n[:label],
240
237
  n[:klass], false)
@@ -231,12 +231,6 @@ module IsoDoc
231
231
  end
232
232
  end
233
233
 
234
- ISO_PUBLISHER_XPATH =
235
- "./contributor[xmlns:role/@type = 'publisher']/" \
236
- "organization[abbreviation = 'ISO' or xmlns:abbreviation = 'IEC' or " \
237
- "xmlns:name = 'International Organization for Standardization' or " \
238
- "xmlns:name = 'International Electrotechnical Commission']".freeze
239
-
240
234
  def reference_names(ref)
241
235
  ids = @klass.bibitem_ref_code(ref)
242
236
  identifiers = @klass.render_identifier(ids)
@@ -0,0 +1,41 @@
1
+ module Enumerable
2
+ def noblank
3
+ reject do |n|
4
+ n["id"].nil? || n["id"].empty?
5
+ end
6
+ end
7
+ end
8
+
9
+ module IsoDoc
10
+ module XrefGen
11
+ module Blocks
12
+ def blank?(text)
13
+ text.nil? || text.empty?
14
+ end
15
+
16
+ def noblank(xpath)
17
+ xpath.reject { |n| blank?(n["id"]) }
18
+ end
19
+
20
+ SECTIONS_XPATH =
21
+ "//foreword | //introduction | //acknowledgements | " \
22
+ "//preface/terms | preface/definitions | preface/references | " \
23
+ "//preface/clause | //sections/terms | //annex | " \
24
+ "//sections/clause | //sections/definitions | " \
25
+ "//bibliography/references | //bibliography/clause".freeze
26
+
27
+ def sections_xpath
28
+ SECTIONS_XPATH
29
+ end
30
+
31
+ def child_asset_path(asset)
32
+ "./*[not(self::xmlns:clause) and not(self::xmlns:appendix) and " \
33
+ "not(self::xmlns:terms) and not(self::xmlns:definitions)]//xmlns:X | " \
34
+ "./xmlns:X".gsub("X", asset)
35
+ end
36
+
37
+ CHILD_SECTIONS = "./clause | ./appendix | ./terms | ./definitions | " \
38
+ "./references".freeze
39
+ end
40
+ end
41
+ end
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.6.4
4
+ version: 2.6.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-09-25 00:00:00.000000000 Z
11
+ date: 2023-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: html2doc
@@ -100,28 +100,28 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 0.3.1
103
+ version: 0.3.4
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 0.3.1
110
+ version: 0.3.4
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: relaton-render
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 0.5.2
117
+ version: 0.6.0
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: 0.5.2
124
+ version: 0.6.0
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: roman-numerals
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -451,6 +451,7 @@ files:
451
451
  - lib/isodoc/xref/xref_gen.rb
452
452
  - lib/isodoc/xref/xref_gen_seq.rb
453
453
  - lib/isodoc/xref/xref_sect_gen.rb
454
+ - lib/isodoc/xref/xref_util.rb
454
455
  - lib/isodoc/xslfo_convert.rb
455
456
  - lib/metanorma/output.rb
456
457
  - lib/metanorma/output/base.rb