isodoc 2.6.4 → 2.6.6

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: 7006fe8d8b97cf4224ddb1887323ed738c7710641451295fe87caf164e158059
4
- data.tar.gz: 63926717876a67586dd1182af72a3c777690b7993f4b10b9b58fd09449a17739
3
+ metadata.gz: 5facc53bb7c8a88619fbf516d9d4d749ee960311f32dcf9f536375ee0c25a806
4
+ data.tar.gz: a6fc8b7e15083a368e3527d4e745977de12fddf02d907163fcc142f41fa96fa2
5
5
  SHA512:
6
- metadata.gz: 30c171d99b4ca59293c0679ca8906c46bd21d5deba795a39f731c8705f53f2ec38bbd4f4c4b4578536e440088de8e67b985c75f057453d39bc89e4163b6351e1
7
- data.tar.gz: 52a0c50bdd62a0a973905c71984bf19d12c4b9e9734cf804d89aabff958a922fb77ef0d62e98983fb44994afdfdc5c52d1a39628f88c606b970e52576ab8063c
6
+ metadata.gz: 55858670ba62d093769824d5888ba78d4af4170626c18e2f575e0fcfbaa6ea2e461b920664ad60911304329536846b89cd54d55688f43c9674938e426a366472
7
+ data.tar.gz: 0aded4a1dd614f01e6d5cff9ed4e8b6f7d4065694e156ec0023fdb7f9525243bd64bc9579a008587274c43f3d5a8af29aa88366cc366632e269434458734701a
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"
@@ -50,6 +50,7 @@ module IsoDoc
50
50
  # sourcehighlighter: whether to apply sourcecode highlighting
51
51
  # semantic_xml_insert: whether to insert into presentation XML
52
52
  # a copy of semantic XML
53
+ # output_formats: hash of supported output formats and suffixes
53
54
  def initialize(options) # rubocop:disable Lint/MissingSuper
54
55
  @options = options_preprocess(options)
55
56
  init_stylesheets(@options)
@@ -97,7 +98,7 @@ module IsoDoc
97
98
  end
98
99
 
99
100
  def convert_init(file, input_filename, debug)
100
- docxml = Nokogiri::XML(file) { |config| config.huge }
101
+ docxml = Nokogiri::XML(file, &:huge)
101
102
  filename, dir = init_file(input_filename, debug)
102
103
  docxml.root.default_namespace = ""
103
104
  convert_i18n_init(docxml)
@@ -205,6 +205,8 @@ module IsoDoc
205
205
  end
206
206
  end
207
207
  end
208
+
209
+ def columnbreak_parse(node, out); end
208
210
  end
209
211
  end
210
212
  end
@@ -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})]"))
@@ -252,6 +252,7 @@ module IsoDoc
252
252
  when "variant-title" then variant_title(node, out)
253
253
  when "span" then span_parse(node, out)
254
254
  when "location" then location_parse(node, out)
255
+ when "columnbreak" then columnbreak_parse(node, out)
255
256
  else error_parse(node, out)
256
257
  end
257
258
  end
@@ -3,6 +3,9 @@ require "metanorma-utils"
3
3
  module IsoDoc
4
4
  module Function
5
5
  module Utils
6
+ Hash.include Metanorma::Utils::Hash
7
+ Array.include Metanorma::Utils::Array
8
+
6
9
  def to_xml(node)
7
10
  self.class.to_xml(node)
8
11
  end
@@ -166,8 +169,8 @@ module IsoDoc
166
169
  .merge(@labels ? { labels: @labels } : {})
167
170
  .merge(@meta.labels ? { labels: @meta.labels } : {})
168
171
  .merge(fonts_options || {})
169
- template = liquid(docxml)
170
- template.render(meta.map { |k, v| [k.to_s, empty2nil(v)] }.to_h)
172
+ liquid(docxml).render(meta.stringify_all_keys
173
+ .transform_values { |v| empty2nil(v) })
171
174
  .gsub("<", "<").gsub(">", ">").gsub("&", "&")
172
175
  end
173
176
 
data/lib/isodoc/init.rb CHANGED
@@ -48,6 +48,7 @@ module IsoDoc
48
48
  @aligncrosselements = options[:aligncrosselements]
49
49
  @modspecidentifierbase = options[:modspecidentifierbase]
50
50
  @sourcehighlighter = options[:sourcehighlighter]
51
+ @output_formats = options[:output_formats] || {}
51
52
  end
52
53
 
53
54
  def init_arrangement(options)
@@ -3,7 +3,7 @@ require_relative "metadata_contributor"
3
3
 
4
4
  module IsoDoc
5
5
  class Metadata
6
- attr_accessor :fonts_options
6
+ attr_accessor :fonts_options, :labels
7
7
 
8
8
  def ns(xpath)
9
9
  Common::ns(xpath)
@@ -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) }
@@ -109,6 +109,7 @@ module IsoDoc
109
109
  end
110
110
 
111
111
  def svg_to_emf(node)
112
+ @output_formats[:doc] or return
112
113
  uri = svg_to_emf_uri(node)
113
114
  svg_impose_height_attr(node)
114
115
  ret = imgfile_suffix(uri, "emf")
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "2.6.4".freeze
2
+ VERSION = "2.6.6".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.6
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-23 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