isodoc 2.6.6 → 2.7.1

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: 5facc53bb7c8a88619fbf516d9d4d749ee960311f32dcf9f536375ee0c25a806
4
- data.tar.gz: a6fc8b7e15083a368e3527d4e745977de12fddf02d907163fcc142f41fa96fa2
3
+ metadata.gz: c3d420c1f407fc9c61f6b5b35b4b6a2da5348eb80331cf1751e09546ceef5669
4
+ data.tar.gz: 8861cbd102660ee74d94b5ff367727607fd23ece4c9bca44a468a68b1756a5c9
5
5
  SHA512:
6
- metadata.gz: 55858670ba62d093769824d5888ba78d4af4170626c18e2f575e0fcfbaa6ea2e461b920664ad60911304329536846b89cd54d55688f43c9674938e426a366472
7
- data.tar.gz: 0aded4a1dd614f01e6d5cff9ed4e8b6f7d4065694e156ec0023fdb7f9525243bd64bc9579a008587274c43f3d5a8af29aa88366cc366632e269434458734701a
6
+ metadata.gz: 0b7e7eeb5050180c3b14d958a102ec895196783203ea0fe201996a38f9f0bd9137bdd2402f8260671abcbc5e264443e1847c3b1e6b0e465d7cea11e1ff403871
7
+ data.tar.gz: 3b591c4f0a8b1359a318ea753f2d1d77efe2dd5e7e903e0a77cad3d40f7318e79a1416ce0958fbafb1d02a43a48f6c29bfd62f5221b14dd943a1470511fe7007
data/isodoc.gemspec CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
28
28
  end
29
29
  spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
30
30
 
31
- spec.add_dependency "html2doc", "~> 1.7.0"
31
+ spec.add_dependency "html2doc", "~> 1.7.1"
32
32
  spec.add_dependency "htmlentities", "~> 4.3.4"
33
33
  # spec.add_dependency "isodoc-i18n", "~> 1.1.0" # already in relaton-render and mn-requirements
34
34
  spec.add_dependency "emf2svg"
@@ -110,11 +110,12 @@ module IsoDoc
110
110
  end
111
111
 
112
112
  def preprocess_xslt(docxml)
113
- extract_preprocess_xslt(docxml).each do |x|
113
+ sheets = extract_preprocess_xslt(docxml)
114
+ sheets.each do |x|
114
115
  docxml = Nokogiri::XSLT(x).transform(docxml)
115
116
  end
116
117
  docxml
117
- rescue
118
+ rescue ::Error => e
118
119
  require "debug"; binding.b
119
120
  end
120
121
 
@@ -131,8 +132,9 @@ module IsoDoc
131
132
  convert_i18n_init1(docxml)
132
133
  i18n_init(@lang, @script, @locale)
133
134
  @reqt_models = requirements_processor
134
- .new({ default: "default", lang: @lang, script: @script, locale: @locale,
135
- labels: @i18n.get, modspecidentifierbase: @modspecidentifierbase })
135
+ .new({ default: "default", lang: @lang, script: @script,
136
+ locale: @locale, labels: @i18n.get,
137
+ modspecidentifierbase: @modspecidentifierbase })
136
138
  end
137
139
 
138
140
  def convert_i18n_init1(docxml)
@@ -136,15 +136,26 @@ module IsoDoc
136
136
  end
137
137
 
138
138
  def html_toc_entries(docxml, path)
139
+ xml = html_toc_entries_prep(docxml, path)
139
140
  path.each_with_index.with_object([]) do |(p, i), m|
140
- docxml.xpath(p.join(" | ")).each do |h|
141
- h["id"] ||= "_#{UUIDTools::UUID.random_create}"
141
+ xml.xpath(p.join(" | ")).each do |h|
142
142
  m << { entry: html_toc_entry("h#{i + 1}", h),
143
143
  line: h.line }
144
144
  end
145
145
  end.sort_by { |k| k[:line] }
146
146
  end
147
147
 
148
+ def html_toc_entries_prep(docxml, path)
149
+ path.each do |p|
150
+ docxml.xpath(p.join(" | ")).each do |h|
151
+ h["id"] ||= "_#{UUIDTools::UUID.random_create}"
152
+ end
153
+ end
154
+ xml = Nokogiri::XML(docxml.to_xml, &:noblanks)
155
+ xml.remove_namespaces!
156
+ xml
157
+ end
158
+
148
159
  def toc_exclude_class
149
160
  "[not(@class = 'TermNum')][not(@class = 'noTOC')]" \
150
161
  "[string-length(normalize-space(.))>0]"
@@ -1,7 +1,7 @@
1
1
  module IsoDoc
2
2
  class Metadata
3
3
  DATETYPES = %w{published accessed created implemented obsoleted confirmed
4
- updated issued received transmitted copied unchanged
4
+ updated corrected issued received transmitted copied unchanged
5
5
  circulated vote-started
6
6
  vote-ended}.freeze
7
7
 
@@ -17,7 +17,8 @@ module IsoDoc
17
17
 
18
18
  def extension_insert(docxml, path = [])
19
19
  ins = docxml.at(ns("//metanorma-extension")) ||
20
- docxml.at(ns("//bibdata")).after("<metanorma-extension/>").next_element
20
+ docxml.at(ns("//bibdata"))&.after("<metanorma-extension/>")&.next_element ||
21
+ docxml.root.elements.first.before("<metanorma-extension/>").previous_element
21
22
  path.each do |n|
22
23
  ins = ins.at(ns("./#{n}")) || ins.add_child("<#{n}/>").first
23
24
  end
@@ -25,9 +26,39 @@ module IsoDoc
25
26
  end
26
27
 
27
28
  def preprocess_xslt_insert(docxml)
28
- content = preprocess_xslt_read or return
29
+ content = ""
30
+ p = passthrough_xslt and content += p
31
+ p = preprocess_xslt_read and content += File.read(p)
32
+ content.empty? and return
29
33
  ins = extension_insert(docxml, %w(render))
30
- ins << File.read(content)
34
+ ins << content
35
+ end
36
+
37
+ def passthrough_xslt
38
+ @output_formats.nil? and return nil
39
+ @output_formats.empty? and return nil
40
+ @output_formats.each_key.with_object([]) do |k, m|
41
+ m << <<~XSLT
42
+ <preprocess-xslt format="#{k}">
43
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" version="1.0">
44
+ <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
45
+ <xsl:strip-space elements="*"/>
46
+ <xsl:template match="@* | node()">
47
+ <xsl:copy>
48
+ <xsl:apply-templates select="@* | node()"/>
49
+ </xsl:copy>
50
+ </xsl:template>
51
+ <xsl:template match="*[local-name() = 'passthrough']">
52
+ <xsl:if test="contains(@formats,',#{k},')"> <!-- delimited -->
53
+ <xsl:copy>
54
+ <xsl:apply-templates select="@* | node()"/>
55
+ </xsl:copy>
56
+ </xsl:if>
57
+ </xsl:template>
58
+ </xsl:stylesheet>
59
+ </preprocess-xslt>
60
+ XSLT
61
+ end.join("\n")
31
62
  end
32
63
 
33
64
  # read in from file, but with `<preprocess-xslt @format="">` wrapper
@@ -45,7 +76,7 @@ module IsoDoc
45
76
  ins << "<toc type='table'><title>#{@i18n.toc_tables}</title></toc>"
46
77
  @tocfigures and
47
78
  ins << "<toc type='recommendation'><title>#{@i18n.toc_recommendations}" \
48
- "</title></toc>"
79
+ "</title></toc>"
49
80
  end
50
81
 
51
82
  def address_precompose(bib)
@@ -152,8 +183,8 @@ module IsoDoc
152
183
  when Array
153
184
  hash.reject { |a| blank?(a) }.each_with_object([])
154
185
  .with_index do |(v1, g), i|
155
- i8n_name(v1, "#{i18n_safe(k)}.#{i}").each { |x| g << x }
156
- end
186
+ i8n_name(v1, "#{i18n_safe(k)}.#{i}").each { |x| g << x }
187
+ end
157
188
  else [i18n_tag(pref, hash)]
158
189
  end
159
190
  end
@@ -99,8 +99,43 @@ module IsoDoc
99
99
  elem.replace(@i18n.date(elem["value"], elem["format"].strip))
100
100
  end
101
101
 
102
+ def inline_format(docxml)
103
+ custom_charset(docxml)
104
+ end
105
+
106
+ def custom_charset(docxml)
107
+ charsets = extract_custom_charsets(docxml)
108
+ docxml.xpath(ns("//span[@custom-charset]")).each do |s|
109
+ s["style"] ||= ""
110
+ s["style"] += ";font-family:#{charsets[s['custom-charset']]}"
111
+ end
112
+ end
113
+
114
+ def passthrough(docxml)
115
+ formats = @output_formats.keys
116
+ docxml.xpath(ns("//passthrough")).each do |p|
117
+ passthrough1(p, formats)
118
+ end
119
+ end
120
+
121
+ def passthrough1(elem, formats)
122
+ (elem["formats"] && !elem["formats"].empty?) or elem["formats"] = "all"
123
+ f = elem["formats"].split(",")
124
+ (f - formats).size == f.size or elem["formats"] = "all"
125
+ elem["formats"] == "all" and elem["formats"] = formats.join(",")
126
+ elem["formats"] = ",#{elem['formats']},"
127
+ end
128
+
102
129
  private
103
130
 
131
+ def extract_custom_charsets(docxml)
132
+ docxml.xpath(ns("//presentation-metadata/custom-charset-font")).
133
+ each_with_object({}) do |x, m|
134
+ kv = x.text.split(":", 2)
135
+ m[kv[0]] = kv[1]
136
+ end
137
+ end
138
+
104
139
  def found_matching_variant_sibling(node)
105
140
  prev = node.xpath("./preceding-sibling::xmlns:variant")
106
141
  foll = node.xpath("./following-sibling::xmlns:variant")
@@ -89,6 +89,8 @@ module IsoDoc
89
89
  variant docxml
90
90
  identifier docxml
91
91
  date docxml
92
+ passthrough docxml
93
+ inline_format docxml
92
94
  end
93
95
 
94
96
  def terms(docxml)
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "2.6.6".freeze
2
+ VERSION = "2.7.1".freeze
3
3
  end
@@ -15,15 +15,17 @@ module IsoDoc
15
15
  end
16
16
 
17
17
  class Counter
18
+ attr_accessor :prefix_override
19
+
18
20
  def initialize(num = 0, opts = { numerals: :arabic })
19
21
  @unnumbered = false
20
22
  @num = num
21
23
  @letter = ""
22
24
  @subseq = ""
23
- @letter_override = nil
24
- @number_override = nil
25
+ reset_overrides
25
26
  @style = opts[:numerals]
26
27
  @skip_i = opts[:skip_i]
28
+ @prefix = opts[:prefix]
27
29
  @base = ""
28
30
  if num.is_a? String
29
31
  if /^\d+$/.match?(num)
@@ -36,6 +38,12 @@ module IsoDoc
36
38
  end
37
39
  end
38
40
 
41
+ def reset_overrides
42
+ @letter_override = nil
43
+ @number_override = nil
44
+ @prefix_override = nil
45
+ end
46
+
39
47
  def new_subseq_increment(node)
40
48
  @subseq = node["subsequence"]
41
49
  @num += 1 unless @num.nil?
@@ -57,7 +65,9 @@ module IsoDoc
57
65
  end
58
66
 
59
67
  def sequence_increment(node)
60
- if node["number"]
68
+ if node["branch-number"]
69
+ @prefix_override = node["branch-number"]
70
+ elsif node["number"]
61
71
  @base = @letter_override = @number_override = ""
62
72
  /^(?<b>.*?)(?<n>\d+)$/ =~ node["number"]
63
73
  if blank?(n)
@@ -130,9 +140,7 @@ module IsoDoc
130
140
 
131
141
  def increment(node)
132
142
  @unnumbered = (node["unnumbered"] || node["hidden"]) and return self
133
-
134
- @letter_override = nil
135
- @number_override = nil
143
+ reset_overrides
136
144
  if node["subsequence"] != @subseq &&
137
145
  !(blank?(node["subsequence"]) && blank?(@subseq))
138
146
  new_subseq_increment(node)
@@ -143,11 +151,11 @@ module IsoDoc
143
151
  end
144
152
 
145
153
  def print
146
- return nil if @unnumbered
147
-
154
+ @unnumbered and return nil
155
+ @prefix_override and return @prefix_override
148
156
  num = @number_override || @num
149
157
  out = @style == :roman && !num.nil? ? RomanNumerals.to_roman(num) : num
150
- "#{@base}#{out}#{@letter_override || @letter}"
158
+ "#{@prefix}#{@base}#{out}#{@letter_override || @letter}"
151
159
  end
152
160
 
153
161
  def ol_type(list, depth)
@@ -14,12 +14,13 @@ module IsoDoc
14
14
 
15
15
  def clause_order_main(docxml)
16
16
  [
17
- { path: "//clause[@type = 'scope']" },
17
+ { path: "//sections/clause[@type = 'scope']" },
18
18
  { path: @klass.norm_ref_xpath },
19
19
  { path: "//sections/terms | " \
20
- "//sections/clause[descendant::terms]" },
20
+ "//sections/clause[descendant::terms]" },
21
21
  { path: "//sections/definitions | " \
22
- "//sections/clause[descendant::definitions][not(descendant::terms)]" },
22
+ "//sections/clause[descendant::definitions]" \
23
+ "[not(descendant::terms)]" },
23
24
  { path: @klass.middle_clause(docxml), multi: true },
24
25
  ]
25
26
  end
@@ -168,17 +169,18 @@ module IsoDoc
168
169
  clause.nil? and return num
169
170
  num.increment(clause)
170
171
  section_name_anchors(clause, num.print, lvl)
171
- clause.xpath(ns(SUBCLAUSES)).each_with_object(Counter.new) do |c, i|
172
- section_names1(c, "#{num.print}.#{i.increment(c).print}", lvl + 1)
172
+ clause.xpath(ns(SUBCLAUSES))
173
+ .each_with_object(Counter.new(0, prefix: "#{num.print}.")) do |c, i|
174
+ section_names1(c, i.increment(c).print, lvl + 1)
173
175
  end
174
176
  num
175
177
  end
176
178
 
177
179
  def section_names1(clause, num, level)
178
180
  section_name_anchors(clause, num, level)
179
- i = Counter.new
181
+ i = Counter.new(0, prefix: "#{num}.")
180
182
  clause.xpath(ns(SUBCLAUSES)).each do |c|
181
- section_names1(c, "#{num}.#{i.increment(c).print}", level + 1)
183
+ section_names1(c, i.increment(c).print, level + 1)
182
184
  end
183
185
  end
184
186
 
@@ -216,8 +218,9 @@ module IsoDoc
216
218
  annex_names1(clause.at(ns("./references | ./terms | ./definitions")),
217
219
  num.to_s, 1)
218
220
  else
219
- clause.xpath(ns(SUBCLAUSES)).each_with_object(Counter.new) do |c, i|
220
- annex_names1(c, "#{num}.#{i.increment(c).print}", 2)
221
+ clause.xpath(ns(SUBCLAUSES))
222
+ .each_with_object(Counter.new(0, prefix: "#{num}.")) do |c, i|
223
+ annex_names1(c, i.increment(c).print, 2)
221
224
  end
222
225
  end
223
226
  hierarchical_asset_names(clause, num)
@@ -225,18 +228,18 @@ module IsoDoc
225
228
 
226
229
  def annex_names1(clause, num, level)
227
230
  annex_name_anchors(clause, num, level)
228
- i = Counter.new
231
+ i = Counter.new(0, prefix: "#{num}.")
229
232
  clause.xpath(ns(SUBCLAUSES)).each do |c|
230
- annex_names1(c, "#{num}.#{i.increment(c).print}", level + 1)
233
+ annex_names1(c, i.increment(c).print, level + 1)
231
234
  end
232
235
  end
233
236
 
234
237
  def reference_names(ref)
235
238
  ids = @klass.bibitem_ref_code(ref)
236
239
  identifiers = @klass.render_identifier(ids)
237
- reference = @klass
238
- .docid_l10n(identifiers[:metanorma] || identifiers[:sdo] ||
239
- identifiers[:ordinal] || identifiers[:doi])
240
+ reference = @klass.
241
+ docid_l10n(identifiers[:metanorma] || identifiers[:sdo] ||
242
+ identifiers[:ordinal] || identifiers[:doi])
240
243
  @anchors[ref["id"]] = { xref: reference }
241
244
  end
242
245
  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.6
4
+ version: 2.7.1
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-10-23 00:00:00.000000000 Z
11
+ date: 2023-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: html2doc
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.7.0
19
+ version: 1.7.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.7.0
26
+ version: 1.7.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: htmlentities
29
29
  requirement: !ruby/object:Gem::Requirement